简体   繁体   English

cas + spring安全

[英]cas+spring security

I'm trying to implement SSO in my app and as for now, I've faced the next problem: 我正在尝试在我的应用程序中实现SSO,到目前为止,我遇到了下一个问题:

HTTP Status 401 - Authentication Failed: Failed to provide a CAS service ticket to validate

type Status report

message Authentication Failed: Failed to provide a CAS service ticket to validate

description This request requires HTTP authentication (Authentication Failed: Failed to provide a CAS service ticket to validate).

I start my cas server on a different tomcat, login there and when I go to login pageat my app, then: 1. then is no autologin 2. when i enter credentials, I see the stacktrace shown above I took an example from this site . 我在不同的tomcat上启动cas服务器,然后在其中登录,然后在我的应用程序中登录页面时,然后:1.然后没有自动登录2.当我输入凭据时,我看到上面显示的stacktrace我从该站点举了一个例子。

here is my spring security context: 这是我的春季安全上下文:

<security:global-method-security  pre-post-annotations="enabled" />

    <security:http use-expressions="true" auto-config="true"
        entry-point-ref="casAuthenticationEntryPoint" >

    <security:custom-filter position="CAS_FILTER" ref="casAuthenticationFilter"></security:custom-filter>

        <security:access-denied-handler  ref="accessDeniedHandler" />

        <security:form-login login-page="/login.html"
            authentication-failure-url="/login.html?login_error=1"
            default-target-url="/index.html" 
            always-use-default-target="false"
            login-processing-url="/j_spring_security_check"
            authentication-failure-handler-ref="failureHandler"
            authentication-success-handler-ref="successHandler" />
        <security:logout logout-url="/logout" logout-success-url="/login.html" />

        <security:intercept-url pattern="/member/**" access="hasRole('viewer')" />
        <security:intercept-url pattern="/admin/**" access="hasRole('SiteAdmin')" />
        <security:intercept-url pattern="/admin/**" access="hasRole('SystemAdmin')" />

        <security:remember-me />
    </security:http>

    <security:authentication-manager alias="authenticationManager">
        <security:authentication-provider user-service-ref="myUserDetailsService" />
        <security:authentication-provider ref="casAuthenticationProvider"></security:authentication-provider>
    </security:authentication-manager>

    <bean id="myUserDetailsService"
        class="com.mypackage.MyUserDetailsService">
    </bean>

    <bean id="authenticationEntryPoint"
        class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
        <property name="loginFormUrl" value="/login.html" />
        <property name="forceHttps" value="false" />
    </bean>

    <bean id="successHandler"
        class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
        <property name="defaultTargetUrl" value="/member/index.html" />
    </bean>

    <bean id="failureHandler"
        class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
        <property name="defaultFailureUrl" value="/login.html?error=auth_fail" />
    </bean>

    <bean id="bannedHandler"
        class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
        <property name="defaultFailureUrl" value="/login.html?error=banned" />
    </bean>

    <bean id="accessDeniedHandler"
        class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
        <property name="errorPage" value="/403.jsp"></property>
    </bean>


    <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
        <property name="service" value="http://localhost:8080/spring-security-cas/j_spring_cas_security_check"></property>
        <property name="sendRenew" value="false"></property>
    </bean> 

    <bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
        <property name="authenticationManager" ref="authenticationManager"></property>
    </bean>

    <bean id="casAuthenticationEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
        <property name="loginUrl" value="http://localhost:9080/cas-server-webapp-3.4.10/login"></property>
        <property name="serviceProperties" ref="serviceProperties"></property>
    </bean>

    <bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
        <property name="userDetailsService" ref="myUserDetailsService"></property>
        <property name="serviceProperties" ref="serviceProperties"></property>
        <property name="ticketValidator">
            <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                <constructor-arg index="0" value="http://localhost:9080/cas-server-webapp-3.4.10"></constructor-arg>
            </bean>
        </property>
        <property name="key" value="cas"></property>
    </bean>

in web.xml, I've includede spring security context and set the appropriate listeners and etc. in pom(I use maven) I've added the required dependencies, described in the article. 在web.xml中,我包含了spring安全上下文并设置了适当的侦听器等。在pom(我使用maven)中,我添加了必需的依赖项,如本文所述。 But the problem stays. 但是问题仍然存在。 I'd be glad any pieces of advice 我很高兴有任何建议

From your error message "This request requires HTTP authentication" its seems, that your CAS server has authentication enabled. 从错误消息“此请求需要HTTP身份验证”看来,您的CAS服务器已启用身份验证。 You need to deactivate that and login via a HTML-Page (ie it will be a JSP, ASP, or something similar). 您需要停用它并通过HTML页面登录(即,它将是JSP,ASP或类似名称)。

I get the same trace,When 我得到相同的踪迹

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

But the cas login url don`t have the *.do suffix.When I add the .do it work well. 但是cas登录网址没有* .do后缀。当我添加.do时,效果很好。

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

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