在使用我的基于 GWT 的 Web 应用程序实现 Spring Security 时。我找到。
一切都按预期正常工作,除了以下事实:
我打开了 login.jsp 并给出了有效的用户登录凭据。
提交后,成功重定向到主页。现在,当我在地址栏中编辑 login.jsp 的 URL 时...令人惊讶的是,它允许打开我的 login.jsp 但据我了解...它不应该允许返回到 login.jsp 直到&除非我我已登录。
可能是我的 security-context.xml 文件配置不正确。
下面是我的 security-application-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- - Sample namespace-based configuration - -->
<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-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.4.xsd">
<global-method-security secured-annotations="enabled">
</global-method-security>
<beans:bean id="customAuthenticationProcessingFilter"
class="edu.authentication.CustomAuthenticationProcessingFilter">
<custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />
<beans:property name="defaultTargetUrl" value="/Home.html?gwt.codesvr=127.0.0.1:9997" />
<beans:property name="authenticationFailureUrl" value="/login.jsp?login_error=1" />
<beans:property name="authenticationManager" ref="authenticationManager" />
</beans:bean>
<beans:bean id="authenticationProcessingFilterEntryPoint"
class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<beans:property name="loginFormUrl" value="/login.jsp" />
<beans:property name="forceHttps" value="false" />
</beans:bean>
<beans:bean id="customUserDetailsService"
class="edu.authentication.CustomUserDetailsService">
<beans:property name="urmService" ref="urmService" />
</beans:bean>
<http auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint">
<intercept-url pattern="/login.jsp*" filters="none" />
<intercept-url pattern="/forgot_password.jsp*" filters="none" />
<intercept-url pattern="/forgotPasswordServlet.do*" filters="none" />
<intercept-url pattern="/myApp/**" access="IS_AUTHENTICATED_FULLY"/>
<intercept-url pattern="/gwt/**" access="IS_AUTHENTICATED_FULLY"/>
<intercept-url pattern="/*.html" access="IS_AUTHENTICATED_FULLY"/>
<logout logout-url="/j_spring_security_logout"
invalidate-session="true" logout-success-url="/login.jsp?loggedout=true"/>
</http>
<authentication-manager alias="authenticationManager" />
<authentication-provider user-service-ref="customUserDetailsService">
<password-encoder hash="md5" />
</authentication-provider>
</beans:beans>
任何帮助/建议都将非常有用。
Spring Security 中没有内置任何内容来阻止您在登录后查看登录页面。您可以通过将以下代码添加到登录页面顶部来阻止登录用户查看登录页面。
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags' %>
<sec:authorize ifNotGranted="ROLE_ANONYMOUS">
<% response.sendRedirect("/mainpage.jsp"); %>
</sec:authorize>
其逻辑是,如果用户未登录,Spring Security 将为他们创建一个匿名 Authentication 对象,并为他们提供 ROLE_ANONYMOUS 角色。因此,您只需检查用户是否具有该角色,如果没有,您可以假设他们已登录并将其重定向到应用程序的主页。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)