Search in sources :

Example 6 with CoreTokenException

use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.

the class OpenSSOCoreTokenStore method createSearchFilter.

private String createSearchFilter(String query) throws CoreTokenException {
    if ((query == null) || (query.length() == 0)) {
        throw new CoreTokenException(218, null, 400);
    }
    StringTokenizer attrs = new StringTokenizer(query, "&");
    StringBuilder sb = new StringBuilder(100);
    sb.append("(&");
    while (attrs.hasMoreTokens()) {
        String attr = (String) attrs.nextToken();
        int pos = attr.indexOf("=");
        if (pos == -1) {
            String[] args = new String[] { attr };
            throw new CoreTokenException(219, args);
        }
        String key = attr.substring(0, pos);
        if ((key == null) || (key.length() == 0)) {
            String[] args = new String[] { attr };
            throw new CoreTokenException(219, args, 400);
        }
        // change attribute name to lower case as all attribute
        // names are converted to lower case before saving
        String lcKey = key.toLowerCase();
        if (!searchableAttrs.contains(lcKey) && !internalSearchableAttrs.contains(lcKey)) {
            String[] args = new String[] { key };
            throw new CoreTokenException(223, args, 400);
        }
        String value = attr.substring(pos + 1);
        if ((value == null) || (value.length() == 0)) {
            String[] args = new String[] { attr };
            throw new CoreTokenException(219, args, 400);
        }
        sb.append("(").append(SMSEntry.ATTR_XML_KEYVAL + "=");
        if (searchableAttrs.contains(lcKey)) {
            sb.append(SEARCHABLE_ATTR).append("=");
        }
        sb.append(lcKey).append("=").append(value).append(")");
    }
    sb.append(")");
    if (CoreTokenUtils.debug.messageEnabled()) {
        CoreTokenUtils.debug.message("OpenSSOCoreTokenStore." + "createSearchFilter, filter is " + sb.toString());
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) CoreTokenException(com.sun.identity.coretoken.CoreTokenException)

Example 7 with CoreTokenException

use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.

the class OpenSSOCoreTokenStore method deleteToken.

/**
     *
     * @param subject
     * @param tokenId
     * @throws CoreTokenException
     * @throws JSONException
     */
public void deleteToken(Subject subject, String tokenId) throws CoreTokenException {
    SSOToken adminToken = SubjectUtils.getSSOToken(subject);
    String dn = getCoreTokenDN(tokenId);
    if (adminToken == null) {
        throw new CoreTokenException(211, null, 401);
    }
    if (!SMSEntry.checkIfEntryExists(dn, adminToken)) {
        throw new CoreTokenException(203, null, 404);
    }
    try {
        SMSEntry s = new SMSEntry(adminToken, dn);
        s.delete();
    } catch (SSOException ex) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.deleteToken", ex);
        throw new CoreTokenException(205, null, ex);
    } catch (SMSException ex) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.deleteToken", ex);
        throw new CoreTokenException(205, null, ex);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) SMSEntry(com.sun.identity.sm.SMSEntry) SSOException(com.iplanet.sso.SSOException)

Example 8 with CoreTokenException

use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.

the class OpenSSOCoreTokenStore method createToken.

/**
     * 
     * @param subject
     * @param attributes
     * @return the created token in JSON format
     * @throws CoreTokenException
     * @throws JSONException
     */
