我正在使用 CAS 构建 SSO 应用程序。在 Spring 客户端中,CasAssertionAuthenticationToken
没有附带任何属性。
网上有很多样本,他们似乎对此没有问题(是不是明显遗漏了一些东西?)
对于 cas 服务器,它是所有默认配置,除了我更改了注册服务默认值以确保这不是问题。这部分看起来像这样:
<bean class="org.jasig.cas.services.RegexRegisteredService">
<property name="id" value="1"/>
<property name="name" value="HTTP and IMAP"/>
<property name="description" value="Allows HTTP(S) and IMAP(S)"/>
<property name="serviceId" value="^(https?|imaps?)://.*"/>
<property name="evaluationOrder" value="0"/>
<property name="ignoreAttributes" value="true"/>
<property name="attributeFilter">
<bean class="org.jasig.cas.services.support.RegisteredServiceDefaultAttributeFilter"/>
</property>
</bean>
调试结果时,将释放 3 个预定义属性!!
在spring中,验证ticket时服务器响应是这样的:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>casuser</cas:user>
</cas:authenticationSuccess>
</cas:serviceResponse>
它根本不包含任何属性。无法弄清楚缺少什么。 考虑到 cas 配置几乎是默认配置,这是我的 spring 配置(我使用 spring boot 来配置客户端):
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class Security extends WebSecurityConfigurerAdapter {
@Bean
public ServiceProperties serviceProperties() {
ServiceProperties prop = new ServiceProperties();
prop.setService("http://localhost:8180/j_spring_cas_security_check");
prop.setSendRenew(true);
return prop;
}
@Bean
public AuthenticationProvider casAuthenticationProvider() {
CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider();
casAuthenticationProvider.setAuthenticationUserDetailsService(authenticationUserDetailsService());
casAuthenticationProvider.setServiceProperties(serviceProperties());
casAuthenticationProvider.setTicketValidator(ticketValidator());
casAuthenticationProvider.setKey("test_app_key");
return casAuthenticationProvider;
}
@Bean
public AuthenticationUserDetailsService<CasAssertionAuthenticationToken> authenticationUserDetailsService() {
return new TestCasAuthenticationUserDetailsService();
}
@Bean
public TicketValidator ticketValidator() {
return new Cas20ServiceTicketValidator("https://localhost:8443/cas");
}
@Bean
public CasAuthenticationEntryPoint casAuthenticationEntryPoint() {
CasAuthenticationEntryPoint casAuthenticationEntryPoint = new CasAuthenticationEntryPoint();
casAuthenticationEntryPoint.setLoginUrl("https://localhost:8443/cas/login");
casAuthenticationEntryPoint.setServiceProperties(serviceProperties());
return casAuthenticationEntryPoint;
}
@Bean
public CasAuthenticationFilter casAuthenticationFilter() throws Exception {
CasAuthenticationFilter casAuthenticationFilter = new CasAuthenticationFilter();
casAuthenticationFilter.setAuthenticationManager(authenticationManager());
return casAuthenticationFilter;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.addFilter(casAuthenticationFilter());
http
.exceptionHandling()
.authenticationEntryPoint(casAuthenticationEntryPoint());
http.authorizeRequests()
.anyRequest().authenticated();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.authenticationProvider(casAuthenticationProvider());
}
}
谁能告诉我我缺少的明显部分是什么?
最佳答案
哇。我不相信。
这一切都只是为了一个p3!
TicketValidator
url 必须以 /p3
结尾,以便它使用 cas 3.0 协议(protocol)并返回值。这是变化:
@Bean
public TicketValidator ticketValidator() {
return new Cas20ServiceTicketValidator("https://localhost:8443/cas/p3");
}
文档可能会更清楚一点(现在我知道答案了,但它看起来确实很明显)。 希望这可以帮助需要使用 cas 配置 spring security 的人。
关于java - Cas 没有属性到达客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29744496/