Java Code Examples for org.springframework.security.authentication.UsernamePasswordAuthenticationToken#isAuthenticated()
The following examples show how to use
org.springframework.security.authentication.UsernamePasswordAuthenticationToken#isAuthenticated() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecurityServiceImpl.java From yugastore-java with Apache License 2.0 | 5 votes |
@Override public void autoLogin(String username, String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); } }
Example 2
Source File: SecurityServiceImpl.java From hellokoding-courses with MIT License | 5 votes |
@Override public void autoLogin(String username, String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); } }
Example 3
Source File: SecurityServiceImpl.java From hellokoding-courses with MIT License | 5 votes |
@Override public void autologin(String username, String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); } }
Example 4
Source File: SignUpController.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public String signUpUser(){ boolean registered = false; try { registered = userService.createUser(username, password); } catch (Exception e){ //nothing to do } if(registered){ UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(token); if (token.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(token); } return "/index.jsf?faces-redirect=true"; } else { return "/signup.jsf?faces-redirect=true&error=true"; } }
Example 5
Source File: SignUpController.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public String signUpUser(){ boolean registered = false; try { registered = userService.createUser(username, password); }catch (Exception e){ //nothing to do } if(registered){ UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(token); if (token.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(token); } return "/index.jsf?faces-redirect=true"; } else { return "/signup.jsf?faces-redirect=true&error=true"; } }
Example 6
Source File: SignUpController.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public String signUpUser(){ boolean registered = false; try { registered = userService.createUser(username, password); } catch (Exception e){ //nothing to do } if(registered){ UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(token); if (token.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(token); } return "/index.jsf?faces-redirect=true"; } else { return "/signup.jsf?faces-redirect=true&error=true"; } }
Example 7
Source File: SecurityServiceImpl.java From registration-login-spring-xml-maven-jsp-mysql with MIT License | 5 votes |
@Override public void autologin(String username, String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); } }
Example 8
Source File: SignUpController.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public String signUpUser(){ boolean registered = false; try { registered = userService.createUser(username, password); } catch (Exception e){ //nothing to do } if(registered){ UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(token); if (token.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(token); } return "/index.jsf?faces-redirect=true"; } else { return "/signup.jsf?faces-redirect=true&error=true"; } }
Example 9
Source File: SignUpController.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public String signUpUser(){ boolean registered = false; try { registered = userService.createUser(username, password); }catch (Exception e){ //nothing to do } if(registered){ UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(token); if (token.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(token); } return "/index.jsf?faces-redirect=true"; } else { return "/signup.jsf?faces-redirect=true&error=true"; } }
Example 10
Source File: SignUpController.java From testing_security_development_enterprise_systems with GNU Lesser General Public License v3.0 | 5 votes |
public String signUpUser(){ boolean registered = false; try { registered = userService.createUser(username, password); } catch (Exception e){ //nothing to do } if(registered){ UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(token); if (token.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(token); } return "/index.jsf?faces-redirect=true"; } else { return "/signup.jsf?faces-redirect=true&error=true"; } }
Example 11
Source File: SecurityServiceImpl.java From registration-login-spring-hsql with MIT License | 5 votes |
@Override public void autologin(String username, String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); } }
Example 12
Source File: SecurityServiceImpl.java From registration-login-spring-xml-maven-jsp-mysql with MIT License | 5 votes |
@Override public void autologin(String username, String password) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities()); authenticationManager.authenticate(usernamePasswordAuthenticationToken); if (usernamePasswordAuthenticationToken.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); logger.debug(String.format("Auto login %s successfully!", username)); } }
Example 13
Source File: JwtSsoBasedAuthenticationFilter.java From wecube-platform with Apache License 2.0 | 4 votes |
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { if (log.isDebugEnabled()) { log.debug("=== doFilterInternal ==="); } SecurityContextHolder.clearContext(); String header = request.getHeader(JwtSsoClientContext.HEADER_AUTHORIZATION); if (header == null || !header.startsWith(JwtSsoClientContext.PREFIX_BEARER_TOKEN)) { log.debug("bearer token does not exist"); chain.doFilter(request, response); return; } if (log.isDebugEnabled()) { log.debug("start to authenticate with bearer token"); } try { UsernamePasswordAuthenticationToken authentication = getAuthentication(request); if (authentication != null && authentication.isAuthenticated()) { SecurityContextHolder.getContext().setAuthentication(authentication); } } catch (AuthenticationException failed) { log.debug("authentication failed"); SecurityContextHolder.clearContext(); onUnsuccessfulAuthentication(request, response, failed); if (this.ignoreFailure) { chain.doFilter(request, response); } else { this.getAuthenticationEntryPoint().commence(request, response, failed); } return; } executeFilter(request, response, chain); }