use of com.sun.identity.oauth.service.models.Consumer in project OpenAM by OpenRock.
the class ConsumerResource method deleteRegistration.
@DELETE
@Consumes(MediaType.TEXT_PLAIN)
public Response deleteRegistration() {
OAuthResourceManager oauthResMgr = OAuthResourceManager.getInstance();
try {
String consKey = context.getAbsolutePath().toString();
Map<String, String> searchMap = new HashMap<String, String>();
searchMap.put(CONSUMER_KEY, consKey);
List<Consumer> consumers = oauthResMgr.searchConsumers(searchMap);
if ((consumers == null) || consumers.isEmpty()) {
return Response.status(UNAUTHORIZED).build();
}
Consumer consumer = consumers.get(0);
oauthResMgr.deleteConsumer(consumer);
return Response.ok().build();
} catch (OAuthServiceException e) {
Logger.getLogger(ConsumerResource.class.getName()).log(Level.SEVERE, null, e);
throw new WebApplicationException(e);
}
}
use of com.sun.identity.oauth.service.models.Consumer 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.Consumer in project OpenAM by OpenRock.
the class OAuthResourceManager method readConsumer.
/**
* Reads a consumer entity from the data store.
*
* @param consumerId the identifier of the consumer
*
* @return the consumer entity to read
* @throws OAuthServiceException if an error condition occurs
*/
public Consumer readConsumer(String consumerId) throws OAuthServiceException {
if (consumerId == null) {
throw new OAuthServiceException("The consumer id is null");
}
Map<String, String> attributes = em.readEntity(consumerId);
if ((attributes == null) || (attributes.isEmpty())) {
throw new OAuthServiceException("Could not read the consumer entity");
}
Consumer consumer = new Consumer();
String consumerName = attributes.get(CONSUMER_NAME);
if ((consumerName == null) || (consumerName.trim().length() == 0)) {
throw new OAuthServiceException("Invalid consumer name");
}
consumer.setConsName(consumerName);
String consumerSecret = attributes.get(CONSUMER_SECRET);
if ((consumerSecret == null) || (consumerSecret.trim().length() == 0)) {
throw new OAuthServiceException("Invalid consumer secret");
}
consumer.setConsSecret(consumerSecret);
String consumerRSAKey = attributes.get(CONSUMER_RSA_KEY);
if ((consumerRSAKey != null) && (consumerRSAKey.trim().length() != 0)) {
consumer.setConsRsakey(consumerRSAKey);
}
String consumerKey = attributes.get(CONSUMER_KEY);
if ((consumerKey == null) || (consumerKey.trim().length() == 0)) {
throw new OAuthServiceException("Invalid consumer key");
}
consumer.setConsKey(consumerKey);
String etag = attributes.get(ETAG);
/*
if ((etag == null) || (etag.trim().length()== 0)) {
throw new OAuthServiceException("Invalid etag");
} */
consumer.setEtag(etag);
consumer.setId(consumerId);
return consumer;
}
use of com.sun.identity.oauth.service.models.Consumer in project OpenAM by OpenRock.
the class OAuthResourceManager method readAccessToken.
/**
* Reads an access token entity from the data store.
*
* @param accTokenId the identifier of the access token
*
* @return the access token entity to read
* @throws OAuthServiceException if an error condition occurs
*/
public AccessToken readAccessToken(String accTokenId) throws OAuthServiceException {
if (accTokenId == null) {
throw new OAuthServiceException("The access token id is null");
}
Map<String, String> attributes = em.readEntity(accTokenId);
if ((attributes == null) || (attributes.isEmpty())) {
throw new OAuthServiceException("Could not read the access token entity");
}
AccessToken accToken = new AccessToken();
String accTokenURI = attributes.get(ACCESS_TOKEN_URI);
if ((accTokenURI == null) || (accTokenURI.trim().length() == 0)) {
throw new OAuthServiceException("Invalid access token URI");
}
accToken.setAcctUri(accTokenURI);
String accTokenVal = attributes.get(ACCESS_TOKEN_VAL);
if ((accTokenVal == null) || (accTokenVal.trim().length() == 0)) {
throw new OAuthServiceException("Invalid access token value");
}
accToken.setAcctVal(accTokenVal);
String accTokenSecret = attributes.get(ACCESS_TOKEN_SECRET);
if ((accTokenSecret == null) || (accTokenSecret.trim().length() == 0)) {
throw new OAuthServiceException("Invalid access token secret");
}
accToken.setAcctSecret(accTokenSecret);
String accTokenPPalId = attributes.get(ACCESS_TOKEN_PPAL_ID);
accToken.setAcctPpalid(accTokenPPalId);
String accTokenExpiry = attributes.get(ACCESS_TOKEN_LIFETIME);
if (accTokenExpiry != null) {
try {
Date expiry = DateUtils.stringToDate(accTokenExpiry);
accToken.setAcctLifetime(expiry);
} catch (ParseException pe) {
throw new OAuthServiceException("invalid access token expiry", pe);
}
}
String consumerId = attributes.get(CONSUMER_ID);
if ((consumerId == null) || (consumerId.trim().length() == 0)) {
throw new OAuthServiceException("Invalid access token consumer id");
}
Consumer consumer = readConsumer(consumerId);
accToken.setConsumerId(consumer);
String etag = attributes.get(ETAG);
/*
if ((etag == null) || (etag.trim().length()== 0)) {
throw new OAuthServiceException("Invalid etag");
} */
accToken.setEtag(etag);
accToken.setId(accTokenId);
return accToken;
}
Aggregations