List of usage examples for org.springframework.security.authentication UsernamePasswordAuthenticationToken UsernamePasswordAuthenticationToken
public UsernamePasswordAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities)
AuthenticationManager
or AuthenticationProvider
implementations that are satisfied with producing a trusted (i.e. From source file:com.lennonjesus.auth.security.provider.SecurityAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); if (name.equals("user") && password.equals("user")) { List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>(); grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER")); return new UsernamePasswordAuthenticationToken(name, password, grantedAuths); }/* www .j a v a 2 s . c o m*/ if (name.equals("admin") && password.equals("admin")) { List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>(); grantedAuths.add(new SimpleGrantedAuthority("ROLE_ADMIN")); return new UsernamePasswordAuthenticationToken(name, password, grantedAuths); } return null; }
From source file:opensnap.config.CustomHandshakeHandler.java
@Override protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) { Principal principal = request.getPrincipal(); if (principal == null) { principal = new UsernamePasswordAuthenticationToken("anonymous", "jdqsjkdjsqkjd", Arrays.asList(new SimpleGrantedAuthority("ANONYMOUS"))); }//from w w w . j a va2s . co m return principal; }
From source file:oobbit.security.JpaAuthenticationProvider.java
@Override public Authentication authenticate(Authentication a) throws AuthenticationException { String username = a.getPrincipal().toString(); String password = a.getCredentials().toString(); try {/*from w w w . j a v a 2 s. c o m*/ User user = users.attemptLogin(username, password); return new UsernamePasswordAuthenticationToken(user.getUsername(), password, accessLevelToGrantedAuthority.accessLevelToSimpleGrantedAuthorityList(user.getAccessLevel())); } catch (SQLException ex) { Logger.getLogger(JpaAuthenticationProvider.class.getName()).log(Level.SEVERE, "SQLException was thrown while authenticating a user in JpaAuthenticationProvider.", ex); } catch (FailedLoginException ex) { Logger.getLogger(JpaAuthenticationProvider.class.getName()).log(Level.SEVERE, "FailedLoginException was thrown while tyring to authenticate a user.", ex); } throw new AuthenticationException("Unable to authenticate user " + username) { }; }
From source file:com.trenako.security.SpringSecurityService.java
@Override public void authenticate(Account user) { AccountDetails userDetails = new AccountDetails(user); Authentication auth = new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities()); getSecContext().setAuthentication(auth); }
From source file:pt.webdetails.cpk.testUtils.PentahoSystemForTesting.java
public static <T> T runAsSystem(final Callable<T> callable) throws Exception { final String name = "system session"; //$NON-NLS-1$ IPentahoSession origSession = PentahoSessionHolder.getSession(); Authentication origAuth = SecurityContextHolder.getContext().getAuthentication(); try {/*from w w w . j av a2 s . c o m*/ // create pentaho session StandaloneSession session = new StandaloneSession(name); session.setAuthenticated(name); // create authentication GrantedAuthority[] roles; ISystemSettings settings = PentahoSystem.getSystemSettings(); String roleName = (settings != null) ? settings.getSystemSetting("acl-voter/admin-role", "Admin") : "Admin"; roles = new GrantedAuthority[1]; roles[0] = new SimpleGrantedAuthority(roleName); Authentication auth = new UsernamePasswordAuthenticationToken(name, "", Arrays.asList(roles)); //$NON-NLS-1$ // set holders PentahoSessionHolder.setSession(session); SecurityContextHolder.getContext().setAuthentication(auth); return callable.call(); } finally { IPentahoSession sessionToDestroy = PentahoSessionHolder.getSession(); if (sessionToDestroy != null) { try { sessionToDestroy.destroy(); } catch (Exception e) { e.printStackTrace(); } } PentahoSessionHolder.setSession(origSession); SecurityContextHolder.getContext().setAuthentication(origAuth); } }
From source file:com.tlantic.integration.authentication.service.security.UserAuthProviderService.java
private Authentication signInUser(User user, List<GrantedAuthority> roles) { UserDetails springSecurityUser = new org.springframework.security.core.userdetails.User(user.getEmail(), user.getId(), roles);//from w w w .j a v a 2s.com Authentication authentication = new UsernamePasswordAuthenticationToken(springSecurityUser, user.getId(), roles); SecurityContextHolder.getContext().setAuthentication(authentication); return authentication; }
From source file:com.mec.Security.CustomAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Authentication auth = null;//from w w w . jav a 2s.com final String name = authentication.getName(); final String password = authentication.getCredentials().toString(); if (name != null && password != null) { Usuario u = userDAO.getUser(name, password); if (u != null) { final UserDetails principal = new User(u.getId() + ";" + name, password, u.getRoles()); auth = new UsernamePasswordAuthenticationToken(principal, password, u.getRoles()); } } return auth; }
From source file:eu.gyza.eap.facebook.FacebookProfileController.java
@RequestMapping(value = "/facebook", method = RequestMethod.GET) public String home(Model model) { SecurityContextHolder.getContext()//from w w w.j a v a 2s . c o m .setAuthentication(new UsernamePasswordAuthenticationToken("deslos@yahoo.com", null, null)); Connection<Facebook> connection = connectionRepository.findPrimaryConnection(Facebook.class); if (connection == null) { return "redirect:/connect/facebook"; } model.addAttribute("profile", connection.getApi().userOperations().getUserProfile()); return "facebook/profile"; }
From source file:exanpe.t5.lib.demo.security.SameUserPasswordAP.java
public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); GrantedAuthorityImpl ga = new GrantedAuthorityImpl("ROLE_" + username); List<GrantedAuthority> l = new ArrayList<GrantedAuthority>(); l.add(ga);//from w w w.j a va 2 s . c om return new UsernamePasswordAuthenticationToken(new User(username, username, true, true, true, true, l), username, l); }
From source file:org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessorTests.java
@Test public void clientIsNotUser() throws Exception { SecurityContextHolder.getContext().setAuthentication( new UsernamePasswordAuthenticationToken("client", "secret", UaaAuthority.ADMIN_AUTHORITIES)); assertFalse(new DefaultSecurityContextAccessor().isUser()); }