public Authentication authenticate(Authentication authentication) throws AuthenticationException { throw new AuthenticationServiceException("Cannot authenticate " + authentication); } }
@Test public void testDetectsNullBeingReturnedFromAuthenticationDao() { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( "rod", "koala"); DaoAuthenticationProvider provider = createProvider(); provider.setUserDetailsService(new MockUserDetailsServiceReturnsNull()); try { provider.authenticate(token); fail("Should have thrown AuthenticationServiceException"); } catch (AuthenticationServiceException expected) { assertThat( "UserDetailsService returned null, which is an interface contract violation").isEqualTo( expected.getMessage()); } }
public Authentication authenticate(Authentication authentication) throws AuthenticationException { throw new AuthenticationServiceException("Cannot authenticate " + authentication); } }
@Test public void testAuthenticateError() { OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider(); provider.setUserDetailsService(new MockUserDetailsService()); Authentication preAuth = new OpenIDAuthenticationToken( OpenIDAuthenticationStatus.ERROR, USERNAME, "", null); assertThat(preAuth.isAuthenticated()).isFalse(); try { provider.authenticate(preAuth); fail("Should throw an AuthenticationException"); } catch (AuthenticationServiceException expected) { assertThat(expected.getMessage()).isEqualTo("Error message from server: "); } }
@Override public ServerConfiguration getServerConfiguration(String issuer) { try { if (!whitelist.isEmpty() && !whitelist.contains(issuer)) { throw new AuthenticationServiceException("Whitelist was nonempty, issuer was not in whitelist: " + issuer); } if (blacklist.contains(issuer)) { throw new AuthenticationServiceException("Issuer was in blacklist: " + issuer); } return servers.get(issuer); } catch (UncheckedExecutionException | ExecutionException e) { logger.warn("Couldn't load configuration for " + issuer + ": " + e); return null; } }
@Test public void testAuthenticateSetupNeeded() { OpenIDAuthenticationProvider provider = new OpenIDAuthenticationProvider(); provider.setUserDetailsService(new MockUserDetailsService()); Authentication preAuth = new OpenIDAuthenticationToken( OpenIDAuthenticationStatus.SETUP_NEEDED, USERNAME, "", null); assertThat(preAuth.isAuthenticated()).isFalse(); try { provider.authenticate(preAuth); fail("Should throw an AuthenticationException"); } catch (AuthenticationServiceException expected) { assertThat( "The server responded setup was needed, which shouldn't happen").isEqualTo( expected.getMessage()); } }
public AuthenticationException resolveException(LoginException e) { return new AuthenticationServiceException(e.getMessage(), e); } }
throw new AccessDeniedException(upe.getMessage(), upe); } catch (final AuthenticationServiceException ase) { throw new AdministrationException(ase.getMessage(), ase);
public AuthenticationException resolveException(LoginException e) { return new AuthenticationServiceException(e.getMessage(), e); } }
@Override public RegisteredClient getClientConfiguration(ServerConfiguration issuer) { try { if (!whitelist.isEmpty() && !whitelist.contains(issuer.getIssuer())) { throw new AuthenticationServiceException("Whitelist was nonempty, issuer was not in whitelist: " + issuer); } if (blacklist.contains(issuer.getIssuer())) { throw new AuthenticationServiceException("Issuer was in blacklist: " + issuer); } return clients.get(issuer); } catch (UncheckedExecutionException | ExecutionException e) { logger.warn("Unable to get client configuration", e); return null; } }
@Override public IssuerServiceResponse getIssuer(HttpServletRequest request) { String identifier = request.getParameter(parameterName); if (!Strings.isNullOrEmpty(identifier)) { try { LoadingResult lr = issuers.get(identifier); if (!whitelist.isEmpty() && !whitelist.contains(lr.issuer)) { throw new AuthenticationServiceException("Whitelist was nonempty, issuer was not in whitelist: " + lr.issuer); } if (blacklist.contains(lr.issuer)) { throw new AuthenticationServiceException("Issuer was in blacklist: " + lr.issuer); } return new IssuerServiceResponse(lr.issuer, lr.loginHint, request.getParameter("target_link_uri")); } catch (UncheckedExecutionException | ExecutionException e) { logger.warn("Issue fetching issuer for user input: " + identifier + ": " + e.getMessage()); return null; } } else { logger.warn("No user input given, directing to login page: " + loginPageUrl); return new IssuerServiceResponse(loginPageUrl); } }
@Override public IssuerServiceResponse getIssuer(HttpServletRequest request) { // if the issuer is passed in, return that String iss = request.getParameter("iss"); if (!Strings.isNullOrEmpty(iss)) { if (!whitelist.isEmpty() && !whitelist.contains(iss)) { throw new AuthenticationServiceException("Whitelist was nonempty, issuer was not in whitelist: " + iss); } if (blacklist.contains(iss)) { throw new AuthenticationServiceException("Issuer was in blacklist: " + iss); } return new IssuerServiceResponse(iss, request.getParameter("login_hint"), request.getParameter("target_link_uri")); } else { try { // otherwise, need to forward to the account chooser String redirectUri = request.getRequestURL().toString(); URIBuilder builder = new URIBuilder(accountChooserUrl); builder.addParameter("redirect_uri", redirectUri); return new IssuerServiceResponse(builder.build().toString()); } catch (URISyntaxException e) { throw new AuthenticationServiceException("Account Chooser URL is not valid", e); } } }
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException( "Authentication method not supported: " + request.getMethod()); } String mobile = obtainMobile(request); if (mobile == null) { mobile = ""; } mobile = mobile.trim(); SmsAuthenticationToken authRequest = new SmsAuthenticationToken(mobile); setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); }
public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (supports(authentication.getClass())) { return authentication; } else { throw new AuthenticationServiceException("Don't support this class"); } }
throw new AuthenticationServiceException( "Error message from server: " + response.getMessage()); throw new AuthenticationServiceException( "The server responded setup was needed, which shouldn't happen"); throw new AuthenticationServiceException( "Unrecognized return value " + status.toString());
throw new AuthenticationServiceException( "Unable to process claimed identity '" + claimedIdentity + "'"); throw new AuthenticationServiceException("Consumer error", oice);
} catch (SAMLException e) { LOGGER.debug("Incoming SAML message is invalid.", e); throw new AuthenticationServiceException("Incoming SAML message is invalid.", e); } catch (MetadataProviderException e) { LOGGER.debug("Error determining metadata contracts.", e); throw new AuthenticationServiceException("Error determining metadata contracts.", e); } catch (MessageEncodingException e) { LOGGER.debug("Error decoding incoming SAML message.", e); throw new AuthenticationServiceException("Error encoding outgoing SAML message.", e); } catch (MarshallingException | SecurityException | SignatureException e) { LOGGER.debug("Error signing SAML assertion.", e); throw new AuthenticationServiceException("Error signing SAML assertion.", e);
@Override public String buildAuthRequestUrl(ServerConfiguration serverConfig, RegisteredClient clientConfig, String redirectUri, String nonce, String state, Map<String, String> options, String loginHint) { try { URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri()); uriBuilder.addParameter("response_type", "code"); uriBuilder.addParameter("client_id", clientConfig.getClientId()); uriBuilder.addParameter("scope", Joiner.on(" ").join(clientConfig.getScope())); uriBuilder.addParameter("redirect_uri", redirectUri); uriBuilder.addParameter("nonce", nonce); uriBuilder.addParameter("state", state); // Optional parameters: for (Entry<String, String> option : options.entrySet()) { uriBuilder.addParameter(option.getKey(), option.getValue()); } // if there's a login hint, send it if (!Strings.isNullOrEmpty(loginHint)) { uriBuilder.addParameter("login_hint", loginHint); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e); } }
Throwable cause = exception.getCause(); if (cause != null) { AuthenticationException e = new AuthenticationServiceException(cause.getMessage(), cause.getCause()); logger.debug(cause); super.onAuthenticationFailure(request, response, e);
throw new AuthenticationServiceException("No issuer found."); throw new AuthenticationServiceException("No issuer found: " + issuer); if (serverConfig == null) { logger.error("No server configuration found for issuer: " + issuer); throw new AuthenticationServiceException("No server configuration found for issuer: " + issuer); if (clientConfig == null) { logger.error("No client configuration found for issuer: " + issuer); throw new AuthenticationServiceException("No client configuration found for issuer: " + issuer);