@Override public boolean supports(final Credential credential) { return this.legacyHandler.supports(credentialsAdapter.convert(credential)); }
@Override public HandlerResult authenticate(final Credential credential) throws GeneralSecurityException, PreventedException { try { if (this.legacyHandler.authenticate(credentialsAdapter.convert(credential))) { final CredentialMetaData md; if (credential instanceof CredentialMetaData) { md = (CredentialMetaData) credential; } else { md = new BasicCredentialMetaData(credential); } return new DefaultHandlerResult(this, md); } else { throw new FailedLoginException( String.format("%s failed to authenticate %s", this.getName(), credential)); } } catch (final org.jasig.cas.authentication.handler.AuthenticationException e) { throw new GeneralSecurityException( String.format("%s failed to authenticate %s", this.getName(), credential), e); } }
/** * Creates a new instance that adapts the given legacy authentication handler. * * @param legacy CAS 3.0 authentication handler. */ public LegacyAuthenticationHandlerAdapter(final org.jasig.cas.authentication.handler.AuthenticationHandler legacy) { if (!legacy.supports(new UsernamePasswordCredentials())) { throw new IllegalArgumentException( "Cannot infer credential conversion strategy - specify CredentialsAdapter explicitly."); } this.legacyHandler = legacy; this.credentialsAdapter = new UsernamePasswordCredentialsAdapter(); }