org.apache.oltu.oauth2.common.exception.OAuthProblemException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aem-sdk-api Show documentation
Show all versions of aem-sdk-api Show documentation
The Adobe Experience Manager SDK
/**
* Copyright 2010 Newcastle University
*
* http://research.ncl.ac.uk/smart/
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.oltu.oauth2.common.exception;
import java.util.HashMap;
import java.util.Map;
import org.apache.oltu.oauth2.common.utils.OAuthUtils;
/**
*
*
*
*/
public class OAuthProblemException extends Exception {
private String error;
private String description;
private String uri;
private String state;
private String scope;
private String redirectUri;
private int responseStatus;
private Map parameters = new HashMap();
protected OAuthProblemException(String error) {
this(error, "");
}
protected OAuthProblemException(String error, String description) {
super(error + " " + description);
this.description = description;
this.error = error;
}
public static OAuthProblemException error(String error) {
return new OAuthProblemException(error);
}
public static OAuthProblemException error(String error, String description) {
return new OAuthProblemException(error, description);
}
public OAuthProblemException description(String description) {
this.description = description;
return this;
}
public OAuthProblemException uri(String uri) {
this.uri = uri;
return this;
}
public OAuthProblemException state(String state) {
this.state = state;
return this;
}
public OAuthProblemException scope(String scope) {
this.scope = scope;
return this;
}
public OAuthProblemException responseStatus(int responseStatus) {
this.responseStatus = responseStatus;
return this;
}
public OAuthProblemException setParameter(String name, String value) {
parameters.put(name, value);
return this;
}
public String getError() {
return error;
}
public String getDescription() {
return description;
}
public String getUri() {
return uri;
}
public String getState() {
return state;
}
public String getScope() {
return scope;
}
public int getResponseStatus() {
return responseStatus == 0 ? 400 : responseStatus;
}
public String get(String name) {
return parameters.get(name);
}
public Map getParameters() {
return parameters;
}
public String getRedirectUri() {
return redirectUri;
}
public void setRedirectUri(String redirectUri) {
this.redirectUri = redirectUri;
}
@Override
public String getMessage() {
StringBuilder b = new StringBuilder();
if (!OAuthUtils.isEmpty(error)) {
b.append(error);
}
if (!OAuthUtils.isEmpty(description)) {
b.append(", ").append(description);
}
if (!OAuthUtils.isEmpty(uri)) {
b.append(", ").append(uri);
}
if (!OAuthUtils.isEmpty(state)) {
b.append(", ").append(state);
}
if (!OAuthUtils.isEmpty(scope)) {
b.append(", ").append(scope);
}
return b.toString();
}
@Override
public String toString() {
return "OAuthProblemException{" +
"error='" + error + '\'' +
", description='" + description + '\'' +
", uri='" + uri + '\'' +
", state='" + state + '\'' +
", scope='" + scope + '\'' +
", redirectUri='" + redirectUri + '\'' +
", responseStatus=" + responseStatus +
", parameters=" + parameters +
'}';
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy