use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class DynamicSyncContextTest method testSyncExternalUser.
@Test
public void testSyncExternalUser() throws Exception {
ExternalUser externalUser = idp.getUser(USER_ID);
sync(externalUser, SyncResult.Status.ADD);
assertNotNull(userManager.getAuthorizable(USER_ID));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class DefaultSyncContext method sync.
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public SyncResult sync(@Nonnull String id) throws SyncException {
try {
DebugTimer timer = new DebugTimer();
DefaultSyncResultImpl ret;
// find authorizable
Authorizable auth = userManager.getAuthorizable(id);
if (auth == null) {
return new DefaultSyncResultImpl(new DefaultSyncedIdentity(id, null, false, -1), SyncResult.Status.NO_SUCH_AUTHORIZABLE);
}
// check if we need to deal with this authorizable
ExternalIdentityRef ref = getIdentityRef(auth);
if (ref == null || !isSameIDP(ref)) {
return new DefaultSyncResultImpl(new DefaultSyncedIdentity(id, ref, auth.isGroup(), -1), SyncResult.Status.FOREIGN);
}
if (auth.isGroup()) {
ExternalGroup external = idp.getGroup(id);
timer.mark("retrieve");
if (external == null) {
ret = handleMissingIdentity(id, auth, timer);
} else {
ret = syncGroup(external, (Group) auth);
timer.mark("sync");
}
} else {
ExternalUser external = idp.getUser(id);
timer.mark("retrieve");
if (external == null) {
ret = handleMissingIdentity(id, auth, timer);
} else {
ret = syncUser(external, (User) auth);
timer.mark("sync");
}
}
if (log.isDebugEnabled()) {
log.debug("sync({}) -> {} {}", id, ref.getString(), timer.getString());
}
return ret;
} catch (RepositoryException e) {
throw new SyncException(e);
} catch (ExternalIdentityException e) {
throw new SyncException(e);
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class ExternalGroupPrincipalProviderTest method testFindPrincipalsContainingPercentSign.
@Test
public void testFindPrincipalsContainingPercentSign() throws Exception {
ExternalUser externalUser = idp.getUser(TestIdentityProvider.ID_WILDCARD_USER);
sync(externalUser);
Set<? extends Principal> expected = ImmutableSet.of(new PrincipalImpl("g%r%"));
Set<? extends Principal> res = ImmutableSet.copyOf(principalProvider.findPrincipals("%", PrincipalManager.SEARCH_TYPE_ALL));
assertEquals(expected, res);
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class ExternalGroupPrincipalTest method testIsMember.
@Test
public void testIsMember() throws Exception {
ExternalUser externalUser = idp.getUser(USER_ID);
java.security.acl.Group principal = getGroupPrincipal(externalUser.getDeclaredGroups().iterator().next());
assertTrue(principal.isMember(new PrincipalImpl(externalUser.getPrincipalName())));
assertTrue(principal.isMember(getUserManager(root).getAuthorizable(USER_ID).getPrincipal()));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.external.ExternalUser in project jackrabbit-oak by apache.
the class ExternalLoginModuleFactoryTest method testSyncCreateUser.
//~-------------------------------------------------------------< tests >---
@Test
public void testSyncCreateUser() throws Exception {
setUpJaasFactoryWithInjection();
UserManager userManager = getUserManager(root);
ContentSession cs = null;
try {
assertNull(userManager.getAuthorizable(USER_ID));
cs = login(new SimpleCredentials(USER_ID, new char[0]));
root.refresh();
Authorizable a = userManager.getAuthorizable(USER_ID);
assertNotNull(a);
ExternalUser user = idp.getUser(USER_ID);
for (String prop : user.getProperties().keySet()) {
assertTrue(a.hasProperty(prop));
}
assertEquals(TEST_CONSTANT_PROPERTY_VALUE, a.getProperty(TEST_CONSTANT_PROPERTY_NAME)[0].getString());
} finally {
if (cs != null) {
cs.close();
}
options.clear();
}
}
Aggregations