use of org.apache.jackrabbit.oak.security.SecurityProviderImpl in project jackrabbit-oak by apache.
the class InitializerTest method testInitializerMongo.
@Test
public void testInitializerMongo() throws CommitFailedException {
NodeBuilder builder = mk.getNodeStore().getRoot().builder();
new InitialContent().initialize(builder);
SecurityProviderImpl provider = new SecurityProviderImpl(ConfigurationParameters.of(ImmutableMap.of(UserConfiguration.NAME, ConfigurationParameters.of(ImmutableMap.of("anonymousId", "anonymous", "adminId", "admin", "usersPath", "/home/users", "groupsPath", "/home/groups", "defaultDepth", "1")))));
provider.getConfiguration(UserConfiguration.class).getWorkspaceInitializer().initialize(builder, "default");
builder.getNodeState();
}
use of org.apache.jackrabbit.oak.security.SecurityProviderImpl 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();
}
}
}
use of org.apache.jackrabbit.oak.security.SecurityProviderImpl in project jackrabbit-oak by apache.
the class ImportIgnoreTest method before.
@Before
public void before() throws Exception {
String importBehavior = getImportBehavior();
SecurityProvider securityProvider;
if (importBehavior != null) {
Map<String, String> params = new HashMap<String, String>();
params.put(ProtectedItemImporter.PARAM_IMPORT_BEHAVIOR, getImportBehavior());
ConfigurationParameters config = ConfigurationParameters.of(AuthorizationConfiguration.NAME, ConfigurationParameters.of(params));
securityProvider = new SecurityProviderImpl(config);
} else {
securityProvider = new SecurityProviderImpl();
}
QueryEngineSettings queryEngineSettings = new QueryEngineSettings();
queryEngineSettings.setFailTraversal(true);
Jcr jcr = new Jcr();
jcr.with(securityProvider);
jcr.with(queryEngineSettings);
repo = jcr.createRepository();
adminSession = repo.login(new SimpleCredentials(UserConstants.DEFAULT_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID.toCharArray()));
target = adminSession.getRootNode().addNode("nodeName1");
target.addMixin("rep:AccessControllable");
adminSession.save();
}
use of org.apache.jackrabbit.oak.security.SecurityProviderImpl in project jackrabbit-oak by apache.
the class AbstractImportTest method before.
@Before
public void before() throws Exception {
ConfigurationParameters config = getConfigurationParameters();
if (config != null) {
securityProvider = new SecurityProviderImpl(config);
} else {
securityProvider = new SecurityProviderImpl();
}
QueryEngineSettings queryEngineSettings = new QueryEngineSettings();
queryEngineSettings.setFailTraversal(true);
Jcr jcr = new Jcr();
jcr.with(securityProvider);
jcr.with(queryEngineSettings);
repo = jcr.createRepository();
adminSession = repo.login(new SimpleCredentials(UserConstants.DEFAULT_ADMIN_ID, UserConstants.DEFAULT_ADMIN_ID.toCharArray()));
if (!(adminSession instanceof JackrabbitSession)) {
throw new NotExecutableException();
}
userMgr = ((JackrabbitSession) adminSession).getUserManager();
preTestAuthorizables.clear();
Iterator<Authorizable> iter = userMgr.findAuthorizables("rep:principalName", null);
while (iter.hasNext()) {
String id = iter.next().getID();
preTestAuthorizables.add(id);
}
// make sure the target node for group-import exists
Authorizable administrators = userMgr.getAuthorizable(ADMINISTRATORS);
if (userMgr.getAuthorizable(ADMINISTRATORS) == null) {
userMgr.createGroup(new PrincipalImpl(ADMINISTRATORS));
} else if (!administrators.isGroup()) {
throw new NotExecutableException("Expected " + administrators.getID() + " to be a group.");
}
adminSession.save();
}
use of org.apache.jackrabbit.oak.security.SecurityProviderImpl in project jackrabbit-oak by apache.
the class InitializerTest method testInitializerSegment.
@Test
public void testInitializerSegment() throws CommitFailedException, IOException {
NodeStore store = SegmentNodeStoreBuilders.builder(new MemoryStore()).build();
NodeBuilder builder = store.getRoot().builder();
new InitialContent().initialize(builder);
SecurityProviderImpl provider = new SecurityProviderImpl(ConfigurationParameters.of(ImmutableMap.of(UserConfiguration.NAME, ConfigurationParameters.of(ImmutableMap.of("anonymousId", "anonymous", "adminId", "admin", "usersPath", "/home/users", "groupsPath", "/home/groups", "defaultDepth", "1")))));
provider.getConfiguration(UserConfiguration.class).getWorkspaceInitializer().initialize(builder, "default");
builder.getNodeState();
}
Aggregations