PasswordGrantTypeHandler.java revision 8945f1b58614bdedf14efc01f9830688207cca04
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014 ForgeRock AS.
*/
/**
* Handles the OAuth2 Password Credentials grant type for the 'token' endpoint.
*
* @since 12.0.0
*/
public class PasswordGrantTypeHandler implements GrantTypeHandler {
private final ClientAuthenticator clientAuthenticator;
private final ScopeValidator scopeValidator;
private final TokenStore tokenStore;
private final OAuth2ProviderSettingsFactory providerSettingsFactory;
/**
* Constructs a new PasswordGrantTypeHandler.
*
* @param clientAuthenticator An instance of the ClientAuthenticator.
* @param scopeValidator An instance of the ScopeValidator.
* @param tokenStore An instance of the TokenStore.
* @param providerSettingsFactory An instance of the OAuth2ProviderSettingsFactory.
*/
public PasswordGrantTypeHandler(final ClientAuthenticator clientAuthenticator, final ScopeValidator scopeValidator,
this.scopeValidator = scopeValidator;
this.tokenStore = tokenStore;
}
/**
* Handles the OAuth2 request for the Password Credentials grant type.
*
* @param accessTokenRequest {@inheritDoc}
* @return {@inheritDoc}
* @throws InvalidClientException If the client's registration could not be found.
* @throws InvalidGrantException If the resource owner could not be verified.
* @throws OAuth2Exception If the resource owner could not be authenticated.
*/
public AccessToken handle(final AccessTokenRequest accessTokenRequest) throws InvalidClientException,
if (resourceOwner == null) {
throw new InvalidGrantException();
}
final Set<String> validatedScope = scopeValidator.validateAccessTokenScope(clientRegistration, scope,
if (providerSettingsFactory.getProviderSettings(accessTokenRequest.getContext()).issueRefreshTokens()) {
}
if (refreshToken != null) {
}
scopeValidator.addAdditionalDataToReturnFromTokenEndpoint(accessToken, accessTokenRequest.getContext());
}
return accessToken;
}
}