use of org.forgerock.openam.sts.TokenValidationException in project OpenAM by OpenRock.
the class PrincipalFromSessionImpl method parsePrincipalFromResponse.
private Principal parsePrincipalFromResponse(String response) throws TokenValidationException {
JsonValue responseJson;
try {
responseJson = JsonValueBuilder.toJsonValue(response);
} catch (JsonException e) {
String message = "Exception caught getting the text of the json principal from session response: " + e;
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, message, e);
}
JsonValue principalIdJsonValue = responseJson.get(ID);
if (!principalIdJsonValue.isString()) {
String message = "Principal from session response does not contain " + ID + " string entry. The obtained entry: " + principalIdJsonValue.toString() + "; The response: " + responseJson.toString();
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, message);
}
return new STSPrincipal(principalIdJsonValue.asString());
}
use of org.forgerock.openam.sts.TokenValidationException in project OpenAM by OpenRock.
the class PrincipalFromSessionImpl method obtainPrincipalFromSession.
private Principal obtainPrincipalFromSession(String sessionToUsernameUrl, String sessionId) throws TokenValidationException {
if ((sessionId == null) || sessionId.isEmpty()) {
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, "the sessionId passed to PrincipalFromSession is null or empty.");
}
try {
Map<String, String> headerMap = new HashMap<>();
headerMap.put(AMSTSConstants.COOKIE, amSessionCookieName + AMSTSConstants.EQUALS + sessionId);
headerMap.put(AMSTSConstants.CONTENT_TYPE, AMSTSConstants.APPLICATION_JSON);
headerMap.put(AMSTSConstants.CREST_VERSION_HEADER_KEY, crestVersionUsersService);
HttpURLConnectionWrapper.ConnectionResult connectionResult = httpURLConnectionWrapperFactory.httpURLConnectionWrapper(new URL(sessionToUsernameUrl)).setRequestHeaders(headerMap).setRequestMethod(AMSTSConstants.POST).makeInvocation();
final int responseCode = connectionResult.getStatusCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new TokenValidationException(responseCode, "Non-200 response from posting principal from session request: " + connectionResult.getResult());
} else {
return parsePrincipalFromResponse(connectionResult.getResult());
}
} catch (IOException e) {
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, "Exception caught making principal from session invocation: " + e, e);
}
}
use of org.forgerock.openam.sts.TokenValidationException in project OpenAM by OpenRock.
the class AMTokenParserImpl method getSessionFromAuthNResponse.
@Override
public String getSessionFromAuthNResponse(String authNResponse) throws TokenValidationException {
JsonValue responseJson;
try {
responseJson = JsonValueBuilder.toJsonValue(authNResponse);
} catch (JsonException e) {
String message = "Exception caught getting the text of the json authN response: " + e;
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, message, e);
}
JsonValue sessionIdJsonValue = responseJson.get(TOKEN_ID);
if (!sessionIdJsonValue.isString()) {
String message = "REST authN response does not contain " + TOKEN_ID + " string entry. The obtained entry: " + sessionIdJsonValue.toString() + "; The response: " + responseJson.toString();
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, message);
}
return sessionIdJsonValue.asString();
}
use of org.forgerock.openam.sts.TokenValidationException in project OpenAM by OpenRock.
the class SoapUsernameTokenAuthenticationRequestDispatcher method dispatch.
@Override
public String dispatch(URL url, AuthTargetMapping.AuthTarget target, UsernameToken token) throws TokenValidationException {
try {
Map<String, String> headerMap = new HashMap<>();
headerMap.put(AMSTSConstants.CONTENT_TYPE, AMSTSConstants.APPLICATION_JSON);
headerMap.put(AMSTSConstants.CREST_VERSION_HEADER_KEY, crestVersionAuthNService);
headerMap.put(AMSTSConstants.AM_REST_AUTHN_USERNAME_HEADER, token.getName());
headerMap.put(AMSTSConstants.AM_REST_AUTHN_PASSWORD_HEADER, token.getPassword());
HttpURLConnectionWrapper.ConnectionResult connectionResult = httpURLConnectionWrapperFactory.httpURLConnectionWrapper(url).setRequestHeaders(headerMap).setRequestMethod(AMSTSConstants.POST).makeInvocation();
final int responseCode = connectionResult.getStatusCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new TokenValidationException(responseCode, "Non-200 response from posting Username token " + "to rest authN: " + connectionResult.getResult());
} else {
return connectionResult.getResult();
}
} catch (IOException e) {
throw new TokenValidationException(ResourceException.INTERNAL_ERROR, "Exception caught posting UsernameToken to rest authN: " + e, e);
}
}
use of org.forgerock.openam.sts.TokenValidationException in project OpenAM by OpenRock.
the class OpenAMWSSUsernameTokenValidator method verifyPlaintextPassword.
@Override
protected void verifyPlaintextPassword(UsernameToken usernameToken, RequestData data) throws WSSecurityException {
try {
final String sessionId = authenticationHandler.authenticate(usernameToken, TokenType.USERNAME);
threadLocalAMTokenCache.cacheSessionIdForContext(validationInvocationContext, sessionId, invalidateOpenAMSession);
} catch (TokenValidationException e) {
String message = "Exception caught authenticating UsernameToken with OpenAM: " + e;
logger.error(message, e);
throw new WSSecurityException(message, e);
}
}
Aggregations