TokenRequestMarshallerImplTest.java revision f5356c1f88047993a4e2f34c4c104b5960b21edb
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyrighted [year] [name of copyright owner]".
*
* Copyright 2013-2015 ForgeRock AS.
*/
public class TokenRequestMarshallerImplTest {
private TokenRequestMarshaller tokenMarshaller;
static class MyModule extends AbstractModule {
protected void configure() {
}
Logger getSlf4jLogger() {
}
//Must be empty for the testX509CertificateTokenMarshalling() to reference cert from ServletRequest attribute
return "";
}
return Collections.emptySet();
}
return Sets.newHashSet(new CustomTokenOperation(CUSTOM_TOKEN_NAME, "org.forgerock.bobo.BoboTokenValidator"));
}
return Sets.newHashSet(new CustomTokenOperation(CUSTOM_TOKEN_NAME, "org.forgerock.bobo.BoboTokenProvider"));
}
}
public void initialize() {
}
@Test
RestTokenTransformValidatorParameters<?> params = tokenMarshaller.buildTokenTransformValidatorParameters(jsonUnt, null);
assertEquals("bobo".getBytes(AMSTSConstants.UTF_8_CHARSET_ID), ((RestUsernameToken)params.getInputToken()).getUsername());
}
@Test
public void marshallOpenAMToken() throws TokenMarshalException {
RestTokenTransformValidatorParameters<?> params = tokenMarshaller.buildTokenTransformValidatorParameters(jsonOpenAM, null);
}
@Test
public void testX509CertificateTokenMarshalling() throws Exception {
ClientContext clientInfoContext = ClientContext.buildExternalClientContext(null).certificates(certificate).build();
@SuppressWarnings("unchecked")
tokenMarshaller.buildTokenTransformValidatorParameters(new X509TokenState().toJson(), clientInfoContext);
}
@Test
public void testBuildProviderParametersUsernameToken() throws TokenMarshalException, UnsupportedEncodingException {
SAML2TokenCreationState.builder().saml2SubjectConfirmation(SAML2SubjectConfirmation.BEARER).build().toJson();
tokenMarshaller.buildTokenProviderParameters(TokenType.USERNAME, jsonUnt, TokenType.SAML2, saml2Output);
}
@Test
.build()
.toJson();
tokenMarshaller.buildTokenProviderParameters(TokenType.OPENAM, jsonOpenAM, TokenType.SAML2, saml2Output);
((Saml2TokenCreationState)params.getTokenCreationState()).getProofTokenState().getX509Certificate().getEncoded());
}
@Test
return CUSTOM_TOKEN_NAME;
}
};
tokenMarshaller.buildTokenProviderParameters(TokenType.USERNAME, jsonUnt, customTokenType, jsonCustomOutput);
assertEquals(((JsonValue)params.getTokenCreationState()).get("token_type").asString(), CUSTOM_TOKEN_NAME);
}
public void testBuildCustomProviderParametersWithUnregisteredCustomToken() throws IOException, CertificateException {
return "NOT_REGISTERED_AS_CUSTOM_TYPE";
}
};
tokenMarshaller.buildTokenProviderParameters(TokenType.USERNAME, jsonUnt, customTokenType, new JsonValue(new HashMap<String, Object>()));
}
return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(getClass().getResourceAsStream("/cert.jks"));
}
}