Search in sources :

Example 6 with Consumer

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);
    }
}
Also used : Consumer(com.sun.identity.oauth.service.models.Consumer) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes)

Example 7 with Consumer

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;
}
Also used : Consumer(com.sun.identity.oauth.service.models.Consumer) RequestToken(com.sun.identity.oauth.service.models.RequestToken) ParseException(java.text.ParseException) Date(java.util.Date)

Example 8 with Consumer

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;
}
Also used : Consumer(com.sun.identity.oauth.service.models.Consumer)

Example 9 with 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;
}
Also used : Consumer(com.sun.identity.oauth.service.models.Consumer) AccessToken(com.sun.identity.oauth.service.models.AccessToken) ParseException(java.text.ParseException) Date(java.util.Date)

Aggregations

Consumer (com.sun.identity.oauth.service.models.Consumer)9 HashMap (java.util.HashMap)5 Consumes (javax.ws.rs.Consumes)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 RequestToken (com.sun.identity.oauth.service.models.RequestToken)3 UniqueRandomString (com.sun.identity.oauth.service.util.UniqueRandomString)3 URI (java.net.URI)3 POST (javax.ws.rs.POST)3 AccessToken (com.sun.identity.oauth.service.models.AccessToken)2 OAuthServerRequest (com.sun.jersey.oauth.server.OAuthServerRequest)2 OAuthParameters (com.sun.jersey.oauth.signature.OAuthParameters)2 OAuthSecrets (com.sun.jersey.oauth.signature.OAuthSecrets)2 OAuthSignatureException (com.sun.jersey.oauth.signature.OAuthSignatureException)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLEncoder (java.net.URLEncoder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1