Search in sources :

Example 1 with CasOAuthWrapperProfileDefinition

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();
}
Also used : CasOAuthWrapperProfileDefinition(org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfileDefinition) CasOAuthWrapperApi20(org.pac4j.scribe.builder.api.CasOAuthWrapperApi20)

Example 2 with CasOAuthWrapperProfileDefinition

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));
}
Also used : CasOAuthWrapperProfileDefinition(org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfileDefinition) HashMap(java.util.HashMap) JsonFactory(com.fasterxml.jackson.core.JsonFactory) CasOAuthWrapperProfile(org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfile) StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with CasOAuthWrapperProfileDefinition

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));
}
Also used : CasOAuthWrapperProfile(org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfile) CasOAuthWrapperProfileDefinition(org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfileDefinition) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

CasOAuthWrapperProfileDefinition (org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfileDefinition)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 CasOAuthWrapperProfile (org.pac4j.oauth.profile.casoauthwrapper.CasOAuthWrapperProfile)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 StringWriter (java.io.StringWriter)1 Map (java.util.Map)1 CasOAuthWrapperApi20 (org.pac4j.scribe.builder.api.CasOAuthWrapperApi20)1