use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testImpersonationWithAttributes.
@Test
public void testImpersonationWithAttributes() throws Exception {
ContentSession cs = null;
try {
createTestUser();
SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
cs = login(sc);
AuthInfo authInfo = cs.getAuthInfo();
cs.close();
cs = null;
sc = new SimpleCredentials(USER_ID, new char[0]);
sc.setAttribute("attr", "value");
ImpersonationCredentials ic = new ImpersonationCredentials(sc, authInfo);
cs = login(ic);
authInfo = cs.getAuthInfo();
assertTrue(Arrays.asList(authInfo.getAttributeNames()).contains("attr"));
assertEquals("value", authInfo.getAttribute("attr"));
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testAuthInfoContainsUserId.
@Test
public void testAuthInfoContainsUserId() 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());
} finally {
if (cs != null) {
cs.close();
}
}
}
use of org.apache.jackrabbit.oak.api.AuthInfo in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testLoginWithAttributes.
@Test
public void testLoginWithAttributes() throws Exception {
ContentSession cs = null;
try {
createTestUser();
SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PW.toCharArray());
sc.setAttribute("attr", "value");
cs = login(sc);
AuthInfo authInfo = cs.getAuthInfo();
assertTrue(Arrays.asList(authInfo.getAttributeNames()).contains("attr"));
assertEquals("value", authInfo.getAttribute("attr"));
cs.close();
} finally {
if (cs != null) {
cs.close();
}
}
}
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());
}
Aggregations