Search in sources :

Example 6 with RequestToken

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;
}
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 7 with RequestToken

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

Aggregations

RequestToken (com.sun.identity.oauth.service.models.RequestToken)7 HashMap (java.util.HashMap)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 Consumes (javax.ws.rs.Consumes)4 Consumer (com.sun.identity.oauth.service.models.Consumer)3 UniqueRandomString (com.sun.identity.oauth.service.util.UniqueRandomString)3 URI (java.net.URI)3 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 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 AccessToken (com.sun.identity.oauth.service.models.AccessToken)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1