Hi

I've followed this document: 
https://apereo.github.io/cas/5.1.x/installation/Configuring-Custom-Authentication.html
to design my own authentication handler, but I found that I can't construct 
the handler in the PlanConfiguration cause I don't know how to pass a 
ServicesManager object
to the constructor.
So I followed this thread: 
https://groups.google.com/forum/#!topic/jasig-cas-user/ddCmLLTxeGU then
1 define my own handler which implements AuthenticationHandler
2 add just some static accounts
3 add the AuthenticationConfiguration class to spring.factories.

But I failed. It gives me warning message: Authentication has failed. 
Credentials may be incorrect or CAS cannot find authentication handler that 
supports [admin] of type [UsernamePasswordCredential], which suggests a 
configuration problem.

Here is my code:

@Override
    public HandlerResult authenticate(Credential credential) throws 
GeneralSecurityException, PreventedException {
        final UsernamePasswordCredential upc = (UsernamePasswordCredential) 
credential;
        PrincipalFactory pf = new DefaultPrincipalFactory();
        if (upc.getUsername().equals("admin") && 
upc.getPassword().equals("123")) {
            return new DefaultHandlerResult(this, new 
BasicCredentialMetaData(credential), pf.createPrincipal(upc.getUsername()));
        } else if (upc.getUsername().equals("sysadmin")) {
            throw new AccountDisabledException("Sorry, this account has 
been disabled.");
        }
        throw new FailedLoginException("Sorry, login failed!");
    }

    @Override
    public boolean supports(Credential credential) {
        return credential instanceof UsernamePasswordCredential;
    }

    @Override
    public String getName() {
        return getClass().getSimpleName();
    }

    @Override
    public int getOrder() {
        return 0;
    }

-- 
- CAS gitter chatroom: https://gitter.im/apereo/cas
- CAS mailing list guidelines: https://apereo.github.io/cas/Mailing-Lists.html
- CAS documentation website: https://apereo.github.io/cas
- CAS project website: https://github.com/apereo/cas
--- 
You received this message because you are subscribed to the Google Groups "CAS 
Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/apereo.org/d/msgid/cas-user/54f6f11b-3750-40d5-aee3-c8430fdb5f97%40apereo.org.

Reply via email to