use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class PreAuthTest method testValidReadSubjectWithCredentials.
@Test
public void testValidReadSubjectWithCredentials() throws Exception {
Set<SimpleCredentials> publicCreds = Collections.singleton(new SimpleCredentials("testUserId", new char[0]));
final Subject subject = new Subject(true, principals, publicCreds, Collections.<Object>emptySet());
ContentSession cs = Subject.doAsPrivileged(subject, new PrivilegedAction<ContentSession>() {
@Override
public ContentSession run() {
try {
return login(null);
} catch (Exception e) {
return null;
}
}
}, null);
try {
AuthInfo authInfo = cs.getAuthInfo();
assertNotSame(AuthInfo.EMPTY, authInfo);
assertEquals(principals, authInfo.getPrincipals());
assertEquals("testUserId", authInfo.getUserID());
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class GuestDefaultLoginModuleTest method testGuestLogin.
@Test
public void testGuestLogin() throws Exception {
ContentSession cs = login(new GuestCredentials());
try {
AuthInfo authInfo = cs.getAuthInfo();
String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters());
assertEquals(anonymousID, authInfo.getUserID());
} finally {
cs.close();
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class AbstractLoginModuleTest method testSetAuthInfoPreExisting.
@Test
public void testSetAuthInfoPreExisting() {
Subject subject = new Subject();
subject.getPublicCredentials().add(new AuthInfoImpl(null, null, null));
AuthInfo authInfo = new AuthInfoImpl("userid", null, null);
AbstractLoginModule.setAuthInfo(authInfo, subject);
Set<AuthInfo> fromSubject = subject.getPublicCredentials(AuthInfo.class);
assertEquals(1, fromSubject.size());
assertSame(authInfo, fromSubject.iterator().next());
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class AuthInfoImplTest method testCreateFromSubjectWithAnyCredentials.
@Test
public void testCreateFromSubjectWithAnyCredentials() {
Subject subject = new Subject();
subject.getPublicCredentials().add(new Credentials() {
});
AuthInfo info = AuthInfoImpl.createFromSubject(subject);
assertNull(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 AuthInfoImplTest method testCreateFromSubjectWithAuthInfo.
@Test
public void testCreateFromSubjectWithAuthInfo() {
Subject subject = new Subject();
subject.getPublicCredentials().add(authInfo);
AuthInfo info = AuthInfoImpl.createFromSubject(subject);
assertEquals(USER_ID, info.getUserID());
assertEquals(PRINCIPALS, info.getPrincipals());
assertArrayEquals(authInfo.getAttributeNames(), info.getAttributeNames());
}
Aggregations