public String createToken(Subject subject, JSONObject attributes) throws CoreTokenException, JSONException {
    SSOToken adminToken = SubjectUtils.getSSOToken(subject);
    if (adminToken == null) {
        throw new CoreTokenException(212, null, 401);
    }
    String tokenId = null;
    try {
        // validate attribute names and convert to lower case
        attributes = validateAndToLowerCase(attributes);
        if (attributes.has(CoreTokenConstants.TOKEN_ID)) {
            throw new CoreTokenException(201, null, 409);
        }
        tokenId = UUID.randomUUID().toString();
        String dn = getCoreTokenDN(tokenId);
        SMSEntry s = new SMSEntry(adminToken, dn);
        Map<String, Set<String>> map = validateAndCreateMap(tokenId, attributes);
        s.setAttributes(map);
        s.save();
        JSONObject json = new JSONObject();
        JSONArray jArray = new JSONArray();
        jArray.put(tokenId);
        json.put(CoreTokenConstants.TOKEN_ID, jArray);
        return json.toString();
    } catch (SSOException e) {
        CoreTokenUtils.debug.error("OpenSSOTokenStore.createToken", e);
        throw new CoreTokenException(202, null, e);
    } catch (SMSException e) {
        CoreTokenUtils.debug.error("OpenSSOTokenStore.createToken", e);
        throw new CoreTokenException(202, null, e);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) JSONObject(org.json.JSONObject) SMSException(com.sun.identity.sm.SMSException) JSONArray(org.json.JSONArray) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) SMSEntry(com.sun.identity.sm.SMSEntry) SSOException(com.iplanet.sso.SSOException)

Example 9 with CoreTokenException

use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.

the class OpenSSOCoreTokenStore method readToken.

/**
     *
     * @param adminSubject
     * @param tokenId
     * @return token value from SM with the given tokenId
     * @throws CoreTokenException
     */
public String readToken(Subject adminSubject, String tokenId) throws CoreTokenException {
    SSOToken adminToken = SubjectUtils.getSSOToken(adminSubject);
    if (adminToken == null) {
        throw new CoreTokenException(209, null, 401);
    }
    String dn = getCoreTokenDN(tokenId);
    if (!SMSEntry.checkIfEntryExists(dn, adminToken)) {
        throw new CoreTokenException(203, null, 404);
    }
    try {
        SMSEntry s = new SMSEntry(adminToken, dn);
        return getTokenAttributeValueFromSM(s, JSON_ATTR);
    } catch (SSOException ex) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.read", ex);
        throw new CoreTokenException(204, null, ex);
    } catch (SMSException ex) {
        CoreTokenUtils.debug.error("OpenSSOCoreTokenStore.read", ex);
        throw new CoreTokenException(204, null, ex);
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SMSException(com.sun.identity.sm.SMSException) CoreTokenException(com.sun.identity.coretoken.CoreTokenException) SMSEntry(com.sun.identity.sm.SMSEntry) SSOException(com.iplanet.sso.SSOException)

Example 10 with CoreTokenException

use of com.sun.identity.coretoken.CoreTokenException in project OpenAM by OpenRock.

the class OpenSSOCoreTokenStore method validateAndCreateMap.

private Map<String, Set<String>> validateAndCreateMap(String tokenId, JSONObject jsonAttr) throws JSONException, CoreTokenException {
    String tokenExpiry = null;
    if (jsonAttr.has(CoreTokenConstants.TOKEN_EXPIRY)) {
        tokenExpiry = getSingleStringValue(jsonAttr, CoreTokenConstants.TOKEN_EXPIRY);
    }
    // check token.expiry if exist
    if ((tokenExpiry != null) && (tokenExpiry.length() != 0) && CoreTokenUtils.isTokenExpired(tokenExpiry)) {
        String[] args = new String[] { tokenExpiry };
        throw new CoreTokenException(11, args, 400);
    }
    // token.type must present and must be single-valued attribute
    String tokenType = getSingleStringValue(jsonAttr, CoreTokenConstants.TOKEN_TYPE);
    // toke.subject could be an array and must be present
    JSONArray tokenSubject = null;
    if (jsonAttr.has(CoreTokenConstants.TOKEN_SUBJECT)) {
        tokenSubject = jsonAttr.getJSONArray(CoreTokenConstants.TOKEN_SUBJECT);
    } else {
        String[] args = new String[] { CoreTokenConstants.TOKEN_SUBJECT };
        throw new CoreTokenException(217, args, 400);
    }
    return getSMSAttributeMap(tokenId, tokenSubject, tokenType, tokenExpiry, jsonAttr);
}
Also used : JSONArray(org.json.JSONArray) CoreTokenException(com.sun.identity.coretoken.CoreTokenException)

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