Hengliang
10/27/2017 - 10:51 AM

[Apereo CAS 3.5 CORE] The core code snippet of Apereo CAS 3.5 #CAS

[Apereo CAS 3.5 CORE] The core code snippet of Apereo CAS 3.5 #CAS

Code Snippet from pumadong/cas-server-3.5.2

org.jasig.cas.CentralAuthenticationServiceImpl

/**
 * @throws IllegalArgumentException if the credentials are null.
 */
@Audit(
    action="TICKET_GRANTING_TICKET",
    actionResolverName="CREATE_TICKET_GRANTING_TICKET_RESOLVER",
    resourceResolverName="CREATE_TICKET_GRANTING_TICKET_RESOURCE_RESOLVER")
@Profiled(tag = "CREATE_TICKET_GRANTING_TICKET", logFailuresSeparately = false)
@Transactional(readOnly = false)
public String createTicketGrantingTicket(final Credentials credentials) throws TicketCreationException {
    Assert.notNull(credentials, "credentials cannot be null");

    try {
        final Authentication authentication = this.authenticationManager
            .authenticate(credentials);

        final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl(
            this.ticketGrantingTicketUniqueTicketIdGenerator
                .getNewTicketId(TicketGrantingTicket.PREFIX),
            authentication, this.ticketGrantingTicketExpirationPolicy);

        this.ticketRegistry.addTicket(ticketGrantingTicket);
        return ticketGrantingTicket.getId();
    } catch (final AuthenticationException e) {
        throw new TicketCreationException(e);
    }
}

org.jasig.cas.authentication.AbstractAuthenticationManager

public final class AuthenticationManagerImpl extends AbstractAuthenticationManager implements AuthenticationManager

@Audit(
    action="AUTHENTICATION",
    actionResolverName="AUTHENTICATION_RESOLVER",
    resourceResolverName="AUTHENTICATION_RESOURCE_RESOLVER")
@Profiled(tag = "AUTHENTICATE", logFailuresSeparately = false)
public final Authentication authenticate(final Credentials credentials) throws AuthenticationException {

    final Pair<AuthenticationHandler, Principal> pair = authenticateAndObtainPrincipal(credentials);

    // we can only get here if the above method doesn't throw an exception. And if it doesn't, then the pair must not be null.
    final Principal p = pair.getSecond();
    log.info("{} authenticated {} with credential {}.", pair.getFirst(), p, credentials);
    log.debug("Attribute map for {}: {}", p.getId(), p.getAttributes());

    Authentication authentication = new MutableAuthentication(p);

    if (pair.getFirst()instanceof NamedAuthenticationHandler) {
        final NamedAuthenticationHandler a = (NamedAuthenticationHandler) pair.getFirst();
        authentication.getAttributes().put(AuthenticationManager.AUTHENTICATION_METHOD_ATTRIBUTE, a.getName());
    }

    // Default: this.authenticationMetaDataPopulators is empty, see deployerConfigContext.xml
    for (final AuthenticationMetaDataPopulator authenticationMetaDataPopulator : this.authenticationMetaDataPopulators) {
        authentication = authenticationMetaDataPopulator
            .populateAttributes(authentication, credentials);
    }

    return new ImmutableAuthentication(authentication.getPrincipal(),
        authentication.getAttributes());
}