【问题标题】:Apereo CAS 5.2.X how do I use a custom authentication handlerApereo CAS 5.2.X 如何使用自定义身份验证处理程序
【发布时间】:2018-02-05 23:09:29
【问题描述】:

使用 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

但没有关于构造函数参数的信息...

【问题讨论】:

  • 你最终成功了吗?
  • @Newbee 没有。转向更有成效的工作。

标签: cas


【解决方案1】:

this post 作为参考,您必须按照以下步骤操作(引用自提供的链接):

  1. 设计身份验证处理程序
  2. 向 CAS 身份验证注册身份验证处理程序 引擎。
  3. 告诉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-tempaltejava

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2020-01-07
    • 2018-07-11
    • 2022-11-08
    • 2016-04-18
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    相关资源
    最近更新 更多