クラス ExpressionBasedMessageSecurityMetadataSourceFactory


  • public final class ExpressionBasedMessageSecurityMetadataSourceFactory
    extends java.lang.Object
    Spring 式にマップされた MessageMatcher を使用する MessageSecurityMetadataSource を作成するために使用されるクラス。
    導入:
    4.0
    • メソッドの詳細

      • createExpressionMessageMetadataSource

        public static MessageSecurityMetadataSource createExpressionMessageMetadataSource​(java.util.LinkedHashMap<MessageMatcher<?>,​java.lang.String> matcherToExpression)
        Spring 式にマップされた MessageMatcher を使用する MessageSecurityMetadataSource を作成します。各エントリは順番に考慮され、最初に一致したものだけが使用されます。例:
             LinkedHashMap<MessageMatcher<?>,String> matcherToExpression = new LinkedHashMap<MessageMatcher<Object>,String>();
             matcherToExpression.put(new SimDestinationMessageMatcher("/public/**"), "permitAll");
             matcherToExpression.put(new SimDestinationMessageMatcher("/admin/**"), "hasRole('ROLE_ADMIN')");
             matcherToExpression.put(new SimDestinationMessageMatcher("/topics/{name}/**"), "@someBean.customLogic(authentication, #name)");
             matcherToExpression.put(new SimDestinationMessageMatcher("/**"), "authenticated");
        
             MessageSecurityMetadataSource metadataSource = createExpressionMessageMetadataSource(matcherToExpression);
         

        宛先が "/public/hello" の場合、"/public/**" と "/**" で一致します。ただし、"/public/**" は最初のエントリであるため、使用されるのは "/public/**" のみです。これは、"/public/hello" の宛先が "permitAll" にマップされることを意味します。

        式の完全なリストについては、MessageSecurityExpressionRoot を参照してください

        パラメーター:
        matcherToExpression - AbstractSecurityExpressionHandler.getExpressionParser() を使用して式に変換される文字列への MessageMatcher の順序付けられたマッピング
        戻り値:
        使用する MessageSecurityMetadataSource。null にはできません。
      • createExpressionMessageMetadataSource

        public static MessageSecurityMetadataSource createExpressionMessageMetadataSource​(java.util.LinkedHashMap<MessageMatcher<?>,​java.lang.String> matcherToExpression,
                                                                                          SecurityExpressionHandler<org.springframework.messaging.Message<java.lang.Object>> handler)
        Spring 式にマップされた MessageMatcher を使用する MessageSecurityMetadataSource を作成します。各エントリは順番に考慮され、最初に一致したものだけが使用されます。例:
             LinkedHashMap<MessageMatcher<?>,String> matcherToExpression = new LinkedHashMap<MessageMatcher<Object>,String>();
             matcherToExpression.put(new SimDestinationMessageMatcher("/public/**"), "permitAll");
             matcherToExpression.put(new SimDestinationMessageMatcher("/admin/**"), "hasRole('ROLE_ADMIN')");
             matcherToExpression.put(new SimDestinationMessageMatcher("/topics/{name}/**"), "@someBean.customLogic(authentication, #name)");
             matcherToExpression.put(new SimDestinationMessageMatcher("/**"), "authenticated");
        
             MessageSecurityMetadataSource metadataSource = createExpressionMessageMetadataSource(matcherToExpression);
         

        宛先が "/public/hello" の場合、"/public/**" と "/**" で一致します。ただし、"/public/**" は最初のエントリであるため、使用されるのは "/public/**" のみです。これは、"/public/hello" の宛先が "permitAll" にマップされることを意味します。

        式の完全なリストについては、MessageSecurityExpressionRoot を参照してください

        パラメーター:
        matcherToExpression - AbstractSecurityExpressionHandler.getExpressionParser() を使用して式に変換される文字列への MessageMatcher の順序付けられたマッピング
        handler - 使用する SecurityExpressionHandler
        戻り値:
        使用する MessageSecurityMetadataSource。null にはできません。