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();
}
}
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();
}
}
}
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());
}
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());
}
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"));
}
Aggregations