use of org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters in project OpenAM by OpenRock.
the class TokenRequestMarshallerImplTest method testX509CertificateTokenMarshalling.
@Test
public void testX509CertificateTokenMarshalling() throws Exception {
X509Certificate certificate = getCertificate();
ClientContext clientInfoContext = ClientContext.buildExternalClientContext(null).certificates(certificate).build();
@SuppressWarnings("unchecked") RestTokenTransformValidatorParameters<X509Certificate[]> params = (RestTokenTransformValidatorParameters<X509Certificate[]>) tokenMarshaller.buildTokenTransformValidatorParameters(new X509TokenState().toJson(), clientInfoContext);
assertEquals(certificate.getEncoded(), (params.getInputToken()[0].getEncoded()));
}
use of org.forgerock.openam.sts.rest.token.validator.RestTokenTransformValidatorParameters 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.rest.token.validator.RestTokenTransformValidatorParameters 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.rest.token.validator.RestTokenTransformValidatorParameters in project OpenAM by OpenRock.
the class TokenRequestMarshallerImpl method buildAMSessionTokenTransformValidatorParameters.
private RestTokenTransformValidatorParameters<OpenAMSessionToken> buildAMSessionTokenTransformValidatorParameters(JsonValue receivedToken) throws TokenMarshalException {
if (!receivedToken.get(AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID).isString()) {
String message = "Exception: json representation of AM Session Token does not contain a session_id field. " + "The representation: " + receivedToken;
throw new TokenMarshalException(ResourceException.BAD_REQUEST, message);
} else {
final String sessionId = receivedToken.get(AMSTSConstants.AM_SESSION_TOKEN_SESSION_ID).asString();
final OpenAMSessionToken openAMSessionToken = new OpenAMSessionToken(sessionId);
return new RestTokenTransformValidatorParameters<OpenAMSessionToken>() {
@Override
public OpenAMSessionToken getInputToken() {
return openAMSessionToken;
}
};
}
}
Aggregations