use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.
the class OpenSSOCoreTokenStore method validateAndToLowerCase.
/**
* Validates token attribute name, it should not start with "token.".
* Also convert all attribute name to lower case and return.
* @param jObj
* @return JSONObject with all attribute name in lower case.
* @throws CoreTokenException
* @throws JSONException
*/
private JSONObject validateAndToLowerCase(JSONObject jObj) throws CoreTokenException, JSONException {
if (jObj == null) {
return null;
}
// TODO : check attribute name to be alphabetic, numerical
JSONObject retObj = new JSONObject();
Iterator<String> it = jObj.keys();
while (it.hasNext()) {
String key = it.next();
String lcKey = key.toLowerCase();
int pos = lcKey.indexOf(CONNECTOR);
if (pos <= 0) {
String[] args = new String[] { key };
throw new CoreTokenException(227, args, 400);
}
if (!internalTokenAttrs.contains(lcKey) && lcKey.startsWith("token.")) {
String[] args = new String[] { key };
throw new CoreTokenException(225, args, 400);
} else {
retObj.put(lcKey, jObj.getJSONArray(key));
}
}
return retObj;
}
use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.
the class CoreTokenResource method readToken.
/**
* Reads token attributes.
*
* @param headers HTTPHeaders object of the request.
* @param request HTTPServletRequest object of the request.
* @param tokenId token.id of the token to be retrieved.
* @return JSON-encoded token attributes.
*/
@GET
@Produces("application/json")
@Path("{token.id}")
public Response readToken(@Context HttpHeaders headers, @Context HttpServletRequest request, @PathParam("token.id") String tokenId) {
try {
String tokenVal = CoreTokenStoreFactory.getInstance().readToken(CoreTokenUtils.getAdminSubject(), tokenId);
JSONObject jObj = new JSONObject(tokenVal);
// retrieve etag attribute and set it as ETag header value.
String eTag = jObj.getJSONArray(CoreTokenConstants.VERSION_TAG).getString(0);
// remove version tag in return
jObj.remove(CoreTokenConstants.VERSION_TAG);
Response.ResponseBuilder builder = Response.status(200);
builder.entity(jObj.toString());
builder.type("application/json");
builder.header("ETag", eTag);
Response retResponse = builder.build();
// logging
String[] data = new String[] { jObj.getJSONArray(CoreTokenConstants.TOKEN_TYPE).toString(), jObj.getJSONArray(CoreTokenConstants.TOKEN_SUBJECT).toString() };
TokenLogUtils.access(Level.INFO, TokenLogUtils.TOKEN_READ_SUCCESS, data, null, tokenId);
return retResponse;
} catch (CoreTokenException ce) {
CoreTokenUtils.debug.error("CoreTokenResource.readToken", ce);
String[] data = new String[] { ce.getLocalizedMessage() };
TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_READ_TOKEN, data, null, tokenId);
throw getWebApplicationException(headers, ce);
} catch (JSONException je) {
CoreTokenUtils.debug.error("CoreTokenResource.readToken", je);
String[] data = new String[] { je.getLocalizedMessage() };
TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_READ_TOKEN, data, null, tokenId);
throw getWebApplicationException(je, MimeType.PLAIN);
}
}
use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.
the class CoreTokenResource method searchTokens.
/**
* Searches tokens.
*
* @param headers HTTPHeaders object of the request.
* @param request HTTPServletRequest object of the request.
* @return JSON array of tokens matching the queryString
*/
@GET
@Produces("application/json")
public String searchTokens(@Context HttpHeaders headers, @Context HttpServletRequest request) {
String query = null;
try {
query = request.getQueryString();
JSONArray jArray = CoreTokenStoreFactory.getInstance().searchTokens(CoreTokenUtils.getAdminSubject(), query);
String retArray = jArray.toString();
// logging
String[] data = new String[] { query, "" + jArray.length() };
TokenLogUtils.access(Level.INFO, TokenLogUtils.TOKEN_SEARCH_SUCCESS, data, null, null);
return retArray;
} catch (CoreTokenException ex) {
CoreTokenUtils.debug.error("CoreTokenResource.searchToken", ex);
String[] data = new String[] { query, ex.getLocalizedMessage() };
TokenLogUtils.error(Level.INFO, TokenLogUtils.UNABLE_TO_SEARCH_TOKEN, data, null, null);
throw getWebApplicationException(headers, ex);
}
}
Aggregations