Apereo CAS 5.2.X如何使用自定义身份验证处理程序

时间:2018-02-05 23:09:30

标签: cas

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

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

1 个答案:

答案 0 :(得分:0)

this post作为参考,您必须执行以下步骤(从提供的链接中引用):

  
      
  1. 设计身份验证处理程序
  2.   
  3. 使用CAS身份验证注册身份验证处理程序   引擎。
  4.   
  5. 告诉CAS识别注册记录和身份验证   配置。
  6.   

创建一个扩展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()));            
    } 
}

然后,您需要通过将其添加到@Configuration类来向cas注册身份验证处理程序。

@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