AbstractFlow.java revision 8945f1b58614bdedf14efc01f9830688207cca04
/*
* DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012-2014 ForgeRock AS. All rights reserved.
*
* 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
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* 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]"
*/
/**
* Defines an abstract OAuth2 flow and the flow helper methods.
*/
public abstract class AbstractFlow extends ServerResource {
protected boolean fragment = false;
if (null == clientVerifier) {
"ClientVerifier is not initialised");
}
return clientVerifier;
}
if (null == tokenStore) {
"Token store is not initialised");
}
return tokenStore;
}
/**
* Set-up method that can be overridden in order to initialize the state of
* the resource. By default it does nothing.
*
* @see #init(Context, Request, Response)
*/
protected void doInit() throws ResourceException {
}
/**
* Handles a call by first verifying the optional request conditions and
* continue the processing if possible. Note that in order to evaluate those
* conditions, {@link #getInfo()} or
* {@link #getInfo(org.restlet.representation.Variant)} methods might be
* invoked.
*
* @return The response entity.
* @throws ResourceException
*/
fragment = false;
// -------------------------------------
// Add Cache-Control: no-store
// Pragma: no-cache
// -------------------------------------
if (additionalHeaders == null) {
}
return super.doConditionalHandle();
}
/**
* Effectively handles a call without content negotiation of the response
* entity. The default behavior is to dispatch the call to one of the
* {@link #get()}, {@link #post(org.restlet.representation.Representation)},
* {@link #put(org.restlet.representation.Representation)},
* {@link #delete()}, {@link #head()} or {@link #options()} methods.
*
* @return The response entity.
* @throws org.restlet.resource.ResourceException
*
*/
return super.doHandle();
}
this.endpointType = endpointType;
}
/**
* Invoked when an error or an exception is caught during initialization,
* handling or releasing. By default, updates the responses's status with
* the result of
* {@link org.restlet.service.StatusService#getStatus(Throwable, org.restlet.resource.Resource)}
* .
*
* @param throwable
* The caught error or exception.
*/
if (throwable instanceof OAuthProblemException) {
new Redirector(new Context(), exception.getRedirectUri().toString(), Redirector.MODE_CLIENT_PERMANENT);
return;
} else {
}
switch (endpointType) {
case TOKEN_ENDPOINT: {
break;
}
case AUTHORIZATION_ENDPOINT: {
if (fragment){
} else {
}
if (null != dispatcher) {
} else {
// TODO Introduce new method
}
}
break;
}
default: {
}
}
} else {
// TODO Use custom StatusServer to set the proper status
.getMessage()));
// super.doCatch(throwable);
}
}
}
}
// TODO Use flexible util to detect the client-agent and select the proper
// display
try {
} catch (IllegalArgumentException e) {
}
}
Representation r = null;
try {
} catch (IOException e) {
"Server can not serve the content of authorization page");
}
} else {
}
if (null != r) {
return r;
}
"Server can not serve the content of authorization page");
}
+ "/" + templateName;
if (factory instanceof TemplateFactory) {
} else {
}
}
return result;
}
/**
* Validate the {@code redirectionURI} and return an object used in the
* session.
* <p/>
* Throws {@link OAuthProblemException.OAuthError#REDIRECT_URI_MISMATCH}
*
* @return
* @throws OAuthProblemException
*/
protected OAuth2Client validateRemoteClient() {
switch (endpointType) {
case AUTHORIZATION_ENDPOINT: {
String.class);
return new OAuth2Client(client);
} else {
/*
* unauthorized_client The client is not authorized to request
* an authorization code using this method.
*/
}
}
case TOKEN_ENDPOINT: {
return getAuthenticatedClient();
}
default: {
return null;
}
}
}
}
}
"The authorization server can not authenticate the client.");
}
protected void validateMethod() throws OAuthProblemException {
switch (endpointType) {
case AUTHORIZATION_ENDPOINT: {
.getMethod()))) {
}
break;
}
case TOKEN_ENDPOINT: {
}
break;
}
default: {
}
}
}
protected void validateContentType() throws OAuthProblemException {
switch (endpointType) {
case AUTHORIZATION_ENDPOINT: {
.getMediaType())) {
"Invalid Content Type");
}
}
case TOKEN_ENDPOINT: {
.getMediaType())) {
"Invalid Content Type");
}
}
default: {
}
}
}
protected void validateRequiredParameters() throws OAuthProblemException {
boolean isClientID = false;
}
isClientID = true;
}
}
}
.toString());
.toString());
}
}
}
protected String[] getRequiredParameters() {
return null;
}
try {
.getScopeDelimiter(getContext())));
OAuth2ProviderSettings settings = OAuth2ConfigurationFactory.Holder.getConfigurationFactory().getOAuth2ProviderSettings(getRequest());
}
} catch (Exception e){
checkedScope = null;
scopeClass = null;
}
// Validate the granted scope
} else {
throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(null, "No setting set for scope plugin class");
}
return checkedScope;
}
protected String getGrantType() {
return OAuth2Utils.getRequestParameter(getRequest(), OAuth2Constants.Params.GRANT_TYPE, String.class);
}
}