我尝试过所有解决方案。我面临两个问题:
以下是我之后所做的更改:
以下是安全上下文配置:
<http pattern="/" security="none"/>
<!--<http pattern="/login" security="none"/>-->
<http pattern="/resources/assets/**" security="none"/>
<http pattern="/resources/bootstrap/**" security="none"/>
<http pattern="/resources/config/**" security="none"/>
<http pattern="/resources/css/**" security="none"/>
<http pattern="/resources/data/**" security="none"/>
<http pattern="/resources/font-awesome-4.5.0/**" security="none"/>
<http pattern="/resources/fonts/**" security="none"/>
<http pattern="/resources/images/**" security="none"/>
<http auto-config="false" use-expressions="true" entry-point-ref="loginUrlAuthenticationEntryPoint">
<!--permitall isAnonymous()-->
<intercept-url pattern="/login" access="isAnonymous()" />
<intercept-url pattern="/login?logout=1" access="isAnonymous()" />
<intercept-url pattern="/login?logout=0" access="isAnonymous()" />
<intercept-url pattern="/login?logout=2" access="isAnonymous()" />
<intercept-url pattern="/login?error" access="isAnonymous()" />
<intercept-url pattern="/**" access="isAuthenticated()" />
<intercept-url pattern="/user/*" access="isAuthenticated()" />
<intercept-url pattern="/resources/js/angular/**" access="isAuthenticated()" />
<custom-filter position="FORM_LOGIN_FILTER" ref="customUsernamePasswordAuthenticationFilter" />
<logout logout-success-url="/login?logout=0" invalidate-session="true" delete-cookies="JSESSIONID" />
<!--<logout success-handler-ref="customLogoutSuccessHandler" invalidate-session="true" delete-cookies="JSESSIONID"
newSession/>-->
<session-management invalid-session-url="/login?logout=1" session-fixation-protection="migrateSession">
<concurrency-control max-sessions="1" expired-url="/login?logout=2" />
</session-management>
<csrf/>
<headers/>
</http>
<beans:bean id="loginUrlAuthenticationEntryPoint"
class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
<beans:property name="loginFormUrl" value="/login"/>
</beans:bean>
<authentication-manager alias="authenticationManager">
<authentication-provider ref="customAuthenticationProvider"/>
</authentication-manager>
<beans:bean id="customUsernamePasswordAuthenticationFilter"
class="com.vitrana.hilit.web.security.CustomAuthenticationFilter" >
<beans:property name="authenticationManager" ref="authenticationManager"/>
<beans:property name="authenticationFailureHandler" ref="failureHandler"/>
<beans:property name="authenticationSuccessHandler" ref="successHandler"/>
<beans:property name="usernameParameter" value="hdnUserName" />
<beans:property name="passwordParameter" value="password" />
</beans:bean>
<beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
<beans:property name="defaultTargetUrl" value="/user/dashboard.jsp"/>
</beans:bean>
<beans:bean id="failureHandler" class="com.vitrana.hilit.web.security.UserNameCachingAuthenticationFailureHandler">
<beans:property name="defaultFailureUrl" value="/login?error"/>
</beans:bean>
<beans:bean id="customLogoutSuccessHandler" class="com.vitrana.hilit.web.security.CustomLogoutSuccessHandler" > </beans:bean>
<beans:bean class="com.vitrana.hilit.web.security.SessionDestroyedListener">
</beans:bean>
请建议。任何帮助表示赞赏。 感谢
答案 0 :(得分:0)
对不需要授权的端点禁用spring web安全性。如登录页面静态内容等。一旦禁用Spring Security,将无法验证会话。
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity webSecurity) {
log.debug("ignore urls for web security.....");
//Web resources
webSecurity.ignoring().antMatchers("/uistatic/**");
webSecurity.ignoring().antMatchers("/css/**");
webSecurity.ignoring().antMatchers("/js/**");
webSecurity.ignoring().antMatchers("/img/**");
webSecurity.ignoring().antMatchers("/images/**");
webSecurity.ignoring().antMatchers("/index**");
webSecurity.ignoring().antMatchers("/login**");
}
}