List of usage examples for org.springframework.security.authentication AbstractAuthenticationToken getName
public String getName()
From source file:com.katsu.springframework.security.authentication.dni.DniAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { AbstractAuthenticationToken auth = (AbstractAuthenticationToken) authentication; UserDetails result = dniAuthenticationDao.getUserByDNI(auth.getName()); if (result != null) { return createSuccessAuthentication(auth, result, result.getAuthorities()); }//from w ww .ja v a2 s . co m return null; }
From source file:org.xaloon.wicket.security.spring.SpringSecurityFacade.java
private AuthenticationToken authenticateInternal(AbstractAuthenticationToken authenticationRequestToken) { boolean authenticated = false; String name = authenticationRequestToken.getName(); String errorMessage = null;/*from w w w. j a va 2 s . c o m*/ try { Authentication authentication = authenticationManager.authenticate(authenticationRequestToken); authenticated = authentication.isAuthenticated(); if (authenticated && authentication.getDetails() == null) { // Try to load user details. Copy information into new token UsernamePasswordAuthenticationToken authenticationWithDetails = new UsernamePasswordAuthenticationToken( authentication.getPrincipal(), authentication.getCredentials(), authentication.getAuthorities()); authenticationWithDetails.setDetails(userDao.getUserByUsername(authentication.getName())); authentication = authenticationWithDetails; } SecurityContextHolder.getContext().setAuthentication(authentication); name = authentication.getName(); } catch (AuthenticationException e) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("User " + name + " failed to login. Reason: ", e); } authenticated = false; errorMessage = e.getMessage(); } if (authenticated) { return new AuthenticationToken(name, new ArrayList<AuthenticationAttribute>()); } return new AuthenticationToken(name, errorMessage); }
From source file:pt.webdetails.cda.push.CdaPushQueryMessageHandler.java
/** * This method executes the query sent by the client of this websocket. * * @param query The query to be executed, and sent over the websocket. *///from w w w.ja v a 2 s . c o m @Override public void onMessage(String query) { try { PentahoRequestContextHolder.setRequestContext(requestContext); AbstractAuthenticationToken principal = (AbstractAuthenticationToken) session.getUserPrincipal(); if (principal.isAuthenticated()) { IPentahoSession pentahoSession = new StandaloneSession(principal.getName()); PentahoSessionHolder.setSession(pentahoSession); SecurityHelper.getInstance().becomeUser(principal.getName()); } this.websocketJsonQueryEndpoint.onMessage(query, outboundMessage -> { try { if (session.isOpen()) { session.getBasicRemote().sendText(outboundMessage); } } catch (Exception e) { logger.error("Error sending message. Closing websocket...", e); try { session.close(); } catch (IOException ioException) { logger.error("Error writing to websocket", ioException); } } }); } catch (Exception e) { logger.error("Error processing message. Closing websocket...", e); try { session.close(); } catch (IOException ioException) { logger.error("Error writing to websocket", ioException); } } }