简体   繁体   English

如何在Spring Security中将未找到标头重定向到登录页面

[英]How to Redirect Header Not Found Exception to Login Page in Spring Security

I am implementing solution using spring security siteminder. 我正在使用Spring Security Siteminder实施解决方案。 I am able to check SM_USER in header if the header is not found in the request i want to redirect the request to login page .how can i do this i am new to spring 我可以检查标头中的SM_USER,如果在请求中找不到标头,我想将请求重定向到登录页面。我该怎么做?

Configuration is: 配置为:

    <security:intercept-url pattern="/Login" access="permitAll"/>
    <security:intercept-url pattern="/**" />
    <security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
</security:http>

<bean id="siteminderFilter" class="arunkumar.sso.preauth.RequestHeaderFilterAuth">
    <property name="principalRequestHeader" value="SM_USER"/>
    <property name="authenticationManager" ref="authenticationManager" />
</bean>

<bean id="preauthAuthProvider" class="arunkumar.sso.preauth.PreAuthenticatedProvider">
    <property name="preAuthenticatedUserDetailsService">
        <bean id="userDetailsServiceWrapper"  class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
            <property name="userDetailsService" ref="customUserDetailsService"/>
        </bean>
    </property>
</bean>

<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>  

<bean id="customUserDetailsService" class="arunkumar.sso.preauth.CustomUserDetailsService"></bean>
<bean id="http403EntryPoint" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"></bean>

In RequestHeaderFilterAuth try this: RequestHeaderFilterAuth尝试以下操作:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {

       String header = ((HttpServletRequest)request).getHeader(headerName);
       if(header == null){
           ((HttpServletResponse) response).sendRedirect(loginUrl);
       }  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM