use of org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfileDefinition in project pac4j by pac4j.
the class CasOAuthWrapperClient method clientInit.
@Override
protected void clientInit() {
CommonHelper.assertNotBlank("casOAuthUrl", this.casOAuthUrl);
configuration.setApi(new CasOAuthWrapperApi20(this.casOAuthUrl, this.springSecurityCompliant));
configuration.setProfileDefinition(new CasOAuthWrapperProfileDefinition());
if (this.implicitFlow) {
configuration.setResponseType("token");
} else {
configuration.setResponseType("code");
}
defaultLogoutActionBuilder(new CasLogoutActionBuilder<>(casLogoutUrl, "service"));
super.clientInit();
}
use of org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfileDefinition 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.CasOAuthWrapperProfileDefinition 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));
}
Aggregations