Search in sources :

Example 6 with CacheKey

use of org.apache.nifi.web.security.util.CacheKey in project nifi by apache.

the class OidcService method createState.

/**
 * Initiates an OpenId Connection authorization code flow using the specified request identifier to maintain state.
 *
 * @param oidcRequestIdentifier request identifier
 * @return state
 */
public State createState(final String oidcRequestIdentifier) {
    if (!isOidcEnabled()) {
        throw new IllegalStateException(OPEN_ID_CONNECT_SUPPORT_IS_NOT_CONFIGURED);
    }
    final CacheKey oidcRequestIdentifierKey = new CacheKey(oidcRequestIdentifier);
    final State state = new State(generateStateValue());
    try {
        synchronized (stateLookupForPendingRequests) {
            final State cachedState = stateLookupForPendingRequests.get(oidcRequestIdentifierKey, () -> state);
            if (!timeConstantEqualityCheck(state.getValue(), cachedState.getValue())) {
                throw new IllegalStateException("An existing login request is already in progress.");
            }
        }
    } catch (ExecutionException e) {
        throw new IllegalStateException("Unable to store the login request state.");
    }
    return state;
}
Also used : State(com.nimbusds.oauth2.sdk.id.State) ExecutionException(java.util.concurrent.ExecutionException) CacheKey(org.apache.nifi.web.security.util.CacheKey)

Aggregations

CacheKey (org.apache.nifi.web.security.util.CacheKey)6 ExecutionException (java.util.concurrent.ExecutionException)2 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)2 State (com.nimbusds.oauth2.sdk.id.State)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1