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