use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testModifiedPreconditionStillSatisfied.
@Test
public void testModifiedPreconditionStillSatisfied() {
registration.activate(context.bundleContext(), requiredServiceIdMap("rpId", "authorizationId"));
RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "rpId"));
registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "authorizationId"));
SecurityProvider service = context.getService(SecurityProvider.class);
assertNotNull(service);
registration.modified(requiredServiceIdMap("authorizationId"));
SecurityProvider service2 = context.getService(SecurityProvider.class);
assertSame(service, service2);
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testBindRestrictionProviderWithAuthorizationConfig.
@Test
public void testBindRestrictionProviderWithAuthorizationConfig() {
registration.activate(context.bundleContext(), requiredServiceIdMap("rpId", "authorizationId"));
RestrictionProvider mockRp = Mockito.mock(RestrictionProvider.class);
registration.bindRestrictionProvider(mockRp, ImmutableMap.of(Constants.SERVICE_PID, "rpId"));
registration.bindAuthorizationConfiguration(new AuthorizationConfigurationImpl(), ImmutableMap.of(Constants.SERVICE_PID, "authorizationId"));
SecurityProvider service = context.getService(SecurityProvider.class);
RestrictionProvider rp = service.getConfiguration(AuthorizationConfiguration.class).getRestrictionProvider();
assertTrue(rp instanceof WhiteboardRestrictionProvider);
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class SecurityProviderRegistrationTest method testActivateWithoutPreconditions.
@Test
public void testActivateWithoutPreconditions() {
registration.activate(context.bundleContext(), requiredServiceIdMap());
SecurityProvider service = context.getService(SecurityProvider.class);
assertNotNull(service);
assertEquals(3, Iterables.size(Iterables.filter(service.getConfigurations(), Predicates.notNull())));
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class PrincipalConfigurationImplTest method testGetPrincipalProvider4.
@Test
public void testGetPrincipalProvider4() {
PrincipalConfigurationImpl pc3 = new PrincipalConfigurationImpl();
final SecurityProvider sp = new SecurityProvider() {
@Nonnull
@Override
public ConfigurationParameters getParameters(@Nullable String name) {
return ConfigurationParameters.EMPTY;
}
@Nonnull
@Override
public Iterable<? extends SecurityConfiguration> getConfigurations() {
return ImmutableList.of();
}
@Nonnull
@Override
public <T> T getConfiguration(@Nonnull Class<T> configClass) {
if (configClass.equals(UserConfiguration.class)) {
return (T) new UserConfigurationImpl(this) {
@Nullable
@Override
public PrincipalProvider getUserPrincipalProvider(@Nonnull Root root, @Nonnull NamePathMapper namePathMapper) {
return null;
}
};
} else {
throw new IllegalArgumentException();
}
}
};
pc3.setSecurityProvider(sp);
PrincipalProvider pp = pc3.getPrincipalProvider(root, NamePathMapper.DEFAULT);
assertTrue(pp instanceof PrincipalProviderImpl);
}
use of org.apache.jackrabbit.oak.spi.security.SecurityProvider in project jackrabbit-oak by apache.
the class UserInitializerTest method testAdminConfiguration.
/**
* @since OAK 1.0 The configuration defines if the password of the
* admin user is being set.
*/
@Test
public void testAdminConfiguration() throws Exception {
Map<String, Object> userParams = new HashMap();
userParams.put(UserConstants.PARAM_ADMIN_ID, "admin");
userParams.put(UserConstants.PARAM_OMIT_ADMIN_PW, true);
ConfigurationParameters params = ConfigurationParameters.of(UserConfiguration.NAME, ConfigurationParameters.of(userParams));
SecurityProvider sp = new SecurityProviderImpl(params);
final ContentRepository repo = new Oak().with(new InitialContent()).with(new PropertyIndexEditorProvider()).with(new PropertyIndexProvider()).with(new TypeEditorProvider()).with(sp).createContentRepository();
ContentSession cs = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() {
@Override
public ContentSession run() throws Exception {
return repo.login(null, null);
}
});
try {
Root root = cs.getLatestRoot();
UserConfiguration uc = sp.getConfiguration(UserConfiguration.class);
UserManager umgr = uc.getUserManager(root, NamePathMapper.DEFAULT);
Authorizable adminUser = umgr.getAuthorizable("admin");
assertNotNull(adminUser);
Tree adminTree = root.getTree(adminUser.getPath());
assertTrue(adminTree.exists());
assertNull(adminTree.getProperty(UserConstants.REP_PASSWORD));
} finally {
cs.close();
}
// login as admin should fail
ContentSession adminSession = null;
try {
adminSession = repo.login(new SimpleCredentials("admin", new char[0]), null);
fail();
} catch (LoginException e) {
//success
} finally {
if (adminSession != null) {
adminSession.close();
}
}
}
Aggregations