use of org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl in project jackrabbit-oak by apache.
the class Jackrabbit2ConfigurationTest method testTokenCreationAndImpersonation.
@Test
public void testTokenCreationAndImpersonation() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
cs = login(ic);
Object token = sc.getAttribute(".token").toString();
assertNotNull(token);
TokenCredentials tc = new TokenCredentials(token.toString());
cs.close();
cs = login(tc);
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl in project jackrabbit-oak by apache.
the class PreAuthTest method testValidSubjectWithAuthInfo.
@Test
public void testValidSubjectWithAuthInfo() throws Exception {
AuthInfo info = new AuthInfoImpl("testUserId", Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet());
Set<AuthInfo> publicCreds = Collections.singleton(info);
final Subject subject = new Subject(false, Collections.singleton(new TestPrincipal()), 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 {
assertSame(info, cs.getAuthInfo());
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl in project jackrabbit-oak by apache.
the class Jackrabbit2ConfigurationTest method testTokenCreationWithImpersonationAttributes.
@Test
public void testTokenCreationWithImpersonationAttributes() throws Exception {
ContentSession cs = null;
try {
SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
sc.setAttribute(".token", "");
sc.setAttribute(".token.mandatory", "something");
sc.setAttribute("attr", "val");
ImpersonationCredentials ic = new ImpersonationCredentials(sc, new AuthInfoImpl(((SimpleCredentials) getAdminCredentials()).getUserID(), Collections.<String, Object>emptyMap(), Collections.<Principal>emptySet()));
cs = login(ic);
AuthInfo ai = cs.getAuthInfo();
Set<String> attrNames = ImmutableSet.copyOf(ai.getAttributeNames());
assertTrue(attrNames.contains("attr"));
assertFalse(attrNames.contains(".token"));
assertFalse(attrNames.contains(".token.mandatory"));
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl in project jackrabbit-oak by apache.
the class TestLoginModule method commit.
@Override
public boolean commit() throws LoginException {
if (userId != null) {
subject.getPrincipals().add(EveryonePrincipal.getInstance());
setAuthInfo(new AuthInfoImpl(userId, credentialsSupport.getAttributes(credentials), subject.getPrincipals()), subject);
return true;
} else {
return false;
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.AuthInfoImpl 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;
}
Aggregations