Spring Security and CAS Integration

前端 未结 3 549
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-04 12:25

Can anyone paste simple steps to integrate Spring security and CAS over here for single sign on and single sign out. Note I dont want any role based access.I have a web appl

相关标签:
3条回答
  • 2021-01-04 13:20

    To solve the problem

    sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    We follow 3 steps to instruct JDK of our app server accept cas server's certificate (in your project, it's cegicollabdev.india.tcs.com:8443)

    1. Download InstallCert.java, and copy to JDK'bin folder

      http://code.google.com/p/java-use-examples/source/browse/trunk/src/com/aw/ad/util/InstallCert.java

    2. Open command line tool with Administrator privilege (if you're on Window 7/Vista). Change to JDK's bin folder and build this java file

      javac InstallCert.java

    3. Install cas server certificate

      java InstallCert cegicollabdev.india.tcs.com:8443

      Hit 1 when prompted.

    That's all.

    0 讨论(0)
  • 2021-01-04 13:27

    Anyway single sign on is done..It took lot of time to figureout but trust me if you have a mind setup that you want to do it then anyway u will succeed ..here is the solution.. Here is my updated spring-security.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:sec="http://www.springframework.org/schema/security"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/security 
            http://www.springframework.org/schema/security/spring-security-3.1.xsd
            ">
    
    <sec:http entry-point-ref="casProcessingFilterEntryPoint" >
            <sec:intercept-url pattern="/**" access="ROLE_ADMIN" />
            <sec:logout logout-success-url="https://abc.com:8443/cas/logout" delete-cookies="JSESSIONID"/>
            <sec:custom-filter ref="requestSingleLogoutFilter" before="LOGOUT_FILTER"/>
        <sec:custom-filter ref="singleLogoutFilter" before="CAS_FILTER"/>
            <sec:custom-filter ref="casAuthenticationFilter" after="CAS_FILTER"/>
        </sec:http>
    
        <sec:authentication-manager alias="authenticationManager">
            <sec:authentication-provider ref="casAuthenticationProvider"/>
        </sec:authentication-manager>
    
    <bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
            <property name="authenticationManager" ref="authenticationManager"/>
            <property name="authenticationFailureHandler">
                <bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
                    <property name="defaultFailureUrl" value="/casfailed.jsp"/>
                </bean>
            </property>
            <property name="authenticationSuccessHandler">
                <bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
                    <property name="defaultTargetUrl" value="/"/>
                </bean>
            </property>
            <property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" />
            <property name="proxyReceptorUrl" value="/secure/receptor" />
        </bean>
    
        <bean id="casProcessingFilterEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
            <property name="loginUrl" value="https://abc.com:8443/cas/login"/>
            <property name="serviceProperties" ref="serviceProperties"/>
        </bean>
    
        <bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
            <property name="userDetailsService" ref="userService"/>
            <property name="serviceProperties" ref="serviceProperties" />
            <property name="ticketValidator">
                <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                    <constructor-arg index="0" value="https://abc.com:8443/cas" />
                    <property name="proxyGrantingTicketStorage" ref="proxyGrantingTicketStorage" />
                    <property name="proxyCallbackUrl" value="http://localhost:8080/dbcomparision/secure/receptor" />
    
                    </bean>
            </property>
            <property name="key" value="an_id_for_this_auth_provider_only"/>
        </bean>
    
       <bean id="proxyGrantingTicketStorage" class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl" />
        <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
            <property name="service" value="http://localhost:8080/dbcomparision/j_spring_cas_security_check"/>
            <property name="sendRenew" value="false"/>
        </bean>
    
        <bean id="userService" class="com.tcs.ceg.services.impl.UserServiceImpl" />
        <!-- This filter handles a Single Logout Request from the CAS Server -->
      <bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"/>
      <!-- This filter redirects to the CAS Server to signal Single Logout should be performed -->
      <bean id="requestSingleLogoutFilter"
            class="org.springframework.security.web.authentication.logout.LogoutFilter">
        <constructor-arg value="https://abc.com:8443/cas/logout"/>
        <constructor-arg>
          <bean class=
              "org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/>
        </constructor-arg>
        <property name="filterProcessesUrl" value="/j_spring_cas_security_logout"/>
      </bean>
    
    </beans>
    

    my updated web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>Spring3MVC</display-name>
      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring-rootcontext.xml
                /WEB-INF/spring-security.xml
            </param-value>
        </context-param>
          <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>
    
        <filter-mapping>
          <filter-name>springSecurityFilterChain</filter-name>
          <url-pattern>/*</url-pattern>
        </filter-mapping>
        <!--
          - Loads the root application context of this web app at startup.
        -->
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
    
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    
      <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/app/*</url-pattern>
      </servlet-mapping>
     <filter>
           <filter-name>CAS Single Sign Out Filter</filter-name>
           <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
        </filter>
     <filter-mapping>
           <filter-name>CAS Single Sign Out Filter</filter-name>
           <url-pattern>/*</url-pattern>
        </filter-mapping>
        <listener>
            <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
        </listener>
    
    </web-app>
    

    I resolved this exception javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source) by copying CAS server "cacerts" file from java\jre\lib\security of CAS server to my local java\jre\lib\security and exception was smoked.

    0 讨论(0)
  • 2021-01-04 13:28

    The simplest steps to getting CAS authentication working is to build and run the CAS sample from the Spring Security source tree.

    You really need to understand how CAS works before you try to use it, or integrate it with your application. I would start on the CAS documentation and the Spring Security reference manual which describes the interactions between CAS and Spring Security.

    j_spring_cas_security_check is the URL which the CAS redirects to in your application after it has authenticated the user (see the above link).

    Even if your application isn't authenticating users, it still typically has a concept of users it knows about. It also has to load the roles for these users, which CAS doesn't handle, hence the user-service declaration. The password won't be used.

    How your application validates that a login is successful is explained in documentation above. It basically calls the CAS server, passing in the service ticket and gets back a response with the username.

    0 讨论(0)
提交回复
热议问题