В моем веб-приложении Spring MVC есть определенные области, доступные только пользователям с достаточными привилегиями. Вместо того, чтобы просто отображать сообщение «Доступ запрещен», мне нужно разрешить пользователям входить в систему как другой пользователь, чтобы использовать эти страницы (вроде как переопределение).
Как я могу сделать это с помощью Spring Security?
Вот поток, который я ищу, с немного более подробной информацией:
Примечание. Страница X имеет большую длинную строку запроса, которую необходимо сохранить.
Как я могу сделать это с помощью Spring Security?
Вот мой файл конфигурации безопасности Spring:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<debug />
<global-method-security pre-post-annotations="enabled">
<!-- AspectJ pointcut expression that locates our "post" method and applies
security that way <protect-pointcut expression="execution(* bigbank.*Service.post*(..))"
access="ROLE_TELLER"/> -->
</global-method-security>
<!-- Allow anyone to get the static resources and the login page by not applying the security filter chain -->
<http pattern="/resources/**" security="none" />
<http pattern="/css/**" security="none" />
<http pattern="/img/**" security="none" />
<http pattern="/js/**" security="none" />
<!-- Lock everything down -->
<http
auto-config="true"
use-expressions="true"
disable-url-rewriting="true">
<!-- Define the URL access rules -->
<intercept-url pattern="/login" access="permitAll" />
<intercept-url pattern="/about/**" access="permitAll and !hasRole('blocked')" />
<intercept-url pattern="/users/**" access="hasRole('user')" />
<intercept-url pattern="/reviews/new**" access="hasRole('reviewer')" />
<intercept-url pattern="/**" access="hasRole('user')" />
<form-login
login-page="/login" />
<logout logout-url="/logout" />
<access-denied-handler error-page="/login?reason=accessDenied"/>
<!-- Limit the number of sessions a user can have to only 1 -->
<session-management>
<concurrency-control max-sessions="1" />
</session-management>
</http>
<authentication-manager>
<authentication-provider ref="adAuthenticationProvider" />
<authentication-provider>
<user-service>
<user name="superadmin" password="superadminpassword" authorities="user" />
</user-service>
</authentication-provider>
</authentication-manager>
<beans:bean id="adAuthenticationProvider" class="[REDACTED Package].NestedGroupActiveDirectoryLdapAuthenticationProvider">
<beans:constructor-arg value="[REDACTED FQDN]" />
<beans:constructor-arg value="[REDACTED LDAP URL]" />
<beans:property name="convertSubErrorCodesToExceptions" value="true" />
<beans:property name="[REDACTED Group Sub-Tree DN]" />
<beans:property name="userDetailsContextMapper" ref="peerReviewLdapUserDetailsMapper" />
</beans:bean>
<beans:bean id="peerReviewLdapUserDetailsMapper" class="[REDACTED Package].PeerReviewLdapUserDetailsMapper">
<beans:constructor-arg ref="UserDAO" />
</beans:bean>
</beans:beans>
Я использую слегка измененную версию возможностей подключения Spring Security 3.1 Active Directory. Модификации просто загружают все группы пользователя, в том числе те, которые достигаются путем вложения групп, а не только те, членом которых является пользователь. Я также использую настраиваемый объект пользователя, в который встроен объект User моего приложения, и настраиваемый сопоставитель LDAP, который выполняет обычное сопоставление LDAP, а затем добавляет моего пользователя.
Существует специальный сценарий аутентификации, который еще не реализован, когда пользователь аутентифицируется на основе имени пользователя, переданного из внешнего приложения (или через Kerberos) в режиме единого входа.