List of usage examples for org.springframework.security.authentication AuthenticationServiceException AuthenticationServiceException
public AuthenticationServiceException(String msg, Throwable t)
AuthenticationServiceException
with the specified message and root cause. From source file:net.projectmonkey.spring.acl.util.reflect.FieldUtil.java
public static Object getFieldValue(final Object domainObject, final String fieldName) { Field field = ReflectionUtils.findField(domainObject.getClass(), fieldName); field.setAccessible(true);/* w ww .j a v a 2 s. c o m*/ try { return field.get(domainObject); } catch (Exception e) { throw new AuthenticationServiceException("Exception retrieving field " + fieldName, e); } }
From source file:net.projectmonkey.spring.acl.util.reflect.MethodUtil.java
public static Object invoke(final Method method, final Object target, final Object... args) { Object providedArgument = null; if (target != null) { try {//from w ww. j ava2s . c o m providedArgument = method.invoke(target, args); } catch (Exception e) { throw new AuthenticationServiceException("Exception invoking method " + method, e); } } return providedArgument; }
From source file:com.mothsoft.alexis.security.CurrentUserUtil.java
public static UserAuthenticationDetails getCurrentUser() { final SecurityContext ctx = SecurityContextHolder.getContext(); final Authentication authentication = ctx.getAuthentication(); try {/*from www .java 2 s . c o m*/ return authentication != null && authentication.isAuthenticated() ? (UserAuthenticationDetails) authentication.getPrincipal() : null; } catch (ClassCastException e) { throw new AuthenticationServiceException(e.getLocalizedMessage(), e); } }
From source file:edu.uchicago.duo.security.DuoAuthenticationDetailsSource.java
@Override public GrantedAuthoritiesContainer buildDetails(HttpServletRequest request) { List gal = new ArrayList(); try {/*from w ww .j a va2s .c o m*/ GrantedAuthority ga = null; if (StringUtils.hasLength(request.getHeader("uid"))) { ga = new SimpleGrantedAuthority("ROLE_USER"); } else { ga = new SimpleGrantedAuthority("ROLE_ANONYMOUS"); } log.debug("UID=" + request.getHeader("uid") + "|Granted:" + ga); gal.add(ga); } catch (Exception e) { throw new AuthenticationServiceException("Error..", e); } return new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(request, gal); }
From source file:com.googlecode.janrain4j.springframework.security.JanrainAuthenticationFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException { String token = request.getParameter("token"); if (token != null && token.length() > 0) { try {//from w w w. j a va2s . c o m UserDataResponse userDataResponse = engageService.authInfo(token, extended); JanrainAuthenticationToken janrainAuthenticationToken = new JanrainAuthenticationToken( userDataResponse); janrainAuthenticationToken.setDetails(authenticationDetailsSource.buildDetails(request)); return getAuthenticationManager().authenticate(janrainAuthenticationToken); } catch (EngageFailureException e) { throw new AuthenticationServiceException("Unable to retrieve Janrain user information", e); } catch (ErrorResponeException e) { throw new AuthenticationServiceException("Unable to retrieve Janrain user information", e); } } return null; }
From source file:org.geonode.security.GeoNodeAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication, HttpServletRequest request) throws AuthenticationException { this.client.setRequestUrl("http://" + request.getServerName() + "/"); if (authentication instanceof UsernamePasswordAuthenticationToken) { UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication; String username = token.getName(); String password = (String) token.getCredentials(); // ignore this - let the other provider(s) handle things if (GeoServerUser.ROOT_USERNAME.equals(username) && GeoServerUser.DEFAULT_ADMIN_PASSWD.equals(username)) { return null; }//from ww w. j a va2 s . com try { if (username == "" && password == null) { return client.authenticateAnonymous(); } else { // if an anonymous session cookie exists in the request but // the user is logging in via the admin or other form mechanism, // it's possible that the GeoNodeCookieProcessingFilter will // 'overwrite' the credentials... it will check for this Authentication auth = client.authenticateUserPwd(username, password); if (auth.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(auth); } return auth; } } catch (IOException e) { throw new AuthenticationServiceException( "Communication with GeoNode failed (UsernamePasswordAuthenticationToken)", e); } } else if (authentication instanceof GeoNodeSessionAuthToken) { try { return client.authenticateCookie((String) authentication.getCredentials()); } catch (IOException e) { throw new AuthenticationServiceException( "Communication with GeoNode failed (GeoNodeSessionAuthToken)", e); } } else if (authentication instanceof AnonymousGeoNodeAuthenticationToken) { try { return client.authenticateAnonymous(); } catch (IOException e) { throw new AuthenticationServiceException( "Communication with GeoNode failed (AnonymousGeoNodeAuthenticationToken)", e); } } else { throw new IllegalArgumentException( "GeoNodeAuthenticationProvider accepts only UsernamePasswordAuthenticationToken and GeoNodeSessionAuthToken; received " + authentication); } }
From source file:cn.com.fubon.springboot.starter.jwt.auth.JwtTokenServiceImpl.java
@Override public Authentication parseJwtToken(String jwtToken) throws AuthenticationException { try {/*from w w w .j a va 2 s .c o m*/ Claims claims = Jwts.parser().setSigningKey(secretkey).parseClaimsJws(jwtToken).getBody(); return JwtAuthenticationToken.of(claims); } catch (ExpiredJwtException | SignatureException e) { throw new BadCredentialsException(e.getMessage(), e); } catch (UnsupportedJwtException | MalformedJwtException e) { throw new AuthenticationServiceException(e.getMessage(), e); } catch (IllegalArgumentException e) { throw new InternalAuthenticationServiceException(e.getMessage(), e); } }
From source file:org.mitre.openid.connect.client.service.impl.PlainAuthRequestUrlBuilder.java
@Override public String buildAuthRequestUrl(ServerConfiguration serverConfig, RegisteredClient clientConfig, String redirectUri, String nonce, String state, Map<String, String> options, String loginHint) { try {/*from w ww.j ava 2s . co m*/ 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); } }
From source file:ar.com.zauber.commons.social.twitter.security.TwitterAuthenticationProvider.java
/** @see AuthenticationProvider#authenticate(Authentication) */ public final Authentication authenticate(final Authentication authentication) throws AuthenticationException { Validate.notNull(authentication);//from w ww .j a v a 2s .c o m TwitterAuthenticationToken authenticationToken = (TwitterAuthenticationToken) authentication; try { Object accessToken = authenticationToken.getCredentials(); if (accessToken == null) { final String oAuthToken = authenticationToken.getOAuthToken(); final String oAuthVerifier = authenticationToken.getOAuthVerifier(); accessToken = twitterAccessManager.getAccessToken(oAuthToken, oAuthVerifier); } UserDetails userDetails = this.userDetailsService .loadUserByTwitterAccessToken((OAuthAccessToken) accessToken); return new TwitterAuthenticationToken((OAuthAccessToken) accessToken, userDetails, userDetails.getAuthorities()); } catch (OAuthAccessException e) { throw new AuthenticationServiceException("twitter error", e); } }
From source file:org.shredzone.cilla.ws.cxf.CillaRemoteAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!(authentication.getPrincipal() instanceof RemoteUserDetails)) { throw new InsufficientAuthenticationException( "authentication must contain a RemoteUserDetails principal"); }//from w ww .ja v a 2 s .c om try { RemoteUserDetails userDetails = (RemoteUserDetails) authentication.getPrincipal(); List<GrantedAuthority> authorities = loginWs.authenticate().getRights().stream() .map(SimpleGrantedAuthority::new).collect(toList()); userDetails.setAuthorities(authorities); userDetails.setUser(userWs.fetchByLogin(userDetails.getUsername())); return new UsernamePasswordAuthenticationToken(userDetails, null, authorities); } catch (SOAPFaultException ex) { throw new BadCredentialsException(ex.getMessage()); } catch (CillaServiceException ex) { throw new AuthenticationServiceException("couldn't get user details", ex); } }