List of usage examples for org.springframework.security.core.userdetails User User
public User(String username, String password, Collection<? extends GrantedAuthority> authorities)
From source file:org.zalando.example.zauth.services.AccountConnectionSignupService.java
@Override public String execute(final Connection<?> connection) { Object api = connection.getApi(); // use the api if you can if (api instanceof ZAuth) { ZAuth zAuth = (ZAuth) api;// ww w. j a v a2 s.co m String login = zAuth.getCurrentLogin(); } // or use more generic org.springframework.social.connect.UserProfile profile = connection.fetchUserProfile(); String username = profile.getUsername(); LOG.info("Created user with id: " + username); User user = new User(username, "", Collections.emptyList()); userDetailsManager.createUser(user); return username; }
From source file:org.starfishrespect.myconsumption.server.business.security.AuthConfig.java
@Bean UserDetailsService userDetailsService() { return new UserDetailsService() { @Override/* w w w. j a v a 2 s . com*/ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { org.starfishrespect.myconsumption.server.business.entities.User account = mUserRepository .getUser(username); if (account != null) { List<GrantedAuthority> auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"); return new User(account.getName(), account.getPassword(), auth); } else { throw new UsernameNotFoundException("could not find the user '" + username + "'"); } } }; }
From source file:io.pivotal.auth.samlwrapper.userannotation.CurrentUserHandlerMethodArgumentResolver.java
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { if (!supportsParameter(methodParameter)) { return WebArgumentResolver.UNRESOLVED; }// w w w . j av a2 s.c o m Principal principal = webRequest.getUserPrincipal(); if (principal == null) { return new User("Unauthenticated", "", Collections.emptyList()); } Object user = ((Authentication) principal).getPrincipal(); if (user instanceof User) { // also prevents null return return user; } return WebArgumentResolver.UNRESOLVED; }
From source file:edu.vt.middleware.cas.userdetails.LdapUserDetailsServiceTest.java
private User parseUserDetails(final String s) { final String[] userRoles = s.split(":"); final String[] roles = userRoles[1].split("\\|"); final Collection<SimpleGrantedAuthority> roleAuthorities = new ArrayList<SimpleGrantedAuthority>( roles.length);//from w w w . jav a 2s.c om for (String role : roles) { roleAuthorities.add(new SimpleGrantedAuthority(role)); } return new User(userRoles[0], LdapUserDetailsService.UNKNOWN_PASSWORD, roleAuthorities); }
From source file:com.mastercard.test.spring.security.SpringTestApplicationWith2UserDetailsServiceBeans.java
/** * Provide an instance of UserDetailsService to help test @WithUserDetails. * @return The instance of UserDetailsService. *///from w ww.j av a 2 s . c o m @Bean public UserDetailsService getUserDetailsService2() { return new UserDetailsService() { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return new User(username, "password", new ArrayList<>()); } }; }
From source file:org.apigw.authserver.svc.encrypted.EncryptedAuthorizationCodeServices.java
@Override public String createAuthorizationCode(AuthorizationRequestHolder authentication) { log.debug("createAuthorizationCode"); UserDetails userDetails = (UserDetails) authentication.getUserAuthentication().getPrincipal(); String encryptedUsername = encrypter.encrypt(userDetails.getUsername()); User secureUser = new User(encryptedUsername, "", Collections.singletonList(new SimpleGrantedAuthority("ROLE_USER"))); SimpleAuthentication auth = new SimpleAuthentication(secureUser); AuthorizationRequestHolder secureAuth = new AuthorizationRequestHolder( authentication.getAuthenticationRequest(), auth); return getAuthorizationCodeServices().createAuthorizationCode(secureAuth); }
From source file:sequrity.LoginService.java
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Korisnik user = null;/* ww w . j a va2s . com*/ try { //username je email u ovom slucaju user = loadUserByEmail(username); } catch (Exception ex) { Logger.getLogger(LoginService.class.getName()).log(Level.SEVERE, null, ex); } if (user == null) throw new UsernameNotFoundException("Ne postoji registrovani korisnik sa email adresom " + username); List<SimpleGrantedAuthority> authorities; if (user instanceof Student) authorities = Arrays.asList(new SimpleGrantedAuthority(ROLE_STUDENT)); else authorities = Arrays.asList(new SimpleGrantedAuthority(ROLE_PROFESOR)); return new User(username, user.getPassword(), authorities); }
From source file:eu.trentorise.smartcampus.permissionprovider.oauth.InternalUserDetailsRepo.java
@Override public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException { List<GrantedAuthority> list = Collections .<GrantedAuthority>singletonList(new SimpleGrantedAuthority("ROLE_USER")); Registration reg = userRepository.findByEmail(userName); if (reg == null) throw new UsernameNotFoundException("User " + userName + " not found"); if (!reg.isConfirmed()) throw new UsernameNotFoundException("Registration not confirmed"); return new User(reg.getUserId().toString(), reg.getPassword(), list); }
From source file:com.sapito.config.UserDetailsServer.java
private User buildUserForAuthentication(Credencial credencial, List<GrantedAuthority> authorities, String nombre) {/*from ww w. j a va 2s .c o m*/ User user = new User(credencial.getUsuario(), credencial.getContrasena(), authorities); return user; }
From source file:com.create.security.core.userdetails.RepositoryUserDetailsService.java
@Override public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException { final Person person = personRepository.findByLogin(username); if (person == null) { throw new UsernameNotFoundException(String.format("User does not exists : %s", username)); }//ww w . j a va 2 s .c om return new User(username, "password", getGrantedAuthorities(person)); }