use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.
the class RedirectUtil method getRedirectResponseBuilder.
public static ResponseBuilder getRedirectResponseBuilder(RedirectUri redirectUriResponse, HttpServletRequest httpRequest) {
ResponseBuilder builder;
if (httpRequest != null && httpRequest.getHeader(NO_REDIRECT_HEADER) != null) {
try {
URI redirectURI = URI.create(redirectUriResponse.toString());
JSONObject jsonObject = new JSONObject();
jsonObject.put(JSON_REDIRECT_PROPNAME, redirectURI.toURL());
String jsonResp = jsonObject.toString();
jsonResp = jsonResp.replace("\\/", "/");
builder = Response.ok(new GenericEntity<String>(jsonResp, String.class), MediaType.APPLICATION_JSON_TYPE);
} catch (MalformedURLException e) {
builder = Response.serverError();
log.debug(e.getMessage(), e);
} catch (JSONException e) {
builder = Response.serverError();
log.debug(e.getMessage(), e);
}
} else if (redirectUriResponse.getResponseMode() != ResponseMode.FORM_POST) {
URI redirectURI = URI.create(redirectUriResponse.toString());
builder = new ResponseBuilderImpl();
builder = Response.status(HTTP_REDIRECT);
builder.location(redirectURI);
} else {
builder = new ResponseBuilderImpl();
builder.status(Response.Status.OK);
builder.type(MediaType.TEXT_HTML_TYPE);
builder.cacheControl(CacheControl.valueOf("no-cache, no-store"));
builder.header("Pragma", "no-cache");
builder.entity(redirectUriResponse.toString());
}
return builder;
}
use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.
the class TokenRestWebServiceImpl method getJSonResponse.
/**
* Builds a JSon String with the structure for token issues.
*/
public String getJSonResponse(AccessToken accessToken, TokenType tokenType, Integer expiresIn, RefreshToken refreshToken, String scope, IdToken idToken) {
JSONObject jsonObj = new JSONObject();
try {
// Required
jsonObj.put("access_token", accessToken.getCode());
// Required
jsonObj.put("token_type", tokenType.toString());
if (expiresIn != null) {
// Optional
jsonObj.put("expires_in", expiresIn);
}
if (refreshToken != null) {
// Optional
jsonObj.put("refresh_token", refreshToken.getCode());
}
if (scope != null) {
// Optional
jsonObj.put("scope", scope);
}
if (idToken != null) {
jsonObj.put("id_token", idToken.getCode());
}
} catch (JSONException e) {
log.error(e.getMessage(), e);
}
return jsonObj.toString();
}
use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.
the class OpenIdConfiguration method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param servletRequest servlet request
* @param servletResponse servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
httpResponse.setContentType("application/json");
PrintWriter out = httpResponse.getWriter();
try {
JSONObject jsonObj = new JSONObject();
jsonObj.put(ISSUER, appConfiguration.getIssuer());
jsonObj.put(AUTHORIZATION_ENDPOINT, appConfiguration.getAuthorizationEndpoint());
jsonObj.put(TOKEN_ENDPOINT, appConfiguration.getTokenEndpoint());
jsonObj.put(USER_INFO_ENDPOINT, appConfiguration.getUserInfoEndpoint());
jsonObj.put(CLIENT_INFO_ENDPOINT, appConfiguration.getClientInfoEndpoint());
jsonObj.put(CHECK_SESSION_IFRAME, appConfiguration.getCheckSessionIFrame());
jsonObj.put(END_SESSION_ENDPOINT, appConfiguration.getEndSessionEndpoint());
jsonObj.put(JWKS_URI, appConfiguration.getJwksUri());
jsonObj.put(REGISTRATION_ENDPOINT, appConfiguration.getRegistrationEndpoint());
jsonObj.put(ID_GENERATION_ENDPOINT, appConfiguration.getIdGenerationEndpoint());
jsonObj.put(INTROSPECTION_ENDPOINT, appConfiguration.getIntrospectionEndpoint());
JSONArray scopesSupported = new JSONArray();
for (Scope scope : scopeService.getAllScopesList()) {
boolean isUmaAuthorization = UmaScopeType.AUTHORIZATION.getValue().equals(scope.getDisplayName());
boolean isUmaProtection = UmaScopeType.PROTECTION.getValue().equals(scope.getDisplayName());
if (!isUmaAuthorization && !isUmaProtection)
scopesSupported.put(scope.getDisplayName());
}
if (scopesSupported.length() > 0) {
jsonObj.put(SCOPES_SUPPORTED, scopesSupported);
}
JSONArray responseTypesSupported = new JSONArray();
for (String responseType : appConfiguration.getResponseTypesSupported()) {
responseTypesSupported.put(responseType);
}
if (responseTypesSupported.length() > 0) {
jsonObj.put(RESPONSE_TYPES_SUPPORTED, responseTypesSupported);
}
JSONArray grantTypesSupported = new JSONArray();
for (String grantType : appConfiguration.getGrantTypesSupported()) {
grantTypesSupported.put(grantType);
}
if (grantTypesSupported.length() > 0) {
jsonObj.put(GRANT_TYPES_SUPPORTED, grantTypesSupported);
}
JSONArray acrValuesSupported = new JSONArray();
for (String acr : externalAuthenticationService.getAcrValuesList()) {
acrValuesSupported.put(acr);
}
jsonObj.put(ACR_VALUES_SUPPORTED, acrValuesSupported);
jsonObj.put(AUTH_LEVEL_MAPPING, createAuthLevelMapping());
JSONArray subjectTypesSupported = new JSONArray();
for (String subjectType : appConfiguration.getSubjectTypesSupported()) {
subjectTypesSupported.put(subjectType);
}
if (subjectTypesSupported.length() > 0) {
jsonObj.put(SUBJECT_TYPES_SUPPORTED, subjectTypesSupported);
}
JSONArray userInfoSigningAlgValuesSupported = new JSONArray();
for (String userInfoSigningAlg : appConfiguration.getUserInfoSigningAlgValuesSupported()) {
userInfoSigningAlgValuesSupported.put(userInfoSigningAlg);
}
if (userInfoSigningAlgValuesSupported.length() > 0) {
jsonObj.put(USER_INFO_SIGNING_ALG_VALUES_SUPPORTED, userInfoSigningAlgValuesSupported);
}
JSONArray userInfoEncryptionAlgValuesSupported = new JSONArray();
for (String userInfoEncryptionAlg : appConfiguration.getUserInfoEncryptionAlgValuesSupported()) {
userInfoEncryptionAlgValuesSupported.put(userInfoEncryptionAlg);
}
if (userInfoEncryptionAlgValuesSupported.length() > 0) {
jsonObj.put(USER_INFO_ENCRYPTION_ALG_VALUES_SUPPORTED, userInfoEncryptionAlgValuesSupported);
}
JSONArray userInfoEncryptionEncValuesSupported = new JSONArray();
for (String userInfoEncryptionEnc : appConfiguration.getUserInfoEncryptionEncValuesSupported()) {
userInfoEncryptionEncValuesSupported.put(userInfoEncryptionEnc);
}
if (userInfoEncryptionAlgValuesSupported.length() > 0) {
jsonObj.put(USER_INFO_ENCRYPTION_ENC_VALUES_SUPPORTED, userInfoEncryptionAlgValuesSupported);
}
JSONArray idTokenSigningAlgValuesSupported = new JSONArray();
for (String idTokenSigningAlg : appConfiguration.getIdTokenSigningAlgValuesSupported()) {
idTokenSigningAlgValuesSupported.put(idTokenSigningAlg);
}
if (idTokenSigningAlgValuesSupported.length() > 0) {
jsonObj.put(ID_TOKEN_SIGNING_ALG_VALUES_SUPPORTED, idTokenSigningAlgValuesSupported);
}
JSONArray idTokenEncryptionAlgValuesSupported = new JSONArray();
for (String idTokenEncryptionAlg : appConfiguration.getIdTokenEncryptionAlgValuesSupported()) {
idTokenEncryptionAlgValuesSupported.put(idTokenEncryptionAlg);
}
if (idTokenEncryptionAlgValuesSupported.length() > 0) {
jsonObj.put(ID_TOKEN_ENCRYPTION_ALG_VALUES_SUPPORTED, idTokenEncryptionAlgValuesSupported);
}
JSONArray idTokenEncryptionEncValuesSupported = new JSONArray();
for (String idTokenEncryptionEnc : appConfiguration.getIdTokenEncryptionEncValuesSupported()) {
idTokenEncryptionEncValuesSupported.put(idTokenEncryptionEnc);
}
if (idTokenEncryptionEncValuesSupported.length() > 0) {
jsonObj.put(ID_TOKEN_ENCRYPTION_ENC_VALUES_SUPPORTED, idTokenEncryptionEncValuesSupported);
}
JSONArray requestObjectSigningAlgValuesSupported = new JSONArray();
for (String requestObjectSigningAlg : appConfiguration.getRequestObjectSigningAlgValuesSupported()) {
requestObjectSigningAlgValuesSupported.put(requestObjectSigningAlg);
}
if (requestObjectSigningAlgValuesSupported.length() > 0) {
jsonObj.put(REQUEST_OBJECT_SIGNING_ALG_VALUES_SUPPORTED, requestObjectSigningAlgValuesSupported);
}
JSONArray requestObjectEncryptionAlgValuesSupported = new JSONArray();
for (String requestObjectEncryptionAlg : appConfiguration.getRequestObjectEncryptionAlgValuesSupported()) {
requestObjectEncryptionAlgValuesSupported.put(requestObjectEncryptionAlg);
}
if (requestObjectEncryptionAlgValuesSupported.length() > 0) {
jsonObj.put(REQUEST_OBJECT_ENCRYPTION_ALG_VALUES_SUPPORTED, requestObjectEncryptionAlgValuesSupported);
}
JSONArray requestObjectEncryptionEncValuesSupported = new JSONArray();
for (String requestObjectEncryptionEnc : appConfiguration.getRequestObjectEncryptionEncValuesSupported()) {
requestObjectEncryptionEncValuesSupported.put(requestObjectEncryptionEnc);
}
if (requestObjectEncryptionEncValuesSupported.length() > 0) {
jsonObj.put(REQUEST_OBJECT_ENCRYPTION_ENC_VALUES_SUPPORTED, requestObjectEncryptionEncValuesSupported);
}
JSONArray tokenEndpointAuthMethodsSupported = new JSONArray();
for (String tokenEndpointAuthMethod : appConfiguration.getTokenEndpointAuthMethodsSupported()) {
tokenEndpointAuthMethodsSupported.put(tokenEndpointAuthMethod);
}
if (tokenEndpointAuthMethodsSupported.length() > 0) {
jsonObj.put(TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED, tokenEndpointAuthMethodsSupported);
}
JSONArray tokenEndpointAuthSigningAlgValuesSupported = new JSONArray();
for (String tokenEndpointAuthSigningAlg : appConfiguration.getTokenEndpointAuthSigningAlgValuesSupported()) {
tokenEndpointAuthSigningAlgValuesSupported.put(tokenEndpointAuthSigningAlg);
}
if (tokenEndpointAuthSigningAlgValuesSupported.length() > 0) {
jsonObj.put(TOKEN_ENDPOINT_AUTH_SIGNING_ALG_VALUES_SUPPORTED, tokenEndpointAuthSigningAlgValuesSupported);
}
JSONArray displayValuesSupported = new JSONArray();
for (String display : appConfiguration.getDisplayValuesSupported()) {
displayValuesSupported.put(display);
}
if (displayValuesSupported.length() > 0) {
jsonObj.put(DISPLAY_VALUES_SUPPORTED, displayValuesSupported);
}
JSONArray claimTypesSupported = new JSONArray();
for (String claimType : appConfiguration.getClaimTypesSupported()) {
claimTypesSupported.put(claimType);
}
if (claimTypesSupported.length() > 0) {
jsonObj.put(CLAIM_TYPES_SUPPORTED, claimTypesSupported);
}
JSONArray claimsSupported = new JSONArray();
List<GluuAttribute> gluuAttributes = attributeService.getAllAttributes();
// Preload all scopes to avoid sending request to LDAP per
// claim
List<org.xdi.oxauth.model.common.Scope> scopes = scopeService.getAllScopesList();
for (GluuAttribute gluuAttribute : gluuAttributes) {
if (GluuStatus.ACTIVE.equals(gluuAttribute.getStatus())) {
String claimName = gluuAttribute.getOxAuthClaimName();
if (StringUtils.isNotBlank(claimName)) {
List<org.xdi.oxauth.model.common.Scope> scopesByClaim = scopeService.getScopesByClaim(scopes, gluuAttribute.getDn());
for (org.xdi.oxauth.model.common.Scope scope : scopesByClaim) {
if (ScopeType.OPENID.equals(scope.getScopeType())) {
claimsSupported.put(claimName);
break;
}
}
}
}
}
if (claimsSupported.length() > 0) {
jsonObj.put(CLAIMS_SUPPORTED, claimsSupported);
}
jsonObj.put(SERVICE_DOCUMENTATION, appConfiguration.getServiceDocumentation());
JSONArray claimsLocalesSupported = new JSONArray();
for (String claimLocale : appConfiguration.getClaimsLocalesSupported()) {
claimsLocalesSupported.put(claimLocale);
}
if (claimsLocalesSupported.length() > 0) {
jsonObj.put(CLAIMS_LOCALES_SUPPORTED, claimsLocalesSupported);
}
JSONArray uiLocalesSupported = new JSONArray();
for (String uiLocale : appConfiguration.getUiLocalesSupported()) {
uiLocalesSupported.put(uiLocale);
}
if (uiLocalesSupported.length() > 0) {
jsonObj.put(UI_LOCALES_SUPPORTED, uiLocalesSupported);
}
jsonObj.put(SCOPE_TO_CLAIMS_MAPPING, createScopeToClaimsMapping());
jsonObj.put(CLAIMS_PARAMETER_SUPPORTED, appConfiguration.getClaimsParameterSupported());
jsonObj.put(REQUEST_PARAMETER_SUPPORTED, appConfiguration.getRequestParameterSupported());
jsonObj.put(REQUEST_URI_PARAMETER_SUPPORTED, appConfiguration.getRequestUriParameterSupported());
jsonObj.put(REQUIRE_REQUEST_URI_REGISTRATION, appConfiguration.getRequireRequestUriRegistration());
jsonObj.put(OP_POLICY_URI, appConfiguration.getOpPolicyUri());
jsonObj.put(OP_TOS_URI, appConfiguration.getOpTosUri());
jsonObj.put(FRONTCHANNEL_LOGOUT_SUPPORTED, "true");
jsonObj.put(FRONTCHANNEL_LOGOUT_SESSION_SUPPORTED, "true");
jsonObj.put(FRONT_CHANNEL_LOGOUT_SESSION_SUPPORTED, appConfiguration.getFrontChannelLogoutSessionSupported());
out.println(jsonObj.toString(4).replace("\\/", "/"));
} catch (JSONException e) {
log.error(e.getMessage(), e);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
out.close();
}
}
use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.
the class SectorIdentifier method processRequest.
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final HttpServletRequest httpRequest = request;
final HttpServletResponse httpResponse = response;
httpResponse.setContentType("application/json");
PrintWriter out = httpResponse.getWriter();
try {
String urlPath = httpRequest.getPathInfo();
String inum = urlPath.substring(urlPath.lastIndexOf("/") + 1, urlPath.length());
org.xdi.oxauth.model.ldap.SectorIdentifier sectorIdentifier = sectorIdentifierService.getSectorIdentifierByInum(inum);
JSONArray jsonArray = new JSONArray();
for (String redirectUri : sectorIdentifier.getRedirectUris()) {
jsonArray.put(redirectUri);
}
out.println(jsonArray.toString(4).replace("\\/", "/"));
} catch (JSONException e) {
log.error(e.getMessage(), e);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
out.close();
}
}
use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.
the class WebFinger method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws javax.servlet.ServletException if a servlet-specific error occurs
* @throws java.io.IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final HttpServletRequest httpRequest = request;
final HttpServletResponse httpResponse = response;
httpResponse.setContentType("application/jrd+json");
PrintWriter out = httpResponse.getWriter();
String resource = httpRequest.getParameter(RESOURCE);
String rel = httpRequest.getParameter(REL);
log.debug("Attempting to request OpenID Connect Discovery: " + resource + ", " + rel + ", Is Secure = " + httpRequest.isSecure());
try {
if (OpenIdConnectDiscoveryParamsValidator.validateParams(resource, rel)) {
if (rel == null || rel.equals(REL_VALUE)) {
JSONObject jsonObj = new JSONObject();
jsonObj.put(SUBJECT, resource);
JSONArray linksJsonArray = new JSONArray();
JSONObject linkJsonObject = new JSONObject();
linkJsonObject.put(REL, REL_VALUE);
linkJsonObject.put(HREF, appConfiguration.getIssuer());
linksJsonArray.put(linkJsonObject);
jsonObj.put(LINKS, linksJsonArray);
out.println(jsonObj.toString(4).replace("\\/", "/"));
}
}
} catch (JSONException e) {
log.error(e.getMessage(), e);
}
out.close();
}
Aggregations