use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class AuthInfoImplNullTest method testCreateAuthInfoFromEmptySubject.
@Test
public void testCreateAuthInfoFromEmptySubject() {
AuthInfo info = AuthInfoImpl.createFromSubject(new Subject());
assertNull(info.getUserID());
assertEquals(0, info.getAttributeNames().length);
assertTrue(info.getPrincipals().isEmpty());
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class AuthInfoImplTest method testCreateFromSubjectWithPrivateSimpleCredentials.
@Test
public void testCreateFromSubjectWithPrivateSimpleCredentials() {
Subject subject = new Subject();
subject.getPrivateCredentials().add(new SimpleCredentials(USER_ID, new char[0]));
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 testCreateFromSubjectWithPrincipals.
@Test
public void testCreateFromSubjectWithPrincipals() {
Subject subject = new Subject();
subject.getPrincipals().addAll(PRINCIPALS);
AuthInfo info = AuthInfoImpl.createFromSubject(subject);
assertNull(info.getUserID());
assertEquals(PRINCIPALS, info.getPrincipals());
assertEquals(0, info.getAttributeNames().length);
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class IndexInitializer method createAdministrativeSession.
private Session createAdministrativeSession() throws RepositoryException {
//Admin ID here can be any string and need not match the actual admin userId
final String adminId = "admin";
Principal admin = new AdminPrincipal() {
@Override
public String getName() {
return adminId;
}
};
AuthInfo authInfo = new AuthInfoImpl(adminId, null, singleton(admin));
Subject subject = new Subject(true, singleton(admin), singleton(authInfo), Collections.emptySet());
Session adminSession;
try {
adminSession = Subject.doAsPrivileged(subject, new PrivilegedExceptionAction<Session>() {
@Override
public Session run() throws Exception {
return repository.login();
}
}, null);
} catch (PrivilegedActionException e) {
throw new RepositoryException("failed to retrieve admin session.", e);
}
return adminSession;
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class UserIDTestLoginModule method commit.
@Override
public boolean commit() {
if (!subject.isReadOnly()) {
// be defensive: remove all potentially added "AuthInfo' objects.
Set<AuthInfo> ais = subject.getPublicCredentials(AuthInfo.class);
if (!ais.isEmpty()) {
subject.getPublicCredentials().removeAll(ais);
}
// and finally add the one that produces the desired result:
String userID = null;
subject.getPublicCredentials().add(new AuthInfoImpl(userID, Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
return true;
} else {
return false;
}
}
Aggregations