use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class AuthenticationInfoTest method testSerializationWithUserProfile.
@Test
void testSerializationWithUserProfile() throws Exception {
final PropertySet data = new PropertySet();
data.setString("subString", "subStringValue");
data.setLong("subLong", 123L);
final PropertyTree userProfile = new PropertyTree();
userProfile.setSet("myApp", data);
userProfile.setString("string", "stringValue");
final User user = User.create().login("userlogin").displayName("my user").key(PrincipalKey.ofUser(IdProviderKey.from("myidprovider"), "userid")).email("user@email").modifiedTime(Instant.now(clock)).profile(userProfile).build();
final IdProviderKey idProvider = IdProviderKey.from("myStore");
final PrincipalKey group1 = PrincipalKey.ofGroup(idProvider, "group1");
final PrincipalKey group2 = PrincipalKey.from("group:myStore:group2");
final PrincipalKey role1 = PrincipalKey.from("role:administrators");
final AuthenticationInfo info = AuthenticationInfo.create().user(user).principals(group1).principals(PrincipalKeys.from(group2, role1)).build();
final byte[] serializedObject = serialize(info);
final AuthenticationInfo deserializedObject = (AuthenticationInfo) deserialize(serializedObject);
assertEquals(deserializedObject, info);
}
use of com.enonic.xp.security.IdProviderKey in project xp by enonic.
the class VirtualHostConfigMap method getHostIdProvidersMapping.
private VirtualHostIdProvidersMapping getHostIdProvidersMapping(final String mappingPrefix) {
final String idProviderPrefix = mappingPrefix + "idProvider" + ".";
final VirtualHostIdProvidersMapping.Builder hostIdProvidersMapping = VirtualHostIdProvidersMapping.create();
getIdProviders(idProviderPrefix).forEach((idProviderName, idProviderStatus) -> {
final IdProviderKey idProviderKey = IdProviderKey.from(idProviderName);
if (DEFAULT_ID_PROVIDER_VALUE.equals(idProviderStatus)) {
hostIdProvidersMapping.setDefaultIdProvider(idProviderKey);
}
if (ENABLED_ID_PROVIDER_VALUE.equals(idProviderStatus)) {
hostIdProvidersMapping.addIdProviderKey(idProviderKey);
}
});
return hostIdProvidersMapping.build();
}
use of com.enonic.xp.security.IdProviderKey in project app-auth0-idprovider by enonic.
the class Auth0CallbackService method handle.
public boolean handle(final HttpServletRequest request) {
try {
final IdProviderKey idProviderKey = getIdProviderKey(request);
final AuthenticationController authController = createAuthController(idProviderKey);
final Tokens tokens = authController.handle(request);
final UserInfo userInfo = retrieveUserInfo(idProviderKey, tokens);
loginService.login(request, new UserInfoAdapter(userInfo), idProviderKey);
return true;
} catch (Exception e) {
LOG.error("Error while handling auth0 callback", e);
}
return false;
}
Aggregations