OAuth2Utils.java revision f58c87ece2202b8f85310d8885c7e39a7f435c09
/*
* DO NOT REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2012 ForgeRock Inc. 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 Copyrighted [year] [name of copyright owner]"
*/
/**
* Utilities related to OAuth2.
*/
public class OAuth2Utils {
private static LogMessageProvider msgProvider;
private static Logger accessLogger;
private static Logger errorLogger;
public static boolean logStatus = false;
static {
if (logStatus) {
}
}
/**
* Logs an access message
* @param msgIdName name of message id
* @param data array of data to be logged
* @param token session token of the user who did the operation
* that triggered this logging
*/
public static void logAccessMessage(
) {
try {
if (msgProvider == null) {
}
} catch (IOException e) {
+ "disabling logging");
logStatus = false;
}
}
}
}
/**
* Logs an error message
* @param msgIdName name of message id
* @param data array of data to be logged
* @param token session token of the user who did the operation
* that triggered this logging
*/
public static void logErrorMessage(
) {
try {
if (msgProvider == null) {
}
} catch (IOException e) {
+ "disabling logging");
logStatus = false;
}
}
}
}
try {
} catch (Exception e){
}
return null;
}
public static enum ParameterLocation {
switch (this) {
case HTTP_FRAGMENT:
return null;
}
case HTTP_HEADER:
}
return null;
case HTTP_QUERY:
// Merge the parameterd from query and body
case HTTP_BODY:
}
// restore the entity body
} else if (MediaType.APPLICATION_JSON
try {
} catch (IOException e) {
throw new ResourceException(e);
}
}
}
return result;
default:
return null;
}
}
/**
* TODO How to use targetPattern?? TODO Use Custom Redirector to encode
* variables in protected Reference getTargetRef(Request request,
* Response response)
*
* @param context
* @return
*/
/*
* 3.1.2.4. Invalid Endpoint
*
* If an authorization request fails validation due to a missing,
* invalid, or mismatching redirection URI, the authorization server
* SHOULD inform the resource owner of the error, and MUST NOT
* automatically redirect the user-agent to the invalid redirection
* URI.
*/
// TODO handle non URL urn:ietf:wg:oauth:2.0:oob
switch (this) {
case HTTP_FRAGMENT: {
// Redirect URI can not contain Fragment so we can set it
break;
}
case HTTP_QUERY: {
break;
}
default:
return null;
}
}
return null;
}
}
/**
* Returns the value of the "access_token_path" parameter.
*
* @param context
* The context where to find the parameter.
* @return The value of the "access_token_path" parameter.
*/
do {
try {
getParentContext.setAccessible(true);
} catch (Exception e) {
}
} else {
}
}
/**
* Returns the value of the "access_token_path" parameter.
*
* @param context
* The context where to find the parameter.
* @return The value of the "access_token_path" parameter.
*/
do {
try {
getParentContext.setAccessible(true);
} catch (Exception e) {
}
} else {
}
}
/**
* Returns the value of the "tokeninfo_path" parameter.
*
* @param context
* The context where to find the parameter.
* @return The value of the "tokeninfo_path" parameter.
*/
}
/**
* Returns the value of the "scope_delimiter" parameter.
*
* @param context
* The context where to find the parameter.
* @return The value of the "scope_delimiter" parameter.
*/
} else {
return SCOPE_DELIMITER;
}
}
/**
* Returns the value of the "ClientVerifier" parameter.
*
* @param context
* The context where to find the parameter.
* @return The value of the "ClientVerifier" parameter.
*/
if (o instanceof ClientVerifier) {
return (ClientVerifier) o;
}
return null;
}
/**
* Returns the value of the "OAuth2TokenStore" parameter.
*
* @param context
* The context where to find the parameter.
* @return The value of the "OAuth2TokenStore" parameter.
*/
if (o instanceof OAuth2TokenStore) {
return (OAuth2TokenStore) o;
}
return null;
}
/**
* Sets the value of the "access_token_path" parameter.
*
* @param value
* The value of the "access_token_path" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Sets the value of the "authorize_path" parameter.
*
* @param value
* The value of the "authorize_path" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Sets the value of the "tokeninfo_path" parameter.
*
* @param value
* The value of the "tokeninfo_path" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Sets the value of the "scope_delimiter" parameter.
*
* @param value
* The value of the "scope_delimiter" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Sets the value of the "realm" parameter.
*
* @param value
* The value of the "realm" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Sets the value of the "scope_delimiter" parameter.
*
* @param value
* The value of the "scope_delimiter" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Sets the value of the "scope_delimiter" parameter.
*
* @param value
* The value of the "scope_delimiter" parameter
* @param context
* The context where to set the parameter.
*/
}
/**
* Get the realm from the Attributes first and then look for the realm in
* the request.
* <p/>
* Example: Restlet Template populates the realm into the
* {@link Request#attributes} {@code TemplateRoute route =
* router.attach("/oauth2/ realm}/authorize", (Restlet)authorization);}
* <p/>
* Example: Custom code fetches it from the query, the body or more secure
* from the User Session
*
* @param request
* @return
*/
}
return "/";
} else {
return ret;
}
}
}
}
}
}
}
}
}
return null;
}
/**
* It copies the given parameters only once!!!
* way the CallResolver can use it and the FreeMarker can list and add all
* into the generated form
*
* @param request
* incoming request object
* @return The modifiable attributes map.
*/
if (null != parameters) {
// Copy the parameter for CallResolver
}
// Avoid reprocess the request next time.
}
return request.getAttributes();
}
/**
* Get the parameters from the request.
* <p/>
* If the method is GET then the parameters are fetched from the query If
* query If the content type is "application/x-www-form-urlencoded" then the
* parameters are fetched from the body
*
* @param request
* incoming request object
* @return null if the request does not contains any parameter
*/
} else {
}
}
/**
* Determines if a string is empty. Empty is defined as null or empty
* string.
* <p/>
*
* <pre>
* OAuth2Utils.isEmpty(null) = true
* OAuth2Utils.isEmpty("") = true
* OAuth2Utils.isEmpty(" ") = false
* OAuth2Utils.isEmpty("bob") = false
* OAuth2Utils.isEmpty(" bob ") = false
* </pre>
*
* @param val
* string to evaluate as empty.
* @return true if the string is empty else false.
*/
}
/**
* Determines if a string is not empty. Its the exact opposite for
* {@link #isEmpty(String)}.
*
* @param val
* string to evaluate.
* @return true if the string is not empty
*/
}
/**
* <pre>
* OAuth2Utils.isBlank(null) = true
* OAuth2Utils.isBlank("") = true
* OAuth2Utils.isBlank(" ") = true
* OAuth2Utils.isBlank("bob") = false
* OAuth2Utils.isBlank(" bob ") = false
* </pre>
*/
}
}
return null;
}
}
}
return null;
}
if (isNotBlank(string)) {
while (tokenizer.hasMoreTokens()) {
}
} else {
return Collections.emptySet();
}
}
/**
* Scopes retrieved from the stored client can be in the form <scope>|<locale>|<description>. This method
* parses out the actual scope value
* @param maximumScope The allowed scopes for the client
* @return A set of strings containing the scope value only
*/
for (String s : maximumScope){
if (index == -1){
cleanScopes.add(s);
continue;
}
}
return cleanScopes;
}
/**
* Constructor.
*/
private OAuth2Utils() {
}
}