没有属性传给客户端
Cas no attributes come to client
我正在使用 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中,验证票据时的服务器响应是这样的:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>casuser</cas:user>
</cas:authenticationSuccess>
</cas:serviceResponse>
它根本不包含任何属性。无法弄清楚缺少什么。
考虑到 cas 配置几乎是默认配置,这是我的 spring 配置(我使用 spring 引导来配置客户端):
@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 协议和 return 值。这是变化:
@Bean
public TicketValidator ticketValidator() {
return new Cas20ServiceTicketValidator("https://localhost:8443/cas/p3");
}
文档可能会更清楚一点(现在我知道了答案,但看起来确实很明显)。
希望这可以帮助需要使用 cas.
配置 spring 安全性的人
我正在使用 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中,验证票据时的服务器响应是这样的:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>casuser</cas:user>
</cas:authenticationSuccess>
</cas:serviceResponse>
它根本不包含任何属性。无法弄清楚缺少什么。 考虑到 cas 配置几乎是默认配置,这是我的 spring 配置(我使用 spring 引导来配置客户端):
@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 协议和 return 值。这是变化:
@Bean
public TicketValidator ticketValidator() {
return new Cas20ServiceTicketValidator("https://localhost:8443/cas/p3");
}
文档可能会更清楚一点(现在我知道了答案,但看起来确实很明显)。 希望这可以帮助需要使用 cas.
配置 spring 安全性的人