简体   繁体   English

使用Spring Security 3实施CAS

[英]Implementing CAS with Spring Security 3

I currently have spring security configured and working correctly. 我目前已经配置了Spring Security并且可以正常工作。 I want to get CAS working so I can have a single sign on across multiple apps I've written. 我想让CAS工作,这样我就可以跨编写的多个应用程序进行单一登录。 I am confused how I can make cas use my custom userdetailService. 我对如何使cas使用自定义的userdetailService感到困惑。

Currently I have this is my spring-security.xml 目前我有这是我的spring-security.xml

    <authentication-manager alias="authManager">
        <authentication-provider user-service-ref="userDetailsService">
            <password-encoder ref="passwordEncoder">
                <salt-source ref="saltSource"/>
            </password-encoder>
        </authentication-provider>
    </authetication-manager>

From all the cas examples I have found they say to do implement the manage this way: 从所有的cas例子中,我发现他们说要以这种方式实现管理:

<beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
    <beans:property name="authenticationUserDetailsService">
        <beans:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
            <beans:constructor-arg ref="userDetailsService"/>
        </beans:bean>
    </beans:property>
    <beans:property name="serviceProperties" ref="serviceProperties"/>
    <beans:property name="ticketValidator">
        <beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
            <beans:constructor-arg index="0" value="https://localhost:8443/cas"/>
        </beans:bean>
    </beans:property>
    <beans:property name="key" value="1234554321"/>
</beans:bean>

<authentication-manager alias="authManager">
    <authentication-provider ref="casAuthenticationProvider"/>
</authentication-manager>

The documentation is confusing. 该文档令人困惑。 How do I go from a working spring-security app to one that implements cas and still use my custom user details? 如何从工作正常的spring-security应用程序转到实现cas并仍使用我的自定义用户详细信息的应用程序? Also what do I need to change on the jsp pages? 另外,我需要在jsp页面上进行哪些更改? Any help would be much appreciated. 任何帮助将非常感激。

Thanks 谢谢

I think you want CAS to authenticate the password using your own password+salt encoder. 我想您希望CAS使用您自己的密码+盐编码器对密码进行身份验证。

Unfortunately, it is not a straight forward configuration and the configuration is not in your Spring apps. 不幸的是,这不是直接的配置,并且该配置不在您的Spring应用程序中。 You need to recompile CAS to include your custom password+salt encoder. 您需要重新编译CAS以包括您的自定义密码+盐编码器。 Thus, when Spring calls CAS for authentication, the same custom password+salt encoder will be used. 因此,当Spring调用CAS进行身份验证时,将使用相同的自定义密码+盐编码器。

Fortunately, CAS team has created WAR Overlay approach so that it is easy for the user to recompile CAS server in order to include custom password+salt encoders 幸运的是,CAS团队创建了WAR Overlay方法,以便用户可以轻松地重新编译CAS服务器以包括自定义密码+盐编码器

The documentation is here https://wiki.jasig.org/display/CASUM/Best+Practice+-+Setting+Up+CAS+Locally+using+the+Maven2+WAR+Overlay+Method 该文档位于https://wiki.jasig.org/display/CASUM/Best+Practice+-+Setting+Up+CAS+Local++using+the+Maven2+WAR+Overlay+Method

You need to be very patient to follow the steps and make sure that your system has Maven2 You need not to download any library as Maven will take care of that. 您需要非常有耐心地遵循这些步骤,并确保您的系统具有Maven2。您无需下载任何库,因为Maven会解决这一问题。 The basic idea of WAR Overlay approach is to create a maven controlled folder where you can create subfolders to add your custom java libraries. WAR Overlay方法的基本思想是创建一个maven控制的文件夹,您可以在其中创建子文件夹来添加自定义Java库。

Maven will used to recompiled the custom java code together with the CAS files to produce a WAR file where you can publish it to a SSL server. Maven将用于重新编译自定义Java代码以及CAS文件,以生成WAR文件,您可以在其中将其发布到SSL服务器。

Just make sure that both CAS and your Spring Apps are using SSL. 只要确保CAS和您的Spring Apps都使用SSL。

Good luck! 祝好运!

Here are the steps I would recommend when setting up a CAS infrastructure 这是设置CAS基础结构时建议的步骤

  1. First of all, you should be aware of what CAS is, and how it works. 首先,您应该了解什么是CAS及其工作方式。 Check out this article and the jasig-webpage. 查看本文和jasig-webpage。
  2. Then download the examples from Spring Source , make the cas-sample run, and play with it to get a better feeling of it. 然后从Spring Source下载示例 ,运行cas-sample,并对其进行操作以获得更好的感觉。 (I'm not sure whether there is a readme file or you get infos on how to use it on the spring source webpage, but there is definitely info out there) (我不确定在spring源网页上是否有自述文件或您是否获得了有关如何使用该文件的信息,但肯定那里有信息)
  3. Make your app authenticate against this simple CAS-Server (find config examples on the CAS webpage) 使您的应用程序针对此简单的CAS服务器进行身份验证(在CAS网页上找到配置示例)
  4. Setup and configure your own CAS-Server that uses your current authentication system to authorize a user. 设置和配置您自己的CAS服务器,该服务器使用当前的身份验证系统来授权用户。
    • you may use the SAML protocol to transfer roles etc from the CAS to the client app after authentication 您可以在身份验证后使用SAML协议将角色等从CAS转移到客户端应用
    • to apply the roles at the client app you may need to implement that on your own. 要将角色应用到客户端应用程序,您可能需要自己实施。
  5. Adapt other apps to use the CAS-Server 调整其他应用程序以使用CAS服务器

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

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