markdown [Apereo CAS 3.5 CORE] Apereo CAS 3.5 #CAS的核心代码片段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown [Apereo CAS 3.5 CORE] Apereo CAS 3.5 #CAS的核心代码片段相关的知识,希望对你有一定的参考价值。

Code Snippet from [pumadong/cas-server-3.5.2](https://github.com/pumadong/cas-server-3.5.2)

### org.jasig.cas.CentralAuthenticationServiceImpl

```java
/**
 * @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

```java
@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());
}
```

以上是关于markdown [Apereo CAS 3.5 CORE] Apereo CAS 3.5 #CAS的核心代码片段的主要内容,如果未能解决你的问题,请参考以下文章

史上最详细的 Apereo CAS 5.3开发教程:二Apereo CAS 5.3 Server环境搭建,登录名,密码从数据库中获取

原创apereo cas 4.2从0开始

CAS 5.x搭建常见问题系列.Failure to find org.apereo.cas:cas-server-support-pm-jdbc:jar:5.1.9

markdown Apereo CLA

CAS5.0.X 使用经历

cas客户端集成方案