List of usage examples for org.springframework.security.authentication AbstractAuthenticationToken getPrincipal
Object getPrincipal();
From source file:com.katsu.springframework.security.authentication.HtmlAuthenticationProvider.java
private Authentication createSuccessAuthentication(AbstractAuthenticationToken upat, Collection<? extends GrantedAuthority> roles) { UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(upat.getPrincipal(), upat.getCredentials(), roles); result.setDetails(upat.getDetails()); return result; }
From source file:com.bac.accountserviceapp.AccountServiceApp.java
@Override public Authentication login(AbstractAuthenticationToken authentication) { Objects.requireNonNull(authenticationManager, noAuthManagerMsg); Objects.requireNonNull(authentication, noAuthenticationMsg); try {/* w w w . j a v a 2s . com*/ authentication = (AbstractAuthenticationToken) authenticationManager.authenticate(authentication); } catch (ProviderNotFoundException e) { logger.warn("No authentication provider available for principal: '{}'", authentication.getPrincipal()); authentication.setDetails(NO_PROVIDER); return authentication; } catch (BadCredentialsException | IllegalArgumentException e) { logger.warn("Unable to authenticate for principal: '{}'", authentication.getPrincipal()); authentication.setDetails(BAD_CREDENTIALS); return authentication; } catch (UsernameNotFoundException e) { logger.warn("Unable to authenticate for principal: '{}'", e.getMessage()); authentication.setDetails(UNKNOWN_PRINCIPAL); return authentication; } catch (DisabledException e) { logger.warn("Principal is disabled: '{}'", authentication.getPrincipal()); authentication.setDetails(DISABLED_PRINCIPAL); return authentication; } authentication.setDetails(AUTHENTICATED); return authentication; }
From source file:com.katsu.springframework.security.authentication.HtmlAuthenticationProvider.java
private Collection<? extends GrantedAuthority> doLogin(AbstractAuthenticationToken upat) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = null;/*from w w w .j a va 2s . c o m*/ HttpResponse httpResponse = null; HttpEntity entity = null; try { // httpclient.getCredentialsProvider().setCredentials( // new AuthScope(AuthScope.ANY), // new UsernamePasswordCredentials(upat.getPrincipal().toString(), upat.getCredentials().toString())); httpget = new HttpGet(url.toURI().toASCIIString()); httpget.setHeader("Authorization", getAuthString(upat.getPrincipal().toString(), upat.getCredentials().toString())); httpResponse = httpclient.execute(httpget); entity = httpResponse.getEntity(); if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { logger.trace(httpResponse.getStatusLine().toString()); String body = new java.util.Scanner(new InputStreamReader(entity.getContent())).useDelimiter("\\A") .next(); List<? extends GrantedAuthority> roles = json.deserialize(body, new TypeToken<List<Role>>() { }.getType()); if (roles != null && roles.size() > 0 && roles.get(0).getAuthority() == null) { roles = json.deserialize(body, new TypeToken<List<Role1>>() { }.getType()); } return roles; } else { throw new Exception(httpResponse.getStatusLine().getStatusCode() + " Http code response."); } } catch (Exception e) { if (entity != null) { logger.error(log(entity.getContent()), e); } else { logger.error(e); } throw e; } finally { httpclient.getConnectionManager().shutdown(); } }