List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:com.xavin.config.security.JWTLoginFilter.java
@Override protected void successfulAuthentication(HttpServletRequest req, HttpServletResponse res, FilterChain chain, Authentication auth) throws IOException, ServletException { TokenAuthenticationService.addAuthentication(res, auth.getName()); }
From source file:com.himanshu.poc.h2.springboot.AuthenticationProviderImpl.java
@Override public Authentication authenticate(Authentication arg0) throws AuthenticationException { System.out.println(" User name is : " + arg0.getName()); //arg0.setAuthenticated(false); //return arg0; if (dummyUsernamePwdMap.get(arg0.getPrincipal()) != null && dummyUsernamePwdMap.get(arg0.getPrincipal()).equals(arg0.getCredentials())) { System.out.println("Auth success"); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(arg0.getPrincipal(), arg0.getCredentials(), arg0.getAuthorities()); return token; }/*from w w w . j av a 2s .co m*/ System.out.println("Auth failed"); return null; }
From source file:tomekkup.helenos.security.web.authentication.JsonAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { logger.debug(String.format("user '%s' logged in successfully", authentication.getName())); writeResult(response, authentication); }
From source file:com.web.mavenproject6.config.CustomAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final String name = authentication.getName(); final String password = authentication.getCredentials().toString(); System.err.println("!!!!Password " + password); for (Users u : userServiceImp.list()) { if (u.getUsername().equals(name) && u.getPassword().equals(password)) { final List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>(); grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER")); final UserDetails principal = new User(name, password, grantedAuths); final Authentication auth = new UsernamePasswordAuthenticationToken(principal, password, grantedAuths);/*from ww w . j a v a 2s .com*/ return auth; } } return null; }
From source file:com.seyren.core.security.mongo.MongoAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { User user = userStore.getUser(authentication.getName()); if (user == null) { throw new AuthenticationCredentialsNotFoundException("User does not exist"); }/*w w w . ja va 2 s . c o m*/ String password = authentication.getCredentials().toString(); if (passwordEncoder.matches(password, user.getPassword())) { return new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword(), user.getAuthorities()); } else { throw new BadCredentialsException("Bad Credentials"); } }
From source file:com.gisnet.cancelacion.web.controller.AutenticarUsuario.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); String password = authentication.getCredentials().toString(); FindResponse<UsuarioInfo> find = service.findByUsername(username); UsuarioInfo usuario = find.getInfo(); if (usuario != null) { if (service.loguear(new FindByRequest(username, password))) { List<GrantedAuthority> grants = new ArrayList<>(); for (String rol : usuario.getRoles()) { grants.add(new SimpleGrantedAuthority(rol)); }/* w ww . j a v a2 s . c o m*/ return new UsernamePasswordAuthenticationToken(username, password, grants); } throw new AuthenticationServiceException("Autenticacion fallida"); } throw new UsernameNotFoundException("Usuario no encontrado."); }
From source file:io.gravitee.management.security.listener.AuthenticationSuccessListener.java
@Override public void onApplicationEvent(AuthenticationSuccessEvent event) { final Authentication authentication = event.getAuthentication(); try {// w w w . ja v a 2 s.c o m userService.findByName(authentication.getName()); } catch (UserNotFoundException unfe) { final NewUserEntity newUser = new NewUserEntity(); newUser.setUsername(authentication.getName()); final Set<String> roles = authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority) .collect(Collectors.toSet()); newUser.setRoles(roles); userService.create(newUser); } }
From source file:com.launchkey.example.springmvc.LaunchKeyAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); try {// w w w . j av a 2 s. c om 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:org.socialsignin.exfmproxy.mvc.auth.ExFmUserPasswordService.java
private String getAuthenticatedUserName() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication == null || authentication.getName().equals("anonymousUser") ? null : authentication.getName();/*from w w w. j av a2 s . c o m*/ }
From source file:org.socialsignin.exfmproxy.mvc.workaround.auth.WorkaroundExFmUserPasswordService.java
public String getAuthenticatedUserPassword() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication == null || authentication.getName().equals("anonymousUser") ? null : ((String) ((User) authentication.getPrincipal()).getPassword()); }