@Test public void LoginUnsupportedCredentials() throws Exception { Credentials unsupportedCredentials = mock(Credentials.class); CallbackHandler cbh = callbacks -> { for (Callback callback : callbacks) { if (callback instanceof RepositoryCallback) { ((RepositoryCallback) callback).setSecurityProvider(getSecurityProvider()); ((RepositoryCallback) callback).setContentRepository(getContentRepository()); } else if (callback instanceof CredentialsCallback) { ((CredentialsCallback) callback).setCredentials(unsupportedCredentials); } else { throw new UnsupportedCallbackException(callback); } } }; Subject subject = new Subject(false, ImmutableSet.of(), ImmutableSet.of(unsupportedCredentials), ImmutableSet.of()); LoginModuleImpl lm = new LoginModuleImpl(); lm.initialize(subject, cbh, Maps.newHashMap(), Maps.newHashMap()); assertFalse(lm.login()); }
@Override public boolean login() throws LoginException { credentials = getCredentials(); PreAuthenticatedLogin preAuthLogin = getSharedPreAuthLogin(); String loginName = getLoginId(preAuthLogin); Authentication authentication = getUserAuthentication(loginName); if (authentication != null) { if (preAuthLogin != null) { success = authentication.authenticate(PreAuthenticatedLogin.PRE_AUTHENTICATED); } else { success = authentication.authenticate(credentials); } if (success) { log.debug("Adding Credentials to shared state."); sharedState.put(SHARED_KEY_CREDENTIALS, credentials); log.debug("Adding login name to shared state."); sharedState.put(SHARED_KEY_LOGIN_NAME, loginName); userId = authentication.getUserId(); if (userId == null) { userId = loginName; } principal = authentication.getUserPrincipal(); } } else { credentials = null; userId = null; } return success; }
LoginModuleImpl extends AbstractLoginModule { @Override public boolean login() throws LoginException { credentials = getCredentials(); PreAuthenticatedLogin preAuthLogin = getSharedPreAuthLogin(); String loginName = getLoginId(preAuthLogin); Authentication authentication = getUserAuthentication(loginName); if (authentication != null) { if (preAuthLogin != null) { success = authentication.authenticate(PreAuthenticatedLogin.PRE_AUTHENTICATED); } else { success = authentication.authenticate(credentials); } if (success) { log.debug("Adding Credentials to shared state."); sharedState.put(SHARED_KEY_CREDENTIALS, credentials); log.debug("Adding login name to shared state."); sharedState.put(SHARED_KEY_LOGIN_NAME, loginName); userId = authentication.getUserId(); if (userId == null) { userId = loginName; } principal = authentication.getUserPrincipal(); } } else { credentials = null; userId = null; } return success; } }
LoginModuleImpl extends AbstractLoginModule { @Override public boolean login() throws LoginException { credentials = getCredentials(); PreAuthenticatedLogin preAuthLogin = getSharedPreAuthLogin(); String loginName = getLoginId(preAuthLogin); Authentication authentication = getUserAuthentication(loginName); if (authentication != null) { if (preAuthLogin != null) { success = authentication.authenticate(PreAuthenticatedLogin.PRE_AUTHENTICATED); } else { success = authentication.authenticate(credentials); } if (success) { log.debug("Adding Credentials to shared state."); sharedState.put(SHARED_KEY_CREDENTIALS, credentials); log.debug("Adding login name to shared state."); sharedState.put(SHARED_KEY_LOGIN_NAME, loginName); userId = authentication.getUserId(); if (userId == null) { userId = loginName; } principal = authentication.getUserPrincipal(); } } else { credentials = null; userId = null; } return success; }  }
LoginModuleImpl extends AbstractLoginModule { @Override public boolean login() throws LoginException { credentials = getCredentials(); PreAuthenticatedLogin preAuthLogin = getSharedPreAuthLogin(); String loginName = getLoginId(preAuthLogin); Authentication authentication = getUserAuthentication(loginName); if (authentication != null) { if (preAuthLogin != null) { success = authentication.authenticate(PreAuthenticatedLogin.PRE_AUTHENTICATED); } else { success = authentication.authenticate(credentials); } if (success) { log.debug("Adding Credentials to shared state."); sharedState.put(SHARED_KEY_CREDENTIALS, credentials); log.debug("Adding login name to shared state."); sharedState.put(SHARED_KEY_LOGIN_NAME, loginName); userId = authentication.getUserId(); if (userId == null) { userId = loginName; } principal = authentication.getUserPrincipal(); } } else { credentials = null; userId = null; } return success; }  @Override boolean login(); @Override boolean commit(); @Override boolean logout(); }
LoginModuleImpl extends AbstractLoginModule { @Override public boolean login() throws LoginException { credentials = getCredentials(); PreAuthenticatedLogin preAuthLogin = getSharedPreAuthLogin(); String loginName = getLoginId(preAuthLogin); Authentication authentication = getUserAuthentication(loginName); if (authentication != null) { if (preAuthLogin != null) { success = authentication.authenticate(PreAuthenticatedLogin.PRE_AUTHENTICATED); } else { success = authentication.authenticate(credentials); } if (success) { log.debug("Adding Credentials to shared state."); sharedState.put(SHARED_KEY_CREDENTIALS, credentials); log.debug("Adding login name to shared state."); sharedState.put(SHARED_KEY_LOGIN_NAME, loginName); userId = authentication.getUserId(); if (userId == null) { userId = loginName; } principal = authentication.getUserPrincipal(); } } else { credentials = null; userId = null; } return success; }  @Override boolean login(); @Override boolean commit(); @Override boolean logout();  }