FirstSuccessfulStrategy class source code analysis

The FirstSuccessfulStrategy class mainly returns the authentication information for the first successful authentication. It inherits the AbstractAuthenticationStrategy abstract class. The first analysis is as follows:

1.AbstractAuthenticationStrategy abstract class

This abstract class can refer to the source code analysis of the AbstractAuthenticationStrategy abstract class. It mainly implements beforeAllAttempts (operations performed before all realm authentication), beforeAttempt (operations performed before a certain realm authentication), afterAttempt (operations performed after a certain realm authentication), merge (the combination of the authentication information of the previous authentication and the authentication information obtained after the current realm authentication), afterAllAttempts (the operation after all the realm authentication is completed).

2. FirstSuccessfulStrategy class (the first authentication success strategy)

2.1. All authentications return empty before (overrides the method of AbstractAuthenticationStrategy)

public AuthenticationInfo beforeAllAttempts(Collection<? extends Realm> realms, AuthenticationToken token) throws AuthenticationException {
        return null;
}

2.2. Combination of authentication information (if the previous authentication result aggregate is not empty, it proves that the authentication has been successful, and the aggregate is returned; if the previous authentication result aggregate is empty, and the current authentication result info is not empty, the current authentication result is returned. As a result, the methods of AbstractAuthenticationStrategy are overridden)

protected AuthenticationInfo merge(AuthenticationInfo info, AuthenticationInfo aggregate) {
        if (aggregate != null && !CollectionUtils.isEmpty(aggregate.getPrincipals())) {
            return aggregate;
        }
        return info != null ? info : aggregate;
    }

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326613002&siteId=291194637