use of com.sun.identity.oauth.service.models.RequestToken in project OpenAM by OpenRock.
the class OAuthResourceManager method readRequestToken.
/**
* Reads a request token entity from the data store.
*
* @param reqTokenId the identifier of the request token
*
* @return the request token entity to read
* @throws OAuthServiceException if an error condition occurs
*/
public RequestToken readRequestToken(String reqTokenId) throws OAuthServiceException {
if (reqTokenId == null) {
throw new OAuthServiceException("The request token id is null");
}
Map<String, String> attributes = em.readEntity(reqTokenId);
if ((attributes == null) || (attributes.isEmpty())) {
throw new OAuthServiceException("Could not read the request token entity");
}
RequestToken reqToken = new RequestToken();
String reqTokenURI = attributes.get(REQUEST_TOKEN_URI);
if ((reqTokenURI == null) || (reqTokenURI.trim().length() == 0)) {
throw new OAuthServiceException("Invalid request token URI");
}
reqToken.setReqtUri(reqTokenURI);
String reqTokenVal = attributes.get(REQUEST_TOKEN_VAL);
if ((reqTokenVal == null) || (reqTokenVal.trim().length() == 0)) {
throw new OAuthServiceException("Invalid request token value");
}
reqToken.setReqtVal(reqTokenVal);
String reqTokenSecret = attributes.get(REQUEST_TOKEN_SECRET);
if ((reqTokenSecret == null) || (reqTokenSecret.trim().length() == 0)) {
throw new OAuthServiceException("Invalid request token secret");
}
reqToken.setReqtSecret(reqTokenSecret);
String reqTokenPPalId = attributes.get(REQUEST_TOKEN_PPAL_ID);
reqToken.setReqtPpalid(reqTokenPPalId);
String reqTokenExpiry = attributes.get(REQUEST_TOKEN_LIFETIME);
if (reqTokenExpiry != null) {
try {
Date expiry = DateUtils.stringToDate(reqTokenExpiry);
reqToken.setReqtLifetime(expiry);
} catch (ParseException pe) {
throw new OAuthServiceException("invalid request token expiry", pe);
}
}
String reqTokenCBK = attributes.get(REQUEST_TOKEN_CALLBACK);
if ((reqTokenCBK == null) || (reqTokenCBK.trim().length() == 0)) {
throw new OAuthServiceException("Invalid request token callback");
}
reqToken.setCallback(reqTokenCBK);
String reqTokenVerifier = attributes.get(REQUEST_TOKEN_VERIFIER);
reqToken.setVerifier(reqTokenVerifier);
String consumerId = attributes.get(CONSUMER_ID);
if ((consumerId == null) || (consumerId.trim().length() == 0)) {
throw new OAuthServiceException("Invalid request token consumer id");
}
Consumer consumer = readConsumer(consumerId);
reqToken.setConsumerId(consumer);
String etag = attributes.get(ETAG);
/*
if ((etag == null) || (etag.trim().length()== 0)) {
throw new OAuthServiceException("Invalid etag");
} */
reqToken.setEtag(etag);
reqToken.setId(reqTokenId);
return reqToken;
}
use of com.sun.identity.oauth.service.models.RequestToken in project OpenAM by OpenRock.
the class OAuthResourceManager method searchRequestTokens.
/**
* Searches for request token entities from the data store.
*
* @param attributes the attribute-value pairs used for the search
*
* @return a list of request tokens that satisfy the search criteria
* @throws OAuthServiceException if an error condition occurs
*/
public List<RequestToken> searchRequestTokens(Map<String, String> attributes) throws OAuthServiceException {
if ((attributes == null) || (attributes.isEmpty())) {
return null;
}
List<String> ids = em.searchEntity(REQUEST_TOKEN_TYPE, attributes);
if ((ids == null) || (ids.isEmpty())) {
return null;
}
List<RequestToken> requestTokens = new ArrayList<RequestToken>();
Iterator<String> iter = ids.iterator();
while (iter.hasNext()) {
String id = iter.next();
RequestToken requestToken = readRequestToken(id);
if (requestToken != null) {
requestTokens.add(requestToken);
}
}
return requestTokens;
}
Aggregations