2013-09-21 1 views
0

Использование Spring Security 3.2, я пытаюсь перехватить URLs следующим образом:Spring Security URL-перехватывать с регулярными выражениями отказа матча

<security:http use-expressions="true" path-type="regex" > 

    <security:intercept-url pattern="/jsp/Error_403.jsp" access="hasAnyRole('ROLE_VISITOR','ROLE_ADMIN','ROLE_BRONZE_SUB','ROLE_BRONZE_TEST','ROLE_SILVER_SUB','ROLE_SILVER_TEST','ROLE_GOLD_SUB','ROLE_GOLD_TEST')" /> 
    <security:intercept-url pattern="/jsp/LoggedOut.jsp" access="hasAnyRole('ROLE_VISITOR','ROLE_ADMIN','ROLE_BRONZE_SUB','ROLE_BRONZE_TEST','ROLE_SILVER_SUB','ROLE_SILVER_TEST','ROLE_GOLD_SUB','ROLE_GOLD_TEST')" /> 
    <security:intercept-url pattern="/jsp/home/header.html" access="hasAnyRole('ROLE_VISITOR','ROLE_ADMIN','ROLE_BRONZE_SUB','ROLE_BRONZE_TEST','ROLE_SILVER_SUB','ROLE_SILVER_TEST','ROLE_GOLD_SUB','ROLE_GOLD_TEST')"/> 
    <security:intercept-url pattern="/unjust?action=statistics" access="hasAnyRole('ROLE_ADMIN','ROLE_GOLD_SUB','ROLE_GOLD_TEST')" /> 
    <security:intercept-url pattern="/unjust?action=browse" access="hasAnyRole('ROLE_ADMIN')" /> 
    <security:intercept-url pattern="/unjust?action=search" access="hasAnyRole('ROLE_ADMIN','ROLE_BRONZE_SUB','ROLE_BRONZE_TEST','ROLE_SILVER_SUB','ROLE_SILVER_TEST','ROLE_GOLD_SUB','ROLE_GOLD_TEST')" /> 
    <security:intercept-url pattern="/unjust?action=home" access="hasAnyRole('ROLE_ADMIN','ROLE_BRONZE_SUB','ROLE_BRONZE_TEST','ROLE_SILVER_SUB','ROLE_SILVER_TEST','ROLE_GOLD_SUB','ROLE_GOLD_TEST')" /> 
      <security:intercept-url pattern="/unjust" access="hasAnyRole('ROLE_VISITOR','ROLE_ADMIN','ROLE_BRONZE_SUB','ROLE_BRONZE_TEST','ROLE_SILVER_SUB','ROLE_SILVER_TEST','ROLE_GOLD_SUB','ROLE_GOLD_TEST')"/> 


    <security:intercept-url pattern="/**" access="denyAll" /> 
    <access-denied-handler error-page="/jsp/Error_403.jsp"/> 

    <security:logout /> 
    <security:openid-login login-page="/openidlogin.jsp" 
     user-service-ref="registeringUserService" authentication-failure-url="/openidlogin.jsp?login_error=true"> 
     <attribute-exchange identifier-match="https://www.google.com/.*"> 
      <openid-attribute name="email" 
       type="http://axschema.org/contact/email" required="true" count="1" /> 
      <openid-attribute name="firstname" 
       type="http://axschema.org/namePerson/first" required="true" /> 
      <openid-attribute name="lastname" 
       type="http://axschema.org/namePerson/last" required="true" /> 
     </attribute-exchange> 

     <attribute-exchange identifier-match=".*myopenid.com.*"> 
      <openid-attribute name="email" 
       type="http://schema.openid.net/contact/email" required="true" /> 
      <openid-attribute name="fullname" 
       type="http://schema.openid.net/namePerson" required="true" /> 
     </attribute-exchange> 
    </security:openid-login> 
    <remember-me token-repository-ref="tokenRepo" /> 
</security:http>  

Когда я пытаюсь выполнить, например, действие просмотра, я не могу проверить подлинность и журнал показывает это:

12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.FilterChainProxy - /unjust?action=statistics at position 11 of 11 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 
12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/jsp/Error_403.jsp' 
12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/jsp/LoggedOut.jsp' 
12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/jsp/home/header.html' 
12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/unjust?action=statistics' 
12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/unjust?action=browse' 
12889 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/unjust?action=search$' 
12890 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/unjust?action=home' 
12890 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.util.RegexRequestMatcher - Checking match of request : '/unjust?action=statistics'; against '/unjust' 
12890 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /unjust?action=statistics; Attributes: [denyAll] 
12890 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor - Previously Authenticated: [[email protected]f995e9: Principal: [email protected]: Username: https://www.google.com/accounts/o8/id?xxxxx; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_BRONZE_SUB; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]380f4: RemoteIpAddress: 127.0.0.1; SessionId: 6F57A4A404D2BC3CD82391F6973FA715; Granted Authorities: ROLE_BRONZE_SUB, attributes : xxxxxx 
12890 [http-bio-8080-exec-14] DEBUG org.springframework.security.access.vote.AffirmativeBased - Voter: org.sp[email protected]b041b0, returned: -1 
12890 [http-bio-8080-exec-14] DEBUG org.springframework.security.web.access.ExceptionTranslationFilter - Access is denied (user is not anonymous); delegating to AccessDeniedHandler 
org.springframework.security.access.AccessDeniedException: Access is denied 

Я видел несколько постов на StackOverflow, которые имеют целый ряд различных форматов для регулярного выражения, начиная от того, что я выше, чтобы

<security:intercept-url pattern="\A^/unjust?action=search.$\Z" 

Я был в состоянии генерировать матчи с помощью муравьиного пути Искателя, однако, все тогда терпят неудачу, когда у меня есть запрос, как это:

/unjust?action=browseUNDT&sEcho=1&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=caseName&mDataProp_1=caseId&mDataProp_2=judgmentDate&mDataProp_3=judgmentType&mDataProp_4=judgmentNo&mDataProp_5=docId&mDataProp_6=displayCase&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&iSortCol_0=0&sSortDir_0=asc&iSortingCols=1&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&_=1379771161138 

и все между ними.

Может кто-нибудь, пожалуйста, направить меня к правильной настройке и синтаксису для этого соответствия шаблону?

+0

Похоже, что проблема заключается в простой синтаксической ошибке, например: должен быть записан как для соответствия всем завершающим символам в конце URL-адреса – jmf1205

ответ

1

Весна не поддерживает сопоставление параметров по URL-адресу по умолчанию. с помощью регулярного выражения с использованием request-matcher = "regex" или path-type = "regex" вы можете использовать regex для соответствия URL-адресам. В данный момент у нас нет шаблона = /unjust?action=browse "?" означает специальный символ в регулярном выражении. Одно появление или нуль. Вы должны убежать? в вашем шаблоне с помощью "\\?"

+1

Это была одной из нескольких проблем - я тоже неправильно сопоставлялся до конца строки. Правильный синтаксис выглядит следующим образом: jmf1205

Смежные вопросы