Search in sources :

Example 6 with SecurityProviderImpl

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();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 7 with SecurityProviderImpl

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();
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) HashMap(java.util.HashMap) PropertyIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) LoginException(javax.security.auth.login.LoginException) InitialContent(org.apache.jackrabbit.oak.InitialContent) PropertyIndexProvider(org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider) SimpleCredentials(javax.jcr.SimpleCredentials) TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) UserManager(org.apache.jackrabbit.api.security.user.UserManager) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) ContentRepository(org.apache.jackrabbit.oak.api.ContentRepository) Oak(org.apache.jackrabbit.oak.Oak) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) Tree(org.apache.jackrabbit.oak.api.Tree) LoginException(javax.security.auth.login.LoginException) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with SecurityProviderImpl

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();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) Before(org.junit.Before)

Example 9 with SecurityProviderImpl

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();
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) Jcr(org.apache.jackrabbit.oak.jcr.Jcr) Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Before(org.junit.Before)

Example 10 with SecurityProviderImpl

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();
}
Also used : InitialContent(org.apache.jackrabbit.oak.InitialContent) MemoryStore(org.apache.jackrabbit.oak.segment.memory.MemoryStore) NodeStore(org.apache.jackrabbit.oak.spi.state.NodeStore) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

SecurityProviderImpl (org.apache.jackrabbit.oak.security.SecurityProviderImpl)10 InitialContent (org.apache.jackrabbit.oak.InitialContent)7 Test (org.junit.Test)6 PropertyIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider)4 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)4 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 HashMap (java.util.HashMap)3 SimpleCredentials (javax.jcr.SimpleCredentials)3 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)3 Oak (org.apache.jackrabbit.oak.Oak)3 Root (org.apache.jackrabbit.oak.api.Root)3 PropertyIndexProvider (org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexProvider)3 ConfigurationParameters (org.apache.jackrabbit.oak.spi.security.ConfigurationParameters)3 UserConfiguration (org.apache.jackrabbit.oak.spi.security.user.UserConfiguration)3 LoginException (javax.security.auth.login.LoginException)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)2 ContentRepository (org.apache.jackrabbit.oak.api.ContentRepository)2 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)2 Jcr (org.apache.jackrabbit.oak.jcr.Jcr)2