Search in sources :

Example 31 with JSONException

use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.

the class TypePersistenceVisitor method visitAttribute.

@Override
public void visitAttribute(String typeName, AttributeInfo attribute) throws AtlasException {
    AtlasVertex vertex = typeVertices.get(typeName);
    String propertyKey = GraphBackedTypeStore.getPropertyKey(typeName, attribute.name);
    try {
        setProperty(vertex, propertyKey, attribute.toJson());
    } catch (JSONException e) {
        throw new StorageException(typeName, e);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) JSONException(org.codehaus.jettison.json.JSONException)

Example 32 with JSONException

use of org.codehaus.jettison.json.JSONException in project incubator-atlas by apache.

the class AtlasStructDefStoreV1 method toAttributeDefintion.

public static AttributeDefinition toAttributeDefintion(AtlasAttribute attribute) {
    AttributeDefinition ret = null;
    String jsonString = toJsonFromAttribute(attribute);
    try {
        ret = AttributeInfo.fromJson(jsonString);
    } catch (JSONException excp) {
        LOG.error("failed in converting to AttributeDefinition: " + jsonString, excp);
    }
    return ret;
}
Also used : AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) JSONException(org.codehaus.jettison.json.JSONException)

Example 33 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class ClientInfoRestWebServiceImpl method getJSonResponse.

/**
     * Builds a JSon String with the response parameters.
     */
public String getJSonResponse(Client client, Set<String> scopes) {
    JSONObject jsonObj = new JSONObject();
    try {
        for (String scopeName : scopes) {
            Scope scope = scopeService.getScopeByDisplayName(scopeName);
            if (scope.getOxAuthClaims() != null) {
                for (String claimDn : scope.getOxAuthClaims()) {
                    GluuAttribute attribute = attributeService.getAttributeByDn(claimDn);
                    String attributeName = attribute.getName();
                    Object attributeValue = clientService.getAttribute(client, attribute.getName());
                    jsonObj.put(attributeName, attributeValue);
                }
            }
        }
    } catch (JSONException e) {
        log.error(e.getMessage(), e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return jsonObj.toString();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Scope(org.xdi.oxauth.model.common.Scope) JSONException(org.codehaus.jettison.json.JSONException) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException) GluuAttribute(org.xdi.model.GluuAttribute)

Example 34 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegisterRestWebServiceImpl method requestClientRead.

@Override
public Response requestClientRead(String clientId, String authorization, HttpServletRequest httpRequest, SecurityContext securityContext) {
    String accessToken = tokenService.getTokenFromAuthorizationParameter(authorization);
    log.debug("Attempting to read client: clientId = {}, registrationAccessToken = {} isSecure = {}", clientId, accessToken, securityContext.isSecure());
    Response.ResponseBuilder builder = Response.ok();
    OAuth2AuditLog oAuth2AuditLog = new OAuth2AuditLog(ServerUtil.getIpAddress(httpRequest), Action.CLIENT_READ);
    oAuth2AuditLog.setClientId(clientId);
    try {
        if (appConfiguration.getDynamicRegistrationEnabled()) {
            if (registerParamsValidator.validateParamsClientRead(clientId, accessToken)) {
                Client client = clientService.getClient(clientId, accessToken);
                if (client != null) {
                    oAuth2AuditLog.setScope(clientScopesToString(client));
                    oAuth2AuditLog.setSuccess(true);
                    builder.entity(clientAsEntity(client));
                } else {
                    log.trace("The Access Token is not valid for the Client ID, returns invalid_token error.");
                    builder = Response.status(Response.Status.BAD_REQUEST.getStatusCode());
                    builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_TOKEN));
                }
            } else {
                log.trace("Client parameters are invalid.");
                builder = Response.status(Response.Status.BAD_REQUEST);
                builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_CLIENT_METADATA));
            }
        } else {
            builder = Response.status(Response.Status.BAD_REQUEST);
            builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.ACCESS_DENIED));
        }
    } catch (JSONException e) {
        builder = Response.status(500);
        builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_CLIENT_METADATA));
        log.error(e.getMessage(), e);
    } catch (StringEncrypter.EncryptionException e) {
        builder = Response.status(500);
        builder.entity(errorResponseFactory.getErrorAsJson(RegisterErrorResponseType.INVALID_CLIENT_METADATA));
        log.error(e.getMessage(), e);
    }
    CacheControl cacheControl = new CacheControl();
    cacheControl.setNoTransform(false);
    cacheControl.setNoStore(true);
    builder.cacheControl(cacheControl);
    builder.header("Pragma", "no-cache");
    applicationAuditLogger.sendMessage(oAuth2AuditLog);
    return builder.build();
}
Also used : Response(javax.ws.rs.core.Response) OAuth2AuditLog(org.xdi.oxauth.model.audit.OAuth2AuditLog) JSONException(org.codehaus.jettison.json.JSONException) CacheControl(javax.ws.rs.core.CacheControl) Client(org.xdi.oxauth.model.registration.Client) StringEncrypter(org.xdi.util.security.StringEncrypter)

Example 35 with JSONException

use of org.codehaus.jettison.json.JSONException in project oxAuth by GluuFederation.

the class RegisterRestWebServiceImpl method putCustomStuffIntoObject.

/**
     * Puts custom object class and custom attributes in client object for persistence.
     *
     * @param p_client        client object
     * @param p_requestObject request object
     */
private void putCustomStuffIntoObject(Client p_client, JSONObject p_requestObject) throws JSONException {
    // custom object class
    final String customOC = appConfiguration.getDynamicRegistrationCustomObjectClass();
    if (StringUtils.isNotBlank(customOC)) {
        p_client.setCustomObjectClasses(new String[] { customOC });
    }
    // custom attributes (custom attributes must be in custom object class)
    final List<String> attrList = appConfiguration.getDynamicRegistrationCustomAttributes();
    if (attrList != null && !attrList.isEmpty()) {
        for (String attr : attrList) {
            if (p_requestObject.has(attr)) {
                final JSONArray parameterValuesJsonArray = p_requestObject.optJSONArray(attr);
                final List<String> parameterValues = parameterValuesJsonArray != null ? toList(parameterValuesJsonArray) : Arrays.asList(p_requestObject.getString(attr));
                if (parameterValues != null && !parameterValues.isEmpty()) {
                    try {
                        boolean processed = processApplicationAttributes(p_client, attr, parameterValues);
                        if (!processed) {
                            p_client.getCustomAttributes().add(new CustomAttribute(attr, parameterValues));
                        }
                    } catch (Exception e) {
                        log.debug(e.getMessage(), e);
                    }
                }
            }
        }
    }
}
Also used : CustomAttribute(org.xdi.ldap.model.CustomAttribute) JSONArray(org.codehaus.jettison.json.JSONArray) WebApplicationException(javax.ws.rs.WebApplicationException) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

JSONException (org.codehaus.jettison.json.JSONException)281 JSONObject (org.codehaus.jettison.json.JSONObject)256 Response (javax.ws.rs.core.Response)183 Builder (javax.ws.rs.client.Invocation.Builder)179 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)179 Test (org.testng.annotations.Test)174 BaseTest (org.xdi.oxauth.BaseTest)174 Parameters (org.testng.annotations.Parameters)171 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)68 JSONArray (org.codehaus.jettison.json.JSONArray)44 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)43 URISyntaxException (java.net.URISyntaxException)35 TokenRequest (org.xdi.oxauth.client.TokenRequest)35 ResponseType (org.xdi.oxauth.model.common.ResponseType)35 WebApplicationException (javax.ws.rs.WebApplicationException)18 IOException (java.io.IOException)17 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)17 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14