use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildUsernameTokenTransformValidatorParameters.
private RestTokenTransformValidatorParameters<RestUsernameToken> buildUsernameTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.USERNAME_TOKEN_USERNAME).isString()) {
final String message = "Exception: json representation of UNT does not contain a username field. The representation: " + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
}
if (!receivedToken.get(AMSTSConstants.USERNAME_TOKEN_PASSWORD).isString()) {
final String message = "Exception: json representation of UNT does not contain a password field. The representation: \n" + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
}
final String username = receivedToken.get(AMSTSConstants.USERNAME_TOKEN_USERNAME).asString();
final String password = receivedToken.get(AMSTSConstants.USERNAME_TOKEN_PASSWORD).asString();
try {
final RestUsernameToken restUsernameToken = new RestUsernameToken(username.getBytes(AMSTSConstants.UTF_8_CHARSET_ID), password.getBytes(AMSTSConstants.UTF_8_CHARSET_ID));
return new RestTokenTransformValidatorParameters<RestUsernameToken>() {
@Override
public RestUsernameToken getInputToken() {
return restUsernameToken;
}
};
} catch (UnsupportedEncodingException e) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "Unable to marshal username token state to strings: " + e.getMessage(), e);
}
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildSAML2IssuedTokenCancellerParameters.
private RestIssuedTokenCancellerParameters<SAML2TokenState> buildSAML2IssuedTokenCancellerParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.SAML2_TOKEN_KEY).isString()) {
String message = "Exception: json representation of a to-be-cancelled SAML2 token does not contain a " + AMSTSConstants.SAML2_TOKEN_KEY + " field containing the " + "to-be-cancelled token. The representation: " + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
} else {
final String tokenValue = receivedToken.get(AMSTSConstants.SAML2_TOKEN_KEY).asString();
final SAML2TokenState saml2TokenState = SAML2TokenState.builder().tokenValue(tokenValue).build();
return new RestIssuedTokenCancellerParameters<SAML2TokenState>() {
@Override
public SAML2TokenState getInputToken() {
return saml2TokenState;
}
};
}
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method pullClientCertFromHeader.
private X509Certificate[] pullClientCertFromHeader(HttpContext httpContext) throws TokenMarshalException {
List<String> clientCertHeader = httpContext.getHeader(offloadedTlsClientCertKey);
if (clientCertHeader.isEmpty()) {
return null;
} else {
int ndx = 0;
X509Certificate[] certificates = new X509Certificate[clientCertHeader.size()];
final CertificateFactory certificateFactory;
try {
certificateFactory = CertificateFactory.getInstance("X.509");
} catch (CertificateException e) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "Exception caught creating X.509 CertificateFactory: " + e, e);
}
for (String headerCertValue : clientCertHeader) {
try {
certificates[ndx++] = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(Base64.decode(headerCertValue.getBytes(AMSTSConstants.UTF_8_CHARSET_ID))));
} catch (CertificateException | UnsupportedEncodingException e) {
throw new TokenMarshalException(ResourceException.BAD_REQUEST, "Exception caught marshalling X509 cert from value set in " + offloadedTlsClientCertKey + " header: " + e, e);
}
}
return certificates;
}
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildOpenIdConnectIdTokenTransformValidatorParameters.
private RestTokenTransformValidatorParameters<OpenIdConnectIdToken> buildOpenIdConnectIdTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_KEY).isString()) {
String message = "Exception: json representation of Open ID Connect ID Token does not contain a " + AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_KEY + " field. The representation: " + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
} else {
final String tokenValue = receivedToken.get(AMSTSConstants.OPEN_ID_CONNECT_ID_TOKEN_KEY).asString();
final OpenIdConnectIdToken openIdConnectIdToken = new OpenIdConnectIdToken(tokenValue);
return new RestTokenTransformValidatorParameters<OpenIdConnectIdToken>() {
@Override
public OpenIdConnectIdToken getInputToken() {
return openIdConnectIdToken;
}
};
}
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class OpenAMTokenState method fromJson.
public static OpenAMTokenState fromJson(JsonValue jsonValue) throws TokenMarshalException {
if (!jsonValue.get(AMSTSConstants.TOKEN_TYPE_KEY).isString() || !TokenType.OPENAM.name().equals(jsonValue.get(AMSTSConstants.TOKEN_TYPE_KEY).asString())) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "passed-in jsonValue does not have " + AMSTSConstants.TOKEN_TYPE_KEY + " field which matches the OpenAM token type: " + jsonValue);
}
final JsonValue jsonSessionId = jsonValue.get(AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID);
if (jsonSessionId.isNull()) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "passed-in jsonValue does not have " + AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID + " field: " + jsonValue);
}
final String sessionId = jsonSessionId.asString();
if (sessionId.isEmpty()) {
throw new TokenMarshalException(ResourceException.INTERNAL_ERROR, "passed-in jsonValue does not have a non-empty " + AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID + " field: " + jsonValue);
}
return OpenAMTokenState.builder().sessionId(sessionId).build();
}
Aggregations