以this post 作为参考,您必须按照以下步骤操作(引用自提供的链接):
- 设计身份验证处理程序
- 向 CAS 身份验证注册身份验证处理程序
引擎。
- 告诉CAS识别注册记录和认证
配置。
创建一个扩展org.apereo.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler的类:
public class CustomAuthenticationHandler extends AbstractUsernamePasswordAuthenticationHandler {
// Constructor
public CustomAuthenticationHandler(String name, ServicesManager servicesManager, PrincipalFactory principalFactory, Integer order) {
super(name, servicesManager, principalFactory, order);
}
@Override
protected AuthenticationHandlerExecutionResult authenticateUsernamePasswordInternal(UsernamePasswordCredential credential, String originalPassword) throws GeneralSecurityException, PreventedException {
// Your logic goes here
return createHandlerResult(credential, this.principalFactory.createPrincipal(credential.getUsername()));
}
}
然后您需要将您的身份验证处理程序注册到 cas,方法是将其添加到 @Configuration 类。
@Configuration
public class CustomAuthenticationConfigurer implements AuthenticationEventExecutionPlanConfigurer{
@Autowired
ServicesManager servicesManager;
@Autowired
PrincipalFactory principalFactory;
@Bean
public AuthenticationHandler authenticationHandler(){
final CustomAuthenticationHandler athenticationHandler =
new CustomAuthenticationHandler(
"CustomAuthenticationHandler",
servicesManager,
principalFactory,
0);
return athenticationHandler;
}
@Override
public void configureAuthenticationExecutionPlan(AuthenticationEventExecutionPlan plan) {
plan.registerAuthenticationHandler(authenticationHandler());
}
}
最后一步是指示 cas 在运行时获取您的配置类。这是通过将你的配置类添加到src/main/resources/META-INF/spring.factories来完成的(如果它不存在,则创建它):
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.your_package.CustomAuthenticationConfigurer
这是我对 5.3.x 版本的工作设置,但我认为它对 5.2.x 也有效。
我假设您使用的是cas-overlay-tempalte 和java。