【问题标题】:SPRING BOOT Configure with Jasig CAS使用 Jasig CAS 配置 SPRING BOOT
【发布时间】:2014-11-27 11:01:50
【问题描述】:

我正在制作一个测试项目,为我们未来的项目尝试 Spring Boot。

我们正在使用 jasig CAS,我正在尝试使用 spring boot 和嵌入式 tomcat 服务器进行配置。

所以我在 pom.xml 中添加 spring-boot-starter-security

之后我尝试配置 WebSecurityConfig -> spring 提供类来配置 cas,例如我需要配置一个入口点:

@Bean
public CasAuthenticationEntryPoint casAuthenticationEntryPoint() {
    CasAuthenticationEntryPoint casAuthenticationEntryPoint = new CasAuthenticationEntryPoint();
    casAuthenticationEntryPoint.setLoginUrl("https://localhost:9443/cas/login");
    casAuthenticationEntryPoint.setServiceProperties(serviceProperties());
    return casAuthenticationEntryPoint;
}

这是第一个问题:类 org.springframework.security.cas.web.CasAuthenticationEntryPoint 没有被应用程序重新识别。

该类似乎没有使用 spring-boot-starter-security 导入。

最佳做法是什么?我是否必须像以前一样在我的 pom 中手动添加依赖项?

例子:

<dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-cas</artifactId>
        <version>${spring-security.version}</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

如果是这样,我需要使用哪个版本来适应启动版本包并避免冲突?

第二点是如何配置嵌入式tomcat以启用ssl with certificate?

这是我用于 CAS 的经典 server.xml 配置:

Connector emptySessionPath="true" port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" URIEncoding="UTF-8"
    maxThreads="150" scheme="https" secure="true"
           clientAuth="false" sslProtocol="TLS" 
           keystoreFile="C:\***\***\***\.keystore" keystorePass="***"
    truststoreFile="C:\Program Files\Java\jdk1.7.0_67\jre\lib\security\cacerts"
compression="on"
     compressionMinSize="2048"
     noCompressionUserAgents="gozilla, traviata"
     compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript"/>

是否可以使用嵌入式 tomcat 配置 keystorefile/truststorefile ?

谢谢

【问题讨论】:

    标签: spring spring-security spring-boot cas


    【解决方案1】:

    我有点困惑,我正在尝试完成 SSL 配置,但仍然遇到问题。

    这是我使用 spring boot 的 tomcat 配置:

    server.port = 8080
    server.ssl.key-store = C:\\dev\\web\\tomcat\\.keystore
    server.ssl.key-store-password = changeit
    server.ssl.key-password = changeit
    server.ssl.trustStore = C:\\Program Files\\Java\\jdk1.7.0_67\\jre\\lib\\security\\cacerts
    server.ssl.trustStorePassword = changeit
    

    我启动应用程序,没问题,我在我的 CAS 服务器上被重定向,我输入登录名/密码按回车然后我得到错误:

    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
    

    这就像我的证书不起作用,但是当我以经典方式使用 tomcat(不是嵌入式,我的配置在我的第一篇文章中)时,它可以完美运行。

    我错过了什么吗?

    【讨论】:

    • 之前忘记回复了,但是是证书问题搞错了。现在一切正常!干杯
    【解决方案2】:

    假设您使用 spring-boot-starter-parent 作为项目的父项(或将其导入您自己的 &lt;dependencyManagement&gt; 部分),您不需要为 spring-security-cas 依赖项声明一个版本,因为 Boot 已经为它。你可以这样做:

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-cas</artifactId>
    </dependency>
    

    SSL 配置为covered in the reference docs。您只需要指定一些属性来配置密钥库等。例如:

    server.port = 8443
    server.ssl.key-store = keystore.jks
    server.ssl.key-store-password = secret
    server.ssl.key-password = another-secret
    

    【讨论】:

    • 注:在 application.properties 中配置 SSL 的声明式样式是新的。我还计划在 1.2.0 发布之前更改属性名称。旧版本中有一个示例向您展示了如何以编程方式进行操作。
    • 它是反向移植的,所以只要您使用的是最近的 1.1.x 版本,就可以了
    • 感谢您的快速回答安迪!
    • 依赖,其实我在doc里发现不需要放版本。我现在只需要提取我的证书(我使用的是 param truststoreFile)以与密钥库参数一起使用。
    猜你喜欢
    • 1970-01-01
    • 2020-05-09
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多