使用jasig CAS 3.5.X,我有一个自定义身份验证方法。我所要做的就是在deployerConfigContext.xml中添加扩展AbstractUsernamePasswordAuthenticationHandler的类,并在类路径中添加依赖项。
我似乎无法在Apereo 5.2.X中找到有关如何执行此操作的文档。任何提示?
发现这个https://apereo.github.io/cas/5.2.x/installation/Configuring-Custom-Authentication.html
但没有关于构造函数参数的信息......
以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
。