Refine search
@Test public void repositoryLogin() throws Exception{ //Simple sanity test to see if repository is working Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); session.logout(); } }
@Test public void testAuthenticateMissing() throws Exception { SimpleCredentials creds = new SimpleCredentials("foobar" + TEST_USER1_UID, "pass".toCharArray()); ExternalUser user = idp.authenticate(creds); assertNull("Authenticate must return NULL for unknown user", user); }
@Test public void testCreateTokenFromCredentials() throws Exception { SimpleCredentials sc = new SimpleCredentials(userId, new char[0]); List<Credentials> valid = new ArrayList<Credentials>(); valid.add(sc); valid.add(new ImpersonationCredentials(sc, null)); for (Credentials creds : valid) { TokenInfo info = tokenProvider.createToken(creds); assertTokenInfo(info, userId); } }
@Test public void testAuthenticateWithInvalidCredentials() throws Exception { List<Credentials> invalid = new ArrayList<Credentials>(); invalid.add(new GuestCredentials()); invalid.add(new SimpleCredentials(userId, new char[0])); for (Credentials creds : invalid) { assertFalse(authentication.authenticate(creds)); } }
@Test public void testAuthenticatePasswordExpiredNewUser() throws Exception { Authentication a = new UserAuthentication(getUserConfiguration(), root, userId); // during user creation pw last modified is set, thus it shouldn't expire a.authenticate(new SimpleCredentials(userId, userId.toCharArray())); }
@Test public void testAuthenticateIdMismatch() throws Exception { try { authentication.authenticate(new SimpleCredentials("unknownUser", "pw".toCharArray())); fail("LoginException expected"); } catch (LoginException e) { // success assertTrue(e instanceof FailedLoginException); } }
@Test public void testGetUserId() throws LoginException { authentication.authenticate(new SimpleCredentials(userId, userId.toCharArray())); assertEquals(userId, authentication.getUserId()); }
@Test public void testAuthenticatePasswordExpiredNewUser() throws Exception { Authentication a = new UserAuthentication(getUserConfiguration(), root, userId); // during user creation pw last modified is set, thus it shouldn't expire a.authenticate(new SimpleCredentials(userId, userId.toCharArray())); }
@Test public void testImpersonateSystemUser() throws Exception { createUser(null); ContentSession cs = login(new ImpersonationCredentials(new SimpleCredentials(uid, new char[0]), adminSession.getAuthInfo())); cs.close(); }
@Test public void testGetCredentialsFromSubjectWrongClass() { Subject subject = new Subject(); subject.getPublicCredentials().add(new SimpleCredentials("userid", new char[0])); AbstractLoginModule lm = new TestLoginModule(TestCredentials.class); lm.initialize(subject, null, ImmutableMap.<String, Object>of(), null); assertNull(lm.getCredentials()); }
@Test public void testLoginAfterChangePassword() throws RepositoryException { user.changePassword("changed"); superuser.save(); // make sure the user can login with the new pw Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), "changed".toCharArray())); s.logout(); }
@Test public void testCreateTokenWithInvalidExpirationParam() throws Exception { SimpleCredentials sc = new SimpleCredentials(userId, new char[0]); sc.setAttribute(TokenProvider.PARAM_TOKEN_EXPIRATION, "invalid"); try { tokenProvider.createToken(sc); fail(); } catch (NumberFormatException e) { // success } }
@Test public void testAuthenticateMustChangePassword() throws Exception { Authentication a = new UserAuthentication(getUserConfiguration(), root, userId); try { // the user should need to change the password on first login a.authenticate(new SimpleCredentials(userId, userId.toCharArray())); fail("Credentials should be expired"); } catch (CredentialExpiredException e) { // success } }
@Test public void testCreateTokenFromInvalidCredentials() throws Exception { List<Credentials> invalid = new ArrayList<Credentials>(); invalid.add(new GuestCredentials()); invalid.add(new TokenCredentials("sometoken")); invalid.add(new ImpersonationCredentials(new GuestCredentials(), null)); invalid.add(new SimpleCredentials("unknownUserId", new char[0])); for (Credentials creds : invalid) { assertNull(tokenProvider.createToken(creds)); } }
@Test public void testAuthenticateMustChangePassword() throws Exception { Authentication a = new UserAuthentication(getUserConfiguration(), root, userId); try { a.authenticate(new SimpleCredentials(userId, userId.toCharArray())); fail("Credentials should be expired"); } catch (CredentialExpiredException e) { // success } }
@Test public void testAuthenticateWithoutUserId() throws Exception { authentication = new UserAuthentication(getUserConfiguration(), root, null); assertFalse(authentication.authenticate(new SimpleCredentials(userId, userId.toCharArray()))); }
@Test public void testLoginWithOldPassword() throws RepositoryException, NotExecutableException { try { user.changePassword("changed"); superuser.save(); Session s = getHelper().getRepository().login(new SimpleCredentials(user.getID(), testPw.toCharArray())); s.logout(); fail("user pw has changed. login must fail."); } catch (LoginException e) { // success } }
@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); }
@Test public void testUnknownUserLogin() throws RepositoryException { String uid = createUserId(); assertNull(userMgr.getAuthorizable(uid)); try { Session s = superuser.getRepository().login(new SimpleCredentials(uid, uid.toCharArray())); s.logout(); fail("An unknown user should not be allowed to execute the login."); } catch (Exception e) { // ok. } }
@Test public void testAuthenticateImpersonationCredentials() throws Exception { SimpleCredentials sc = new SimpleCredentials(userId, new char[0]); assertTrue(authentication.authenticate(new ImpersonationCredentials(sc, adminSession.getAuthInfo()))); }