CAS Logout 通知所有登录客户端销毁Session


具体通知由org.jasig.cas.authentication.principal.AbstractWebApplicationService发出。logOutOfService方法生成发送消息,然后由org.jasig.cas.util.HttpClient的sendMessageToEndPoint方法发出。
public boolean sendMessageToEndPoint(final String url, final String message) {
HttpURLConnection connection = null;
BufferedReader in = null;
try {
if (log.isDebugEnabled()) {
log.debug("Attempting to access " + url);
}
final URL logoutUrl = new URL(url);
final String output = "logoutRequest=" + URLEncoder.encode(message, "UTF-8");

connection = (HttpURLConnection) logoutUrl.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setReadTimeout(this.readTimeout);
connection.setConnectTimeout(this.connectionTimeout);
connection.setRequestProperty("Content-Length", ""
+ Integer.toString(output.getBytes().length));
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
final DataOutputStream printout = new DataOutputStream(connection
.getOutputStream());
printout.writeBytes(output);
printout.flush();
printout.close();

in = new BufferedReader(new InputStreamReader(connection
.getInputStream()));

while (in.readLine() != null) {
// nothing to do
}

if (log.isDebugEnabled()) {
log.debug("Finished sending message to" + url);
}
return true;
} catch (final Exception e) {
log.error(e,e);
return false;
} finally {
if (in != null) {
try {
in.close();
} catch (final IOException e) {
// can't do anything
}
}
if (connection != null) {
connection.disconnect();
}
}
}

 

 

http://blog.csdn.net/redstarofsleep/article/details/51190407

http://blog.csdn.net/lovesummerforever/article/details/36386207

http://zhenkm0507.iteye.com/blog/546785

http://www.cnblogs.com/wangyang108/p/5842275.html

http://dinguangx.iteye.com/blog/1845119

http://libinchinabj.iteye.com/blog/2178155

CAS4.2单点登录如何配置多个系统登录一次和退出到登录页问题 200

1、我用CAS4.2搭建了cas服务端,客户端是3.4.1版本2、现在服务端配置好了,也可以通过我配置的客户端系统访问和查询数据库登录3、问题:我配置了两个cas系统castest1和castest2,两个系统serverName分别配置为hhaip-cas1.com和hhaip-cas2.com,现在我访问castest1且登录成功,然后同一浏览器访问castest2还是跳转到登录页面,预期应该直接跳转到我访问的页面才是4、问题2:我想退出到登录页,但是我每次都退出到我设置的那个链接,且打开浏览器新标签访问我这个系统竟然不会跳转到登录页而是直接跳转到我的系统页面,即:我可能没有退出成功,下图是我的退出URL和客户端web.xml配置。5、注意我的cas-server是4.2版本和老版本差别很大,请大家不要复制其他的代码回答问题。

最佳答案
 
对于cas4.0在cas-server.xml中搜索logoutAction,将${cas.logout.followServiceRedirects:false}中的false改成true,如下:
<bean id="logoutAction" class="org.jasig.cas.web.flow.LogoutAction"
p:servicesManager-ref="servicesManager"
p:followServiceRedirects="${cas.logout.followServiceRedirects:true}"/>
至于cas4.2,cas-server.xml中少了很多东西,把这三行放到最后试试

