use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class AuthInfoImplTest method testCreateFromSubjectWithSimpleCredentials.
@Test
public void testCreateFromSubjectWithSimpleCredentials() {
Subject subject = new Subject();
subject.getPublicCredentials().add(new SimpleCredentials(USER_ID, new char[0]));
AuthInfo info = AuthInfoImpl.createFromSubject(subject);
assertEquals(USER_ID, info.getUserID());
assertTrue(info.getPrincipals().isEmpty());
assertEquals(0, info.getAttributeNames().length);
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class L2_AuthInfoTest method testUserAuthInfo.
@Test
public void testUserAuthInfo() throws LoginException, RepositoryException, CommitFailedException {
testUser = createTestUser(userManager);
root.commit();
contentSession = login(ExerciseUtility.getTestCredentials(testUser.getID()));
AuthInfo authInfo = contentSession.getAuthInfo();
// EXERCISE : fill in the expected id
String expectedId = null;
assertEquals(expectedId, authInfo.getUserID());
// EXERCISE: create the set of expected principals.
// EXERCISE: what are the variants you have at hand when using the Jackrabbit API
// EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces?
Set<Principal> expectedPrincipals = null;
assertEquals(expectedPrincipals, authInfo.getPrincipals());
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class L2_AuthInfoTest method testUserAuthInfoWithGroupMembership.
@Test
public void testUserAuthInfoWithGroupMembership() throws LoginException, RepositoryException, CommitFailedException {
testUser = createTestUser(userManager);
testGroup = createTestGroup(userManager);
testGroup.addMember(testUser);
root.commit();
contentSession = login(getTestCredentials(testUser.getID()));
AuthInfo authInfo = contentSession.getAuthInfo();
// EXERCISE: create the set of expected principals.
// EXERCISE: what are the variants you have at hand when using the Jackrabbit API
// EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces?
Set<Principal> expectedPrincipals = null;
assertEquals(expectedPrincipals, authInfo.getPrincipals());
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class L2_AuthInfoTest method testGuestAuthInfo.
@Test
public void testGuestAuthInfo() throws LoginException, NoSuchWorkspaceException {
contentSession = login(new GuestCredentials());
AuthInfo authInfo = contentSession.getAuthInfo();
// EXERCISE : fill in the expected id
String expectedId = null;
assertEquals(expectedId, authInfo.getUserID());
// EXERCISE: create the set of expected principals.
// EXERCISE: what are the variants you have at hand when using the Jackrabbit API
// EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces?
Set<Principal> expectedPrincipals = null;
assertEquals(expectedPrincipals, authInfo.getPrincipals());
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project sling by apache.
the class OakSlingRepository method createAdministrativeSession.
@Override
protected Session createAdministrativeSession(String workspace) throws RepositoryException {
// TODO: use principal provider to retrieve admin principal
Set<? extends Principal> principals = singleton(new AdminPrincipal() {
@Override
public String getName() {
return OakSlingRepository.this.adminId;
}
});
AuthInfo authInfo = new AuthInfoImpl(this.adminId, Collections.<String, Object>emptyMap(), principals);
Subject subject = new Subject(true, principals, singleton(authInfo), Collections.<Object>emptySet());
Session adminSession;
try {
adminSession = Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>() {
@Override
public Session run() throws Exception {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("oak.refresh-interval", 0);
// TODO OAK-803: Backwards compatibility of long-lived sessions
JackrabbitRepository repo = (JackrabbitRepository) getRepository();
return repo.login(null, null, attrs);
}
}, null);
} catch (PrivilegedActionException e) {
throw new RepositoryException("failed to retrieve admin session.", e);
}
return adminSession;
}
Aggregations