Autoryzacja / uwierzytelnianie taglib Spring Security 3.1.4 nie działa z hierarchią ról w JSF 2.2 na Tomcat 7
RolaHeirarchies jest brana pod uwagę dla Web Security Expressions zdefiniowanych jako przechwytujące adresy URL za pośrednictwem przestrzeni nazw http, ale nie w wyrażeniach używających taglib JSP Authorize.
Czytałem już wiele rzeczy ...ref1 ref2 ref3 ref4 ref5 ref6
****EDYTOWAĆ:****Ref1 i Ref6 wspominają o problemach z porządkiem filtrów i kontekstem bezpieczeństwa niedostępnym w jsp ... (nawiasem mówiąc, używam jsf2) może jest coś do kopania ...
EDYCJA 2: Czy obsługa JSF znacznika bezpieczeństwa lib? czytamto i próbujże bez sukcesu
EDYCJA 3: : Próbowałem zainstalować przez Maven spring-faces 2.3.2 i spring-security-taglibs ... nic się nie dzieje ... Niektórzy tuto powiedzieli, aby utworzyć niestandardowy taglib.xml, ale to też nie zadziałało. starsza wersja...
Przetestowałem to facesContext.externalContext.isUserInRole ('ROLE') i sec: authorize access = "hasRole ('Role') ... Pierwsze działa tylko wtedy, gdy jest to ta sama ROLA, ale nie bierze pod uwagę hierarchii ... I sec: autoryzacja po prostu nic nie robi, wszystkie role są drukowane.
Zobacz powyższy przykład z użytkownikiem z ROLE ROLE_ADMIN_PROFILER_NGS:
<h:outputText rendered="#{facesContext.externalContext.isUserInRole('ROLE_ADMIN_PROFILER_NGS')}" value ="ROLE_ADMIN_PROFILER_NGS"></h:outputText> // WORKS <br></br>
<h:outputText rendered="#{facesContext.externalContext.isUserInRole('ROLE_GUEST')}" value ="ROLE_GUEST"></h:outputText> // SHOULD APPEAR BUT NOTHING HAPPENS<br></br>
<h:outputText rendered="#{facesContext.externalContext.isUserInRole('ROLE_ADMIN')}" value ="ROLE_ADMIN"> // SHOULD NOT APPEAR AND THAT'S THE CASE</h:outputText><br></br>
/* ALL THE THREE NEXT ARE DISPLAYED WHITHOUT CONTROL AUTORIZATION.*/
<sec:authorize access="hasRole('ROLE_ADMIN_PROFILER_NGS')">ROLE_ADMIN_PROFILER_NGS<br></br></sec:authorize>
<sec:authorize access="hasRole('ROLE_GUEST')">ROLE_GUEST <br></br></sec:authorize>
<sec:authorize access="hasRole('ROLE_ADMIN')">ROLE_ADMIN <br></br></sec:authorize>
To właśnie próbowałem uzyskać dostęp do testowania z elementami hierarchii ról:
Gdy użytkownik ma tylko REST GUEST ... Cały tag jest pokazany ... nie powinny się pojawić, powinien pojawić się tylko GUEST (cf definicja na dole):
<sec:authentication property="username" />
<sec:authorize access="hasRole('ROLE_BABAB')">BABA</sec:authorize>
<sec:authorize access="hasRole('ROLE_GUEST')">GUEST</sec:authorize>
<sec:authorize access="hasRole('ROLE_ADMIN')">ADMIN</sec:authorize>
To jest moja konfiguracja bezpieczeństwa:
<security:http auto-config="true" access-decision-manager-ref="accessDecisionManager" use-expressions="true" disable-url-rewriting="true">
<security:intercept-url pattern="/Participant/New/*" access="hasRole('ROLE_ADMIN')" />
<security:intercept-url pattern="/Home" access="hasRole('ROLE_GUEST')" />
<security:intercept-url pattern="/Login" access="hasRole('ROLE_ANONYMOUS')" />
<security:intercept-url pattern="/Login/Error" access="hasRole('ROLE_ANONYMOUS')" />
<security:form-login login-page="/Login" login-processing-url="/j_spring_security_check" authentication-failure-url="/Login/Error" default-target-url="/Home" />
<security:logout logout-url="/j_spring_security_logout" logout-success-url="/Home" delete-cookies="JSESSIONID" invalidate-session="true"/>
<security:anonymous/>
<security:expression-handler ref="defaultWebSecurityExpressionHandler" />
<security:session-management invalid-session-url="/Login" >
<security:concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
</security:session-management>
<security:port-mappings>
<security:port-mapping http="8086" https="8443"/>
</security:port-mappings>
</security:http>
<beans:bean id="defaultWebSecurityExpressionHandler" class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler">
<beans:property name="roleHierarchy" ref="roleHierarchy"/>
</beans:bean>
<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<beans:property name="decisionVoters">
<beans:list>
<beans:ref bean="roleVoter" />
<beans:bean class="org.springframework.security.web.access.expression.WebExpressionVoter">
<beans:property name="expressionHandler" ref="defaultWebSecurityExpressionHandler"/>
</beans:bean>
<beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter">
<beans:constructor-arg ref="roleHierarchy" />
</beans:bean>
<beans:bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
<beans:property name="hierarchy">
<beans:value>
ROLE_ADMIN > ROLE_ADMIN_PROFILER_NGS
ROLE_ADMIN_PROFILER_NGS > ROLE_GUEST
ROLE_GUEST > ROLE_GUEST_PROFILER_NGS
ROLE_ADMIN > ROLE_ADMIN_PROFILER_CGH
ROLE_ADMIN_PROFILER_CGH > ROLE_GUEST
ROLE_GUEST > ROLE_GUEST_PROFILER_CGH
</beans:value>
</beans:property>
</beans:bean>
Wielkie dzięki, jesteś mile widziany, jeśli masz inny pomysł na przetestowanie ...
EDYCJA 3:
Dlaczego zwraca 0 dla RoleHierarchyVoter i 1 dla WebExpressionVoter ... czy to normalne?
14: 48: 32.861 DEBUG FilterSecurityInterceptor: 194 - Bezpieczny obiekt: FilterInvocation: URL: / Home; Atrybuty: [hasRole ('ROLE_GUEST')] 14: 48: 32.861 DEBUG FilterSecurityInterceptor: 310 - Wcześniej uwierzytelniony: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@43a64f5f: Główny: com.clb.genomic.lyon.model.User@d46 : Nazwa użytkownika: jp; Hasło chronione]; Włączone: prawda; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Udzielone organy: ROLE_ADMIN_PROFILER_NGS; Poświadczenia: [OCHRONA]; Authenticated: true; Szczegóły: org.springframework.security.web.authentication.WebAuthenticationDetails@0: RemoteIpAddress: 192.168.154.18; SessionId: 084939D4E097F41ACA6A1F24CD8390BE; Nadawany organy: ROLE_ADMIN_PROFILER_NGS 14: 48: 32861 DEBUGOWANY RoleHierarchyImpl: 117 - getReachableGrantedAuthorities () - z ról [ROLE_ADMIN_PROFILER_NGS] można osiągnąć [ROLE_GUEST_PROFILER_NGS, ROLE_GUEST_PROFILER_CGH, ROLE_ADMIN_PROFILER_NGS, ROLE_GUEST] na zero lub większą liczbę stopni. 14: 48: 32.861 DEBUG AffirmativeBased: 65 - Voter: org.springframework.security.access.vote.RoleHierarchyVoter@6ff43d69, zwrócił: 0 14: 48: 32.862 DEBUG RoleHierarchyImpl: 117 - getReachableGrantedAuthorities () - Z ról [ROLE_ADMIN_PROFILER_NGS] jeden może osiągnąć [ROLE_GUEST_PROFILER_NGS, ROLE_GUEST_PROFILER_CGH, ROLE_ADMIN_PROFILER_NGS, ROLE_GUEST] w zera lub więcej krokach. 14: 48: 32.862 DEBUG AffirmativeBased: 65 - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@3fe932d5, zwrócone: 1 14: 48: 32.862 DEBUG FilterSecurityInterceptor: 215 - Autoryzacja powiodła się
EDYTUJ 5:
<beans:bean id="login" class="com.clb.genomic.lyon.beans.LoginBean" scope ="session">
<beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>
> <security:authentication-manager alias="authenticationManager">
> <security:authentication-provider user-service-ref="userBo" >
> <security:password-encoder ref="standardPasswordEncoder"/>
> </security:authentication-provider>
> </security:authentication-manager>