use of org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfile in project pac4j by pac4j.
the class CasOAuthWrapperClientTests method testParsingAttributesCASServerV4_2AndBefore.
@Test
public void testParsingAttributesCASServerV4_2AndBefore() throws IOException {
final JsonFactory jsonFactory = new JsonFactory(new ObjectMapper());
final Map<String, Object> attributes = new HashMap<>();
attributes.put(KEY, VALUE);
attributes.put(NAME, TOKEN);
final StringWriter writer = new StringWriter();
try (final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer)) {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("id", ID);
jsonGenerator.writeArrayFieldStart("attributes");
for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeObjectField(entry.getKey(), entry.getValue());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
final String body = writer.toString();
final CasOAuthWrapperClient client = new CasOAuthWrapperClient();
client.setKey(KEY);
client.setSecret(SECRET);
client.setCasOAuthUrl(CALLBACK_URL);
client.setCallbackUrl(CALLBACK_URL);
client.init();
final CasOAuthWrapperProfile profile = new CasOAuthWrapperProfileDefinition().extractUserProfile(body);
assertEquals(ID, profile.getId());
assertEquals(2, profile.getAttributes().size());
assertEquals(VALUE, profile.getAttribute(KEY));
assertEquals(TOKEN, profile.getAttribute(NAME));
}
use of org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfile in project pac4j by pac4j.
the class CasOAuthWrapperClientTests method testParsingAttributesCASServerV5.
@Test
public void testParsingAttributesCASServerV5() throws IOException {
final Map<String, Object> attributes = new HashMap<>();
attributes.put(KEY, VALUE);
attributes.put(NAME, TOKEN);
final Map<String, Object> map = new HashMap<>();
map.put("id", ID);
map.put("attributes", attributes);
final String body = new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(map);
final CasOAuthWrapperClient client = new CasOAuthWrapperClient();
client.setKey(KEY);
client.setSecret(SECRET);
client.setCasOAuthUrl(CALLBACK_URL);
client.setCallbackUrl(CALLBACK_URL);
client.init();
final CasOAuthWrapperProfile profile = new CasOAuthWrapperProfileDefinition().extractUserProfile(body);
assertEquals(ID, profile.getId());
assertEquals(2, profile.getAttributes().size());
assertEquals(VALUE, profile.getAttribute(KEY));
assertEquals(TOKEN, profile.getAttribute(NAME));
}
use of org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfile in project pac4j by pac4j.
the class RunCasOAuthWrapperClient method verifyProfile.
@Override
protected void verifyProfile(CommonProfile userProfile) {
final CasOAuthWrapperProfile profile = (CasOAuthWrapperProfile) userProfile;
assertEquals(getLogin(), profile.getId());
assertEquals(CasOAuthWrapperProfile.class.getName() + CommonProfile.SEPARATOR + getLogin(), profile.getTypedId());
assertTrue(ProfileHelper.isTypedIdOf(profile.getTypedId(), CasOAuthWrapperProfile.class));
assertTrue(CommonHelper.isNotBlank(profile.getAccessToken()));
assertTrue(profile.isFromNewLogin());
assertEquals("AcceptUsersAuthenticationHandler", profile.getAuthenticationMethod());
assertFalse(profile.isLongTermAuthenticationRequestTokenUsed());
assertEquals("AcceptUsersAuthenticationHandler", profile.getSuccessfulAuthenticationHandlers());
assertNotNull(profile.getAuthenticationDate());
assertTrue(profile.isFromNewLogin());
assertEquals("groupMembership", profile.getAttribute("affiliation"));
assertEquals("commonName", profile.getAttribute("cn"));
assertEquals("uid", profile.getAttribute("uid"));
assertEquals(11, profile.getAttributes().size());
}
Aggregations