List of usage examples for org.springframework.security.authentication AuthenticationServiceException AuthenticationServiceException
public AuthenticationServiceException(String msg)
AuthenticationServiceException
with the specified message. From source file:com.hp.autonomy.hod.sso.SsoAuthenticationFilter.java
@Override public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticationException, IOException, ServletException { if (!StringUtils.isEmpty(request.getParameter("error"))) { throw new AuthenticationServiceException("The SSO page returned an error"); }/*from www. j a va 2s .c o m*/ final DateTime expiry; try { expiry = new DateTime(Long.parseLong(request.getParameter("expiry"))); } catch (final NumberFormatException ignored) { throw new BadCredentialsException("Invalid combined SSO token"); } final AuthenticationToken<E, TokenType.Simple> token = new AuthenticationToken<>(entityType, TokenType.Simple.INSTANCE, request.getParameter("type"), expiry, request.getParameter("id"), request.getParameter("secret"), null); return getAuthenticationManager().authenticate(new HodTokenAuthentication<>(token)); }
From source file:com.wwpass.springsecurity.web.authentication.WwpassAuthenticationFilter.java
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (!request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }// w w w. java 2 s. co m String ticket = request.getParameter("ticket"); String puid; try { ticket = conn.putTicket(ticket); puid = conn.getPUID(ticket); } catch (UnsupportedEncodingException e) { throw new AuthenticationServiceException("Exception in WWPassConnection library: \n", e); } catch (IOException e) { throw new AuthenticationServiceException("Exception in WWPassConnection library: \n", e); } if (puid == null) { throw new IllegalArgumentException("PUID cannot be null."); } request.getSession().setAttribute("puid", puid); WwpassAuthenticationToken authRequest = new WwpassAuthenticationToken(null, puid, null); return this.getAuthenticationManager().authenticate(authRequest); }
From source file:org.createnet.raptor.auth.service.jwt.JsonUsernamePasswordFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (!request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }/*from w w w.jav a 2 s . co m*/ if (!request.getContentType().equals(MediaType.APPLICATION_JSON)) { throw new AuthenticationServiceException("Only Content-Type " + MediaType.APPLICATION_JSON + " is supported. Provided is " + request.getContentType()); } LoginForm loginForm; try { InputStream body = request.getInputStream(); loginForm = jacksonObjectMapper.readValue(body, LoginForm.class); } catch (IOException ex) { throw new AuthenticationServiceException("Error reading body", ex); } if (loginForm.username == null) { loginForm.username = ""; } if (loginForm.password == null) { loginForm.password = ""; } loginForm.username = loginForm.username.trim(); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( loginForm.username, loginForm.password); setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); }
From source file:org.keycloak.adapters.springsecurity.filter.DirectAccessGrantLoginFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (postOnly && !request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }/*w ww .j a va2 s .c o m*/ String username = obtainUsername(request); String password = obtainPassword(request); if (username == null) { username = ""; } if (password == null) { password = ""; } username = username.trim(); DirectAccessGrantToken authRequest = new DirectAccessGrantToken(username, password); // Allow subclasses to set the "details" property setDetails(request, authRequest); return this.getAuthenticationManager().authenticate(authRequest); }
From source file:com.gcrm.security.AuthenticationFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { if (!request.getMethod().equals("POST")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); }/*from w w w .j a v a 2s . c o m*/ String username = obtainUsername(request); String password = obtainPassword(request); // Validates username and password username = username.trim(); String localValue = obtainLanguage(request); String[] locals = localValue.split("_"); Locale locale = new Locale(locals[0], locals[1]); request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", locale); request.getSession().setAttribute("locale", localValue); Locale.setDefault(locale); User user = UserUtil.getUser(username); Md5PasswordEncoder encoder = new Md5PasswordEncoder(); password = encoder.encodePassword(password, AuthenticationFilter.SALT); if (user == null || !user.getPassword().equals(password)) { ResourceBundle rb = CommonUtil.getResourceBundle(); String errorMessage = rb.getString("error.login.denied"); throw new AuthenticationServiceException(errorMessage); } UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password); setDetails(request, authRequest); // return authRequest; return this.getAuthenticationManager().authenticate(authRequest); }
From source file:com.launchkey.example.springmvc.LaunchKeyAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); try {//from w w w .ja v a 2 s .c o m this.authManager.login(username); Boolean authorized = null; while (authorized == null) { Thread.sleep(100L); authorized = this.authManager.isAuthorized(); } if (authorized == null) { throw new InsufficientAuthenticationException( "The authentication request was not responded to in sufficient time"); } else if (!authorized) { throw new InsufficientAuthenticationException("The authentication request was denied"); } } catch (InterruptedException e) { throw new AuthenticationServiceException("Sleep error"); } catch (AuthManager.AuthException e) { if (e.getCause() instanceof LaunchKeyException) { throw new BadCredentialsException("Authentication failure", e.getCause()); } } return new UsernamePasswordAuthenticationToken(username, authentication.getCredentials(), new ArrayList<GrantedAuthority>()); }
From source file:authentication.ResponseHeaderAuthenticationListener.java
/** {@inheritDoc} */ @Override/* ww w . j ava 2 s.co m*/ public void onAuthenticationSuccess(final AuthenticationEvent event) throws IOException { final JWTClaimsSet claimsSet = new JWTClaimsSet(); final long now = System.currentTimeMillis(); claimsSet.setSubject(event.getUsername()); claimsSet.setIssueTime(new Date(now)); claimsSet.setIssuer("http://localhost:8080/snackbar/"); claimsSet.setExpirationTime(new Date(now + FIVE_HOURS_IN_MILLISECONDS)); claimsSet.setNotBeforeTime(new Date(now)); final SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet); try { signedJWT.sign(signer); } catch (final JOSEException e) { throw new AuthenticationServiceException("The given JWT could not be signed."); } final HttpServletResponse resp = event.getResponse(); resp.setHeader("Authorization", String.format("Bearer %s", signedJWT.serialize())); }
From source file:org.callistasoftware.netcare.video.web.security.AuthenticationProvider.java
@Override public Authentication authenticate(final Authentication auth) throws AuthenticationException { log.info("Authenticating {}", auth.getName()); try {/* www .j a v a 2 s. c o m*/ final UserDetails details = this.service.loadUserByUsername(auth.getName()); return new UsernamePasswordAuthenticationToken(details, null, details.getAuthorities()); } catch (final UsernameNotFoundException e) { } throw new AuthenticationServiceException("Bad credentials"); }
From source file:br.com.insula.spring.security.janrain.JanrainAuthenticationFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String token = request.getParameter("token"); if (token != null && !token.isEmpty()) { try {//from w ww .j av a2 s . co m JanrainAuthenticationToken authentication = janrainService.authenticate(token); if (authentication != null) { return getAuthenticationManager().authenticate(authentication); } else { throw new AuthenticationServiceException( "Unable to parse authentication. Is your 'applicationName' correct?"); } } catch (Exception ex) { throw new ServletException(ex); } } return null; }
From source file:ar.com.zauber.commons.social.twitter.security.TwitterAuthenticationProcessingFilter.java
/** * @see AbstractAuthenticationProcessingFilter * #attemptAuthentication(HttpServletRequest, * HttpServletResponse)//from w w w . jav a 2 s . c om */ @Override public final Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticationException, IOException, ServletException { if (!request.getMethod().equals("GET")) { throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod()); } final String oauthToken = request.getParameter("oauth_token"); final String oauthVerifier = request.getParameter("oauth_verifier"); // verifier may be null final String denyToken = request.getParameter("denied"); if (denyToken != null) { throw new BadCredentialsException("twitter access denied"); } if (oauthToken == null) { throw new AuthenticationServiceException("missing oauth_token parameter"); } return this.getAuthenticationManager() .authenticate(new TwitterAuthenticationToken(oauthToken, oauthVerifier)); }