AllSuccessfulStrategy class source code analysis

The AllSuccessfulStrategy class mainly returns the authentication information returned after all the authentication is successful. It inherits the AbstractAuthenticationStrategy abstraction and parses it 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. AllSuccessfulStrategy class

2.1. The operation before each realm authentication (verify whether the realm supports token, if so, return the authentication information, if not, throw an exception, this method overrides the method of AbstractAuthenticationStrategy)

public AuthenticationInfo beforeAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo info) throws AuthenticationException {
        if (!realm.supports(token)) {
            String msg = "Realm [" + realm + "] of type [" + realm.getClass().getName() + "] does not support " +
                    " the submitted AuthenticationToken [" + token + "].  The [" + getClass().getName() +
                    "] implementation requires all configured realm(s) to support and be able to process the submitted " +
                    "AuthenticationToken.";
            throw new UnsupportedTokenException(msg);
        }

        return info;
    }

2.2. Operation after each realm verification (if the received exception information is not empty, an exception is thrown, if the returned exception information is empty, the current authentication information and the previous authentication information are merged, this method overrides AbstractAuthenticationStrategy Methods)

public AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo info, AuthenticationInfo aggregate, Throwable t)
            throws AuthenticationException {
        if (t != null) {
            if (t instanceof AuthenticationException) {
                //propagate:
                throw ((AuthenticationException) t);
            } else {
                String msg = "Unable to acquire account data from realm [" + realm + "].  The [" +
                        getClass().getName() + " implementation requires all configured realm(s) to operate successfully " +
                        "for a successful authentication.";
                throw new AuthenticationException(msg, t);
            }
        }
        if (info == null) {
            String msg = "Realm [" + realm + "] could not find any associated account data for the submitted " +
                    "AuthenticationToken [" + token + "].  The [" + getClass().getName() + "] implementation requires " +
                    "all configured realm(s) to acquire valid account data for a submitted token during the " +
                    "log-in process.";
            throw new UnknownAccountException(msg);
        }

        log.debug("Account successfully authenticated using realm [{}]", realm);

        // If non-null account is returned, then the realm was able to authenticate the
        // user - so merge the account with any accumulated before:
        merge(info, aggregate);

        return aggregate;
    }

Guess you like

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