Search in sources :

Example 11 with CoreTokenException

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;
}
Also used : JSONObject(org.json.JSONObject) CoreTokenException(com.sun.identity.coretoken.CoreTokenException)

Example 12 with CoreTokenException

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) JSONObject(org.json.JSONObject) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) JSONException(org.json.JSONException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with CoreTokenException

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);
    }
}
Also used : JSONArray(org.json.JSONArray) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CoreTokenException (com.sun.identity.coretoken.CoreTokenException)13 SSOToken (com.iplanet.sso.SSOToken)6 SMSException (com.sun.identity.sm.SMSException)6 JSONObject (org.json.JSONObject)6 SSOException (com.iplanet.sso.SSOException)5 SMSEntry (com.sun.identity.sm.SMSEntry)5 JSONArray (org.json.JSONArray)4 Produces (javax.ws.rs.Produces)3 JSONException (org.json.JSONException)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Response (javax.ws.rs.core.Response)2 StringTokenizer (java.util.StringTokenizer)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1