cas服务端自动登录
应用场景
在信任的第三方系统登录成功后,无需用户账号密码登录,实现后台cas自动登录
具体流程
1、第三方系统登录成功后,回调cas指定的方法;
2、cas根据携带的用户信息,生成票据;
3、带着票据进行cas登录;
代码实现
CAS Server采用CAS Server 3.5.2版本,使用cas-server-core-3.5.2.jar包
private CentralAuthenticationService centralAuthenticationService;
private CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator;
//具体生成相关票据并绑定注册 实现方法
protected Boolean bindTicketGrantingTicket(String userName, HttpServletRequest request, HttpServletResponse response) {
try {
UsernamePasswordCredentialscredentials = new UsernamePasswordCredentials();
credentials.setUsername(userName);
String ticketGrantingTicket = centralAuthenticationService.createTicketGrantingTicket(credentials);
ticketGrantingTicketCookieGenerator.addCookie(request, response, ticketGrantingTicket);
return true;
} catch (TicketException te) {
logger.error("Validate the login name " + loginName + " failure, can't bind the TGT!", te);
} catch (Exception e) {
logger.error("bindTicketGrantingTicket has exception.", e);
}
return false;
}
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/baidu_35030309/article/details/127243470