转载于:https://www.cnblogs.com/mostearth/p/7733092.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Security CAS集成中,可以通过`ServiceProperties`类来指定客户端应用程序的重定向URL。`ServiceProperties`类中的`service`属性定义了客户端应用程序的URL,当用户成功登录CAS后,CAS将重定向到该URL,并将用户的身份信息作为SAML响应返回给客户端应用程序。您可以在`application.properties`或`application.yml`配置文件中设置该属性,例如: **在application.properties中配置:** ``` # 客户端应用程序的URL cas.service=https://example.com/myapp # CAS服务端的URL cas.server-url=https://cas.example.com/cas # CAS服务端的登录URL cas.server-login-url=https://cas.example.com/cas/login # CAS服务端的登出URL cas.server-logout-url=https://cas.example.com/cas/logout ``` **在application.yml中配置:** ```yaml cas: # 客户端应用程序的URL service: https://example.com/myapp # CAS服务端的URL server-url: https://cas.example.com/cas # CAS服务端的登录URL server-login-url: https://cas.example.com/cas/login # CAS服务端的登出URL server-logout-url: https://cas.example.com/cas/logout ``` 在上述配置中,`cas.service`属性指定了客户端应用程序的URL,`cas.server-url`属性指定了CAS服务端的URL,`cas.server-login-url`属性指定了CAS服务端的登录URL,`cas.server-logout-url`属性指定了CAS服务端的登出URL。当用户成功登录CAS后,CAS将重定向到`cas.service`指定的URL,并将用户的身份信息作为SAML响应返回给客户端应用程序。客户端应用程序可以通过Spring Security的配置将用户身份信息与本地用户账户进行绑定,并将用户重定向到特定的路径。例如,以下是一个基于Java配置的Spring Security CAS集成示例: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private CasProperties casProperties; @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/admin/**").hasRole("ADMIN") .anyRequest().authenticated() .and() .logout() .logoutUrl("/logout") .logoutSuccessUrl("/") .and() .exceptionHandling() .authenticationEntryPoint(casAuthenticationEntryPoint()) .and() .addFilter(casAuthenticationFilter()) .addFilterBefore(casLogoutFilter(), LogoutFilter.class); } @Bean public AuthenticationEntryPoint casAuthenticationEntryPoint() { CasAuthenticationEntryPoint entryPoint = new CasAuthenticationEntryPoint(); entryPoint.setLoginUrl(casProperties.getServerLoginUrl()); entryPoint.setServiceProperties(serviceProperties()); return entryPoint; } @Bean public FilterSecurityInterceptor casAuthenticationFilter() throws Exception { CasAuthenticationFilter filter = new CasAuthenticationFilter(); filter.setAuthenticationManager(authenticationManager()); return filter; } @Bean public LogoutFilter casLogoutFilter() { LogoutFilter filter = new LogoutFilter(casProperties.getServerLogoutUrl(), new SecurityContextLogoutHandler()); filter.setFilterProcessesUrl("/logout"); return filter; } @Bean public ServiceProperties serviceProperties() { ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.setService(casProperties.getService()); serviceProperties.setSendRenew(false); return serviceProperties; } @Bean public CasAuthenticationProvider casAuthenticationProvider() { CasAuthenticationProvider provider = new CasAuthenticationProvider(); provider.setServiceProperties(serviceProperties()); provider.setTicketValidator(new Cas20ServiceTicketValidator(casProperties.getServerUrl())); provider.setUserDetailsService(userDetailsService()); provider.setKey("casAuthenticationProviderKey"); return provider; } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(casAuthenticationProvider()); } } ``` 在上述示例中,`serviceProperties()`方法返回一个`ServiceProperties`实例,其中的`setService()`方法设置了客户端应用程序的URL。在CAS登录成功后,Spring Security将重定向到该URL,并将用户的身份信息作为SAML响应返回给客户端应用程序。客户端应用程序可以使用Spring Security的默认登录成功处理器或自定义登录成功处理器来将用户重定向到特定的路径,例如: ```java @Controller public class HomeController { @RequestMapping("/") public String home() { return "home"; } @RequestMapping("/admin") public String admin() { return "admin"; } @RequestMapping("/loginSuccess") public String loginSuccess(HttpServletRequest request) { // 获取用户信息,进行绑定或其他处理 // ... // 将用户重定向到特定的路径 return "redirect:/"; } } ``` 在上述示例中,`loginSuccess()`方法是一个自定义的登录成功处理器,在该方法中可以获取用户的身份信息并将其与本地用户账户进行绑定或其他处理,最后将用户重定向到特定的路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值