use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testUserLoginIsCaseInsensitive2.
@Test
public void testUserLoginIsCaseInsensitive2() throws Exception {
ContentSession cs = null;
try {
createTestUser();
cs = login(new SimpleCredentials(USER_ID_CASED, USER_PW.toCharArray()));
AuthInfo authInfo = cs.getAuthInfo();
assertEquals(user.getID(), authInfo.getUserID());
assertTrue(USER_ID_CASED.equalsIgnoreCase(authInfo.getUserID()));
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testCustomUserAuthentication.
@Test
public void testCustomUserAuthentication() throws Exception {
LoginModuleImpl loginModule = new LoginModuleImpl();
UserAuthenticationFactory factory = new UserAuthenticationFactory() {
@CheckForNull
@Override
public Authentication getAuthentication(@Nonnull UserConfiguration configuration, @Nonnull Root root, @Nullable String userId) {
return new Authentication() {
@Override
public boolean authenticate(@Nullable Credentials credentials) throws LoginException {
return true;
}
@CheckForNull
@Override
public String getUserId() {
return null;
}
@CheckForNull
@Override
public Principal getUserPrincipal() {
return null;
}
};
}
};
CallbackHandler cbh = new TestCallbackHandler(factory);
SimpleCredentials creds = new SimpleCredentials("loginId", new char[0]);
Subject subject = new Subject(false, Sets.<Principal>newHashSet(), ImmutableSet.of(creds), Sets.newHashSet());
loginModule.initialize(subject, cbh, Maps.<String, Object>newHashMap(), Maps.<String, Object>newHashMap());
assertTrue(loginModule.login());
assertTrue(loginModule.commit());
AuthInfo authInfo = subject.getPublicCredentials(AuthInfo.class).iterator().next();
assertEquals("loginId", authInfo.getUserID());
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testUserLogin.
@Test
public void testUserLogin() throws Exception {
ContentSession cs = null;
try {
createTestUser();
cs = login(new SimpleCredentials(USER_ID, USER_PW.toCharArray()));
AuthInfo authInfo = cs.getAuthInfo();
assertEquals(USER_ID, authInfo.getUserID());
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testInvalidImpersonation.
@Test
public void testInvalidImpersonation() throws Exception {
ContentSession cs = null;
try {
createTestUser();
SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
cs = login(sc);
AuthInfo authInfo = cs.getAuthInfo();
assertEquals(USER_ID, authInfo.getUserID());
cs.close();
cs = null;
ConfigurationParameters config = securityProvider.getConfiguration(UserConfiguration.class).getParameters();
String adminId = UserUtil.getAdminId(config);
sc = new SimpleCredentials(adminId, new char[0]);
ImpersonationCredentials ic = new ImpersonationCredentials(sc, authInfo);
try {
cs = login(ic);
fail("User 'test' should not be allowed to impersonate " + adminId);
} catch (LoginException e) {
// success
}
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class AbstractLoginModuleTest method testSetAuthInfo.
@Test
public void testSetAuthInfo() {
Subject subject = new Subject();
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());
}
Aggregations