use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method getProofTokenState.
private ProofTokenState getProofTokenState(JsonValue token) throws TokenMarshalException {
final SAML2TokenCreationState tokenState = SAML2TokenCreationState.fromJson(token);
final ProofTokenState proofTokenState = tokenState.getProofTokenState();
if (proofTokenState == null) {
throw new TokenMarshalException(ResourceException.BAD_REQUEST, "No ProofTokenState specified in the" + " SAML2TokenCreationState. The JsonValue: " + token);
} else {
return proofTokenState;
}
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method createOpenIdConnectTokenProviderParameters.
private RestTokenProviderParameters<OpenIdConnectTokenCreationState> createOpenIdConnectTokenProviderParameters(final TokenTypeId inputTokenType, final JsonValue inputToken, final JsonValue desiredToken) throws TokenMarshalException {
org.forgerock.openam.sts.user.invocation.OpenIdConnectTokenCreationState userSpecifiedTokenCreationState = org.forgerock.openam.sts.user.invocation.OpenIdConnectTokenCreationState.fromJson(desiredToken);
if (!userSpecifiedTokenCreationState.getAllowAccess()) {
throw new TokenMarshalException(ResourceException.BAD_REQUEST, "The OpenIdConnectTokenCreation state must " + "indicate access to the caller's identity with a field of allow_access:true.");
}
final OpenIdConnectTokenCreationState openIdConnectTokenCreationState = new OpenIdConnectTokenCreationState(userSpecifiedTokenCreationState.getNonce(), System.currentTimeMillis() / 1000);
return new OpenIdConnectRestTokenProviderParameters(openIdConnectTokenCreationState, inputTokenType, inputToken);
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildSAML2IssuedTokenValidatorParameters.
private RestIssuedTokenValidatorParameters<SAML2TokenState> buildSAML2IssuedTokenValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.SAML2_TOKEN_KEY).isString()) {
String message = "Exception: json representation of a to-be-validated SAML2 token does not contain a " + AMSTSConstants.SAML2_TOKEN_KEY + " field containing the " + "to-be-validated 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 RestIssuedTokenValidatorParameters<SAML2TokenState>() {
@Override
public SAML2TokenState getInputToken() {
return saml2TokenState;
}
};
}
}
use of org.forgerock.openam.sts.TokenMarshalException in project OpenAM by OpenRock.
the class SoapSamlTokenProvider method getProofTokenState.
/**
*
* @param tokenProviderParameters The TokenProviderParameters corresponding to the RST invocation
* @return The ProofTokenState necessary for HoK assertions.
* @throws AMSTSRuntimeException if the ProofTokenState cannot be obtained from the request, or the X509Certificate
* state cannot be successfully constructed.
*/
private ProofTokenState getProofTokenState(TokenProviderParameters tokenProviderParameters) throws AMSTSRuntimeException {
ReceivedKey receivedKey = tokenProviderParameters.getKeyRequirements().getReceivedKey();
X509Certificate certificate = receivedKey.getX509Cert();
if (certificate == null) {
String exceptionMessage = "The ReceivedKey instance in the KeyRequirements has a null X509Cert. Thus the " + "ProofTokenState necessary to consume the TokenGenerationService cannot be created.";
logger.error(exceptionMessage + " PublicKey in the ReceivedToken: " + receivedKey.getPublicKey());
throw new AMSTSRuntimeException(ResourceException.BAD_REQUEST, exceptionMessage);
}
try {
return ProofTokenState.builder().x509Certificate(certificate).build();
} catch (TokenMarshalException e) {
String message = "In SoapSamlTokenProvider#getAssertion, could not marshal X509Cert in ReceivedKey " + "into ProofTokenState: " + e;
logger.error(message, e);
throw new AMSTSRuntimeException(ResourceException.BAD_REQUEST, message);
}
}
Aggregations