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);
}
}
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;
}
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();
}
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();
}
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);
}
}
}
}
}
}
Aggregations