use of org.pac4j.http.profile.RestProfile in project pac4j by pac4j.
the class RestAuthenticator method internalInit.
@Override
protected void internalInit() {
CommonHelper.assertNotBlank("url", url);
defaultProfileDefinition(new CommonProfileDefinition<>(x -> new RestProfile()));
if (mapper == null) {
mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
}
use of org.pac4j.http.profile.RestProfile in project pac4j by pac4j.
the class RestAuthenticator method buildProfile.
protected void buildProfile(final UsernamePasswordCredentials credentials, final String body) {
final var profileClass = (RestProfile) getProfileDefinition().newProfile();
final RestProfile profile;
try {
profile = mapper.readValue(body, profileClass.getClass());
} catch (final IOException e) {
throw new TechnicalException(e);
}
logger.debug("profile: {}", profile);
credentials.setUserProfile(profile);
}
use of org.pac4j.http.profile.RestProfile in project pac4j by pac4j.
the class RestAuthenticator method internalInit.
@Override
protected void internalInit(final boolean forceReinit) {
CommonHelper.assertNotBlank("url", url);
defaultProfileDefinition(new CommonProfileDefinition(x -> new RestProfile()));
if (mapper == null) {
mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
}
use of org.pac4j.http.profile.RestProfile in project pac4j by pac4j.
the class RestAuthenticatorIT method testProfileOk.
@Test
public void testProfileOk() {
final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=ok");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
final var profile = (RestProfile) credentials.getUserProfile();
assertNotNull(profile);
assertEquals(ID, profile.getId());
assertEquals(1, profile.getRoles().size());
assertEquals(ROLE, profile.getRoles().iterator().next());
}
use of org.pac4j.http.profile.RestProfile in project pac4j by pac4j.
the class RestAuthenticatorIT method testNotFound.
@Test
public void testNotFound() {
final var authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=notfound");
final var credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
authenticator.validate(credentials, MockWebContext.create(), new MockSessionStore());
final var profile = (RestProfile) credentials.getUserProfile();
assertNull(profile);
}
Aggregations