Мне нужно реализовать LoginController для входа в систему пользователя, проверки пароля и защиты некоторых ресурсов или методов.
сценарий 1)
Допустим, пользователь не вошел в систему. он пытается получить доступ к методу, в этот раз мне нужно перенаправить на login.jsp. после входа в систему необходимо перенаправить на правильный URL, откуда исходное местоположение.
scenario2)
скажем, пользователь уже вошел в систему и пытается получить доступ к какому-либо защищенному методу теперь мне нужно перенаправить на verifyPassword.jsp для повторной проверки пароля.
сценарий 1 работает нормально для меня.
Я использую в моем security.xml
<security:global-method-security
secured-annotations="enabled"
jsr250-annotations="disabled"
access-decision-manager-ref="accessDecisionManager"
/>
<security:http entry-point-ref="authEntryPoint" access-denied-page="/accessdenied.action" access-decision-manager-ref="accessDecisionManager" >
<security:intercept-url pattern="/js/**" filters="none" />
<security:anonymous/>
<security:http-basic />
<security:port-mappings >
<security:port-mapping http="8080" https="443"/>
</security:port-mappings>
<security:logout invalidate-session="true" />
<security:custom-filter position="FORM_LOGIN_FILTER" ref="customizedFormLoginFilter"/>
</security:http>
<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
<constructor-arg index="0" value="256" />
</bean>
<bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl">
<property name="hierarchy">
<value>
ROLE_PORTAL_RESTRICTED_USER > ROLE_USER
</value>
</property>
</bean>
<bean id="userDetailsService" class="org.springframework.security.access.hierarchicalroles.UserDetailsServiceWrapper">
<property name="userDetailsService">
<bean class="com.java.CustomeUserDetails" />
</property>
<property name="roleHierarchy" ref="roleHierarchy" />
</bean>
<bean id="authEntryPoint" class="org.springframework.security.web.authentication.AuthenticationProcessingFilterEntryPoint">
<property name="forceHttps" value="false" />
<property name="loginFormUrl" value="/login.action" />
<property name="portMapper">
<bean class="org.springframework.security.web.PortMapperImpl">
<property name="portMappings">
<map>
<entry key="8080" value="443"/>
</map>
</property>
</bean>
</property>
</bean>
<bean id="customizedFormLoginFilter"
class ="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter" >
<property name="allowSessionCreation" value="true" />
<property name="filterProcessesUrl" value="/j_spring_security_check" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="authenticationFailureHandler" ref="failureHandler" />
<property name="authenticationSuccessHandler" ref="successHandler" />
</bean>
<bean id="successHandler"
class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<property name="alwaysUseDefaultTargetUrl" value="false"/>
<property name="defaultTargetUrl" value="/loginsuccess.action" />
</bean>
<bean id="failureHandler"
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
<property name="defaultFailureUrl" value="/loginfailed.action" />
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider user-service-ref="userDetailsService">
<security:password-encoder ref="passwordEncoder">
<security:salt-source user-property="username" />
</security:password-encoder>
</security:authentication-provider>
</security:authentication-manager>
Я использовал аннотацию для методов запроса входа в систему.
@Secured("ROLE_USER")
public ModelAndView protectedMethod()
Я дал всю информацию, я думаю. как перенаправить в verifypin.jsp для зарегистрированных пользователей.
Пожалуйста, дайте мне предложение.