Search in sources :

Example 16 with GuestCredentials

use of javax.jcr.GuestCredentials in project jackrabbit by apache.

the class FirstHop method main.

/**
     * The main entry point of the example application.
     * 
     * @param args
     *            command line arguments (ignored)
     * @throws Exception
     *             if an error occurs
     */
public static void main(String[] args) throws Exception {
    Repository repository = JcrUtils.getRepository();
    Session session = repository.login(new GuestCredentials());
    try {
        String user = session.getUserID();
        String name = repository.getDescriptor(Repository.REP_NAME_DESC);
        System.out.println("Logged in as " + user + " to a " + name + " repository.");
    } finally {
        session.logout();
    }
}
Also used : Repository(javax.jcr.Repository) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session)

Example 17 with GuestCredentials

use of javax.jcr.GuestCredentials in project jackrabbit-oak by apache.

the class UserInitializerTest method testAnonymousConfiguration.

/**
     * @since OAK 1.0 The anonymous user is optional.
     */
@Test
public void testAnonymousConfiguration() throws Exception {
    Map<String, Object> userParams = new HashMap();
    userParams.put(UserConstants.PARAM_ANONYMOUS_ID, "");
    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 anonymous = umgr.getAuthorizable(UserConstants.DEFAULT_ANONYMOUS_ID);
        assertNull(anonymous);
    } finally {
        cs.close();
    }
    // login as admin should fail
    ContentSession anonymousSession = null;
    try {
        anonymousSession = repo.login(new GuestCredentials(), null);
        fail();
    } catch (LoginException e) {
    //success
    } finally {
        if (anonymousSession != null) {
            anonymousSession.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) 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) LoginException(javax.security.auth.login.LoginException) SecurityProviderImpl(org.apache.jackrabbit.oak.security.SecurityProviderImpl) GuestCredentials(javax.jcr.GuestCredentials) UserConfiguration(org.apache.jackrabbit.oak.spi.security.user.UserConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 18 with GuestCredentials

use of javax.jcr.GuestCredentials in project jackrabbit-oak by apache.

the class L5_GuestLoginTest method testAnonymousSimpleCredentialsLoginSuccess.

public void testAnonymousSimpleCredentialsLoginSuccess() throws RepositoryException {
    testSession = repository.login(new GuestCredentials());
    String anonymousID = testSession.getUserID();
    // EXERCISE: how to you need to modify the test-case that this would work?
    Session anonymousUserSession = repository.login(new SimpleCredentials(anonymousID, new char[0]));
    assertEquals(UserConstants.DEFAULT_ANONYMOUS_ID, testSession.getUserID());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session)

Example 19 with GuestCredentials

use of javax.jcr.GuestCredentials in project jackrabbit-oak by apache.

the class AbstractRepositoryTest method createAnonymousSession.

protected Session createAnonymousSession() throws RepositoryException {
    Session admin = getAdminSession();
    AccessControlUtils.addAccessControlEntry(admin, "/", EveryonePrincipal.getInstance(), new String[] { Privilege.JCR_READ }, true);
    admin.save();
    return getRepository().login(new GuestCredentials());
}
Also used : GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session)

Example 20 with GuestCredentials

use of javax.jcr.GuestCredentials in project jackrabbit-oak by apache.

the class VersionTest method testNodeIsCheckedOut.

@Test
public void testNodeIsCheckedOut() throws RepositoryException {
    Session s = repository.login(new GuestCredentials());
    sessions.add(s);
    assertFalse(s.nodeExists("/"));
    assertTrue(s.nodeExists("/testNode"));
    assertTrue(s.getWorkspace().getVersionManager().isCheckedOut("/testNode"));
}
Also used : GuestCredentials(javax.jcr.GuestCredentials) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

GuestCredentials (javax.jcr.GuestCredentials)39 Test (org.junit.Test)25 SimpleCredentials (javax.jcr.SimpleCredentials)13 Credentials (javax.jcr.Credentials)12 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)10 Session (javax.jcr.Session)8 LoginException (javax.security.auth.login.LoginException)7 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Subject (javax.security.auth.Subject)4 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)4 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)4 ArrayList (java.util.ArrayList)3 Repository (javax.jcr.Repository)3 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 Map (java.util.Map)2 RepositoryException (javax.jcr.RepositoryException)2 AccessControlManager (javax.jcr.security.AccessControlManager)2