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;
}
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;
}
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;
}
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;
}
Aggregations