Search in sources :

Example 1 with OAuthServiceException

use of com.sun.identity.oauth.service.OAuthServiceException in project OpenAM by OpenRock.

the class OAuthServiceUtils method getAdminTokenId.

// This method is only called in server mode
public static String getAdminTokenId() throws OAuthServiceException {
    String adminTokenIdString = null;
    try {
        AdminTokenId adminTokenId = (AdminTokenId) Class.forName("com.sun.identity.security.AdminTokenIdImpl").newInstance();
        adminTokenIdString = adminTokenId.getAdminTokenId();
    } catch (Exception e) {
        throw new OAuthServiceException("Getting Admin token failed", e);
    }
    return adminTokenIdString;
}
Also used : AdminTokenId(com.sun.identity.security.AdminTokenId) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException)

Example 2 with OAuthServiceException

use of com.sun.identity.oauth.service.OAuthServiceException in project OpenAM by OpenRock.

the class OAuthServiceUtils method isTokenValid.

public static boolean isTokenValid(String tokenId) throws OAuthServiceException {
    boolean result = false;
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add(TOKEN_ID, tokenId);
    String response;
    try {
        response = tokenValidationResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Validate token failed", uie);
    }
    // ensure response is in expected format
    if (response.startsWith("boolean=true")) {
        result = true;
    }
    return result;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 3 with OAuthServiceException

use of com.sun.identity.oauth.service.OAuthServiceException in project OpenAM by OpenRock.

the class OAuthServiceUtils method authenticate.

public static String authenticate(String username, String password, boolean appAuth) throws OAuthServiceException {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add(AUTHN_USERNAME, username);
    params.add(AUTHN_PASSWORD, password);
    if (appAuth) {
        params.add("uri", "module=application");
    }
    String response;
    try {
        response = authenticateResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Authentication failed", uie);
    }
    // ensure response is in expected format
    if (!response.startsWith(ATTRIBUTE_TOKEN_ID_KEY + "=")) {
        return null;
    }
    String tokenId = response.substring(9);
    tokenId = tokenId.substring(0, tokenId.length() - 1);
    return tokenId;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 4 with OAuthServiceException

use of com.sun.identity.oauth.service.OAuthServiceException in project OpenAM by OpenRock.

the class OAuthServiceUtils method getUUIDByTokenId.

public static String getUUIDByTokenId(String tokenId) throws OAuthServiceException {
    String uuid;
    MultivaluedMapImpl params = new MultivaluedMapImpl();
    params.add(SUBJECT_ID, tokenId);
    params.add("attributenames", UUID_SESSION_PROPERTY_NAME);
    String response;
    try {
        response = attributesResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Get uuid failed", uie);
    }
    if (response == null) {
        return null;
    }
    int index = response.indexOf(USERDETAILS_NAME_KEY + "=" + UUID_SESSION_PROPERTY_NAME);
    index = response.indexOf(USERDETAILS_VALUE_KEY + "=", index);
    int startIdx = index + USERDETAILS_VALUE_KEY.length() + 1;
    int idx = response.indexOf(USERDETAILS_NAME_KEY + "=", startIdx);
    int endIdx;
    if (idx > 0) {
        endIdx = idx;
    } else {
        endIdx = response.length() - 1;
    }
    uuid = response.substring(startIdx, endIdx).trim();
    return uuid;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Aggregations

OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)4 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)4 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)3 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)2 AdminTokenId (com.sun.identity.security.AdminTokenId)1