Java 类org.springframework.security.core.userdetails.UsernameNotFoundException 实例源码

项目:REST-Web-Services    文件:UserDetailsServiceImpl.java   
/**
 * Get user by username. Login process.
 *
 * @param username The user's name
 * @return UserDetails object
 * @throws UsernameNotFoundException No user found
 */
@Override
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {
    log.info("Called with username {}", username);

    Optional<UserEntity> userOptional = userRepository.findByUsernameIgnoreCaseAndEnabledTrue(username);

    userOptional.orElseThrow(() -> new UsernameNotFoundException("No user found with username " + username));

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for(SecurityRole role : userOptional.get().getAuthorities()) {
        grantedAuthorities.add(new SimpleGrantedAuthority(role.toString()));
    }

    return new org.springframework.security.core.userdetails.User(userOptional.get().getUsername(),
                                                                  userOptional.get().getPassword(),
                                                                  grantedAuthorities);
}
项目:SoftUni    文件:ListUserDetailsService.java   
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException{
    User user = userRepository.findByEmail(email);

    if(user == null) {
        throw new UsernameNotFoundException("Invalid User");
    }
    else {
        Set<GrantedAuthority> grantedAuthorities = user.getRoles()
                .stream()
                .map(role -> new SimpleGrantedAuthority(role.getName()))
                .collect(Collectors.toSet());

        return new org
                .springframework
                .security
                .core
                .userdetails
                .User(user.getEmail(), user.getPassword(), grantedAuthorities);
    }
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:EventSoft    文件:UserDetail.java   
@Override
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
    try {
        Usuario u = new SAUsuarioImp().buscarUsuarioByEmail(email);

        ArrayList<SimpleGrantedAuthority> roles = new ArrayList<>();
        for (String rol : u.getRoles().split("[,]")) {
            roles.add(new SimpleGrantedAuthority("ROLE_" + rol));
        }

        return new org.springframework.security.core.userdetails.User(
                u.getEmail(), u.getPassword(), roles);
    } catch (Exception e) {
        //log.error(e.getMessage());
        //e.printStackTrace();
        throw new UsernameNotFoundException("Usuario con email: " + email + " no encontrado.");
    }
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:CalendarUserAuthenticationProvider.java   
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
    String email = token.getName();
    CalendarUser user = email == null ? null : calendarService.findUserByEmail(email);
    if(user == null) {
        throw new UsernameNotFoundException("Invalid username/password");
    }
    // Database Password already encrypted:
    String password = user.getPassword();

    boolean passwordsMatch = passwordEncoder.matches(token.getCredentials().toString(), password);

    if(!passwordsMatch) {
        throw new BadCredentialsException("Invalid username/password");
    }
    Collection<? extends GrantedAuthority> authorities = CalendarUserAuthorityUtils.createAuthorities(user);
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user, password, authorities);
    return usernamePasswordAuthenticationToken;
}
项目:Spring-Security-Third-Edition    文件:CalendarUserAuthenticationProvider.java   
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
    String email = token.getName();
    CalendarUser user = email == null ? null : calendarService.findUserByEmail(email);
    if(user == null) {
        throw new UsernameNotFoundException("Invalid username/password");
    }
    // Database Password already encrypted:
    String password = user.getPassword();

    boolean passwordsMatch = passwordEncoder.matches(token.getCredentials().toString(), password);

    if(!passwordsMatch) {
        throw new BadCredentialsException("Invalid username/password");
    }
    Collection<? extends GrantedAuthority> authorities = CalendarUserAuthorityUtils.createAuthorities(user);
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user, password, authorities);
    return usernamePasswordAuthenticationToken;
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:cas-security-spring-boot-starter    文件:GrantedAuthoritiesFromAssertionAttributesWithDefaultRolesUserDetailsService.java   
protected UserDetails loadUserDetails(Assertion assertion) {
    String username = assertion.getPrincipal().getName();
    if (!StringUtils.hasText(username)) {
        throw new UsernameNotFoundException("Unable to retrieve username from CAS assertion");
    }

    List<GrantedAuthority> authorities = Arrays
            .stream(attributes)
            .map(a -> assertion.getPrincipal().getAttributes().get(a))
            .filter(Objects::nonNull)
            .flatMap(v -> (v instanceof Collection) ? ((Collection<?>) v).stream() : Stream.of(v))
            .map(v -> toUppercase ? v.toString().toUpperCase() : v.toString())
            .map(r -> r.replaceFirst("^ROLE_", ""))
            .map(r -> new SimpleGrantedAuthority("ROLE_" + r))
            .collect(Collectors.toList());

    authorities.addAll(defaultGrantedAuthorities);

    return new User(username, NON_EXISTENT_PASSWORD_VALUE, authorities);
}
项目:FCat    文件:GateUserDetailsService.java   
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    if (StringUtils.isBlank(username)) {
        throw new UsernameNotFoundException("用户名为空");
    }
    String password;
    TUser tUser = iUserService.getByUsername(username);
    if(tUser==null){
        throw new UsernameNotFoundException("登录账号不存在");
    }else{
        password=tUser.getPassword();
    }

    Set<GrantedAuthority> authorities = new HashSet<>();
    authorities.add(new SimpleGrantedAuthority("USER"));
    return new org.springframework.security.core.userdetails.User(
            username, password,
            true,
            true,
            true,
            true,
            authorities);
}
项目:Nasapi    文件:AuthenticationAdapter.java   
@Bean
    UserDetailsService userDetailsService() {
        return new UserDetailsService() {

            @Override
            public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
                AuthenticationResponse response = scriptEngineHolder.authenticate(username);
                if (response != null) {
                    return response.getUser();
                } else {
                    throw new UsernameNotFoundException("No such user '" + username + "'");
                }
/*
                //Account account = accountRepository.findByUsername(username);
//              if(account != null) {
                    return new User(username, "admin", true, true, true, true,
                            AuthorityUtils.createAuthorityList("USER"));
//              } else {
//                  throw new UsernameNotFoundException("could not find the user '" + username + "'");
//              }
*/
            }

        };
    }
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:shoucang    文件:UserDetailsService.java   
@Override
@Transactional
public UserDetails loadUserByUsername(final String login) {
    log.debug("Authenticating {}", login);
    String lowercaseLogin = login.toLowerCase();
    Optional<User> userFromDatabase = userRepository.findOneByLoginOrEmail(lowercaseLogin, lowercaseLogin);
    return userFromDatabase.map(user -> {
        if (!user.getActivated()) {
            throw new UserNotActivatedException("User " + lowercaseLogin + " was not activated");
        }
        List<GrantedAuthority> grantedAuthorities = user.getAuthorities().stream()
                .map(authority -> new SimpleGrantedAuthority(authority.getName()))
            .collect(Collectors.toList());
        return new org.springframework.security.core.userdetails.User(lowercaseLogin,
            user.getPassword(),
            grantedAuthorities);
    }).orElseThrow(() -> new UsernameNotFoundException("User " + lowercaseLogin + " was not found in the " +
    "database"));
}
项目:Spring-Security-Third-Edition    文件:CalendarUserAuthenticationProvider.java   
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
    String email = token.getName();
    CalendarUser user = email == null ? null : calendarService.findUserByEmail(email);
    if(user == null) {
        throw new UsernameNotFoundException("Invalid username/password");
    }
    // Database Password already encrypted:
    String password = user.getPassword();

    boolean passwordsMatch = passwordEncoder.matches(token.getCredentials().toString(), password);

    if(!passwordsMatch) {
        throw new BadCredentialsException("Invalid username/password");
    }
    Collection<? extends GrantedAuthority> authorities = CalendarUserAuthorityUtils.createAuthorities(user);
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user, password, authorities);
    return usernamePasswordAuthenticationToken;
}
项目:tokamak    文件:ClientAuthenticationServiceImpl.java   
public ClientDetails loadClientByClientId(String id) throws ClientRegistrationException {
    if (CurrentAuthenticatedClientContext.hasAuthenticatedClient()) {
        AuthenticatedClient client = CurrentAuthenticatedClientContext.getAuthenticatedClient();
        if (client.getClientId().equals(id)) {
            return CurrentAuthenticatedClientContext.getAuthenticatedClient();
        }
        CurrentAuthenticatedClientContext.clear();
    }

    Result<Client> result = clientService.findByClientId(id);
    if (result.rejected()) {
        CurrentAuthenticatedClientContext.clear();
        throw new UsernameNotFoundException("Could not find client with client id " + id);
    }

    return CurrentAuthenticatedClientContext.setAuthenticatedClient(new AuthenticatedClient(result.getInstance()));
}
项目:Spring-Security-Third-Edition    文件:CalendarUserAuthenticationProvider.java   
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
    String email = token.getName();
    CalendarUser user = email == null ? null : calendarService.findUserByEmail(email);
    if(user == null) {
        throw new UsernameNotFoundException("Invalid username/password");
    }
    // Database Password already encrypted:
    String password = user.getPassword();

    boolean passwordsMatch = passwordEncoder.matches(token.getCredentials().toString(), password);

    if(!passwordsMatch) {
        throw new BadCredentialsException("Invalid username/password");
    }
    Collection<? extends GrantedAuthority> authorities = CalendarUserAuthorityUtils.createAuthorities(user);
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user, password, authorities);
    return usernamePasswordAuthenticationToken;
}
项目:Spring-Security-Third-Edition    文件:CalendarUserAuthenticationProvider.java   
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
    String email = token.getName();
    CalendarUser user = email == null ? null : calendarService.findUserByEmail(email);
    if(user == null) {
        throw new UsernameNotFoundException("Invalid username/password");
    }
    // Database Password already encrypted:
    String password = user.getPassword();

    boolean passwordsMatch = passwordEncoder.matches(token.getCredentials().toString(), password);

    if(!passwordsMatch) {
        throw new BadCredentialsException("Invalid username/password");
    }
    Collection<? extends GrantedAuthority> authorities = CalendarUserAuthorityUtils.createAuthorities(user);
    UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user, password, authorities);
    return usernamePasswordAuthenticationToken;
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:lemon    文件:DatabaseUserFetcher.java   
public Map<String, Object> fetchUserMap(String username,
        String userRepoRef, String tenantId) {
    String sqlUser = "select id,username,password,status,display_name from USER_BASE"
            + " where username=? and user_repo_id=?";

    try {
        Map<String, Object> userMap = null;

        userMap = jdbcTemplate.queryForMap(sqlUser, username, userRepoRef);

        return userMap;
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw new UsernameNotFoundException(username, ex);
    }
}
项目:smarti    文件:MongoUserDetailsService.java   
@Override
public AttributedUserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
    login = login.toLowerCase(Locale.ROOT);

    final SmartiUser smartiUser = getSmaritUser(login);

    if (smartiUser == null) {
        log.debug("User {} not found", login);
        throw new UsernameNotFoundException(String.format("Unknown user: '%s'", login));
    }

    final MongoUserDetails userDetails = new MongoUserDetails(
            smartiUser.getLogin(),
            smartiUser.getPassword(),
            Collections2.transform(smartiUser.getRoles(),
                    role -> new SimpleGrantedAuthority("ROLE_" + StringUtils.upperCase(role, Locale.ROOT))
            )
    );
    userDetails.addAttributes(smartiUser.getProfile());
    return userDetails;
}
项目:Fetax-AI    文件:MainUserDetailServiceImpl.java   
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
    //System.err.println("-----------MyUserDetailServiceImpl loadUserByUsername ----------- ");
    //取得用户的权限
    Customer user = authService.findCustomer(userName);
    if  (user==null)  
           throw new UsernameNotFoundException(userName+" not exist!");  
    Collection<GrantedAuthority> grantedAuths = obtionGrantedAuthorities(user);
    // 封装成spring security的user
    User userdetail = new User(
            user.getName(), 
            user.getPassword(),
            true, 
            true, 
            true,
            true, 
            grantedAuths    //用户的权限
        );
    return userdetail;
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    if (user == null)
        throw new UsernameNotFoundException("username " + username
                + " not found");

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:lemon    文件:HttpUserFetcher.java   
public UserInfo getUserInfo(String username, String appId, String repoCode) {
    Map<String, Object> parameterMap = new HashMap<String, Object>();
    parameterMap.put("username", username);
    parameterMap.put("appId", appId);
    parameterMap.put("repoCode", repoCode);

    try {
        String content = httpHandler.readText(url, parameterMap);
        logger.info(content);

        JsonMapper jsonMapper = new JsonMapper();
        Map map = jsonMapper.fromJson(content, Map.class);
        logger.debug("{}", map);

        long userId = ((Number) map.get("userId")).longValue();

        List<String> authorities = (List<String>) map.get("authorities");
        List<String> attributes = (List<String>) map.get("attributes");

        UserInfoImpl userInfo = new UserInfoImpl();
        userInfo.setUsername(username);
        userInfo.setPassword((String) map.get("password"));
        userInfo.setAuthorities(authorities);
        userInfo.setAttributes(attributes);
        userInfo.getExtra().put("userId", userId);
        userInfo.getExtra().put("appId", appId);

        return userInfo;
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw new UsernameNotFoundException(username, ex);
    }
}
项目:forweaver2.0    文件:WeaverService.java   
public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException {
    // TODO Auto-generated method stub
    Weaver weaver = weaverDao.get(id);

    if(weaver == null || weaver.isLeave())
        return null;

    return weaver;
}
项目:nifi-registry    文件:KerberosUserDetailsService.java   
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    return new User(
            username,
            "notUsed",
            true,
            true,
            true,
            true,
            AuthorityUtils.createAuthorityList("ROLE_USER"));
}
项目:Spring-Security-Third-Edition    文件:UserDetailsServiceImpl.java   
@Override
@Transactional(readOnly = true)
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException {

    CalendarUser user = userRepository.findByEmail(username);

    Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
    for (Role role : user.getRoles()){
        grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
    }

    return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(), grantedAuthorities);
}
项目:rest-api-jwt-spring-security    文件:JwtUserDetailsServiceImpl.java   
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByUsername(username);

    if (user == null) {
        throw new UsernameNotFoundException(String.format("No user found with username '%s'.", username));
    } else {
        return JwtUserFactory.create(user);
    }
}
项目:Spring-Security-Third-Edition    文件:CalendarUserDetailsService.java   
/**
 * Lookup a {@link CalendarUser} by the username representing the email address. Then, convert the
 * {@link CalendarUser} into a {@link UserDetails} to conform to the {@link UserDetails} interface.
 */
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    CalendarUser user = calendarUserDao.findUserByEmail(username);
    if (user == null) {
        throw new UsernameNotFoundException("Invalid username/password.");
    }
    return new CalendarUserDetails(user);
}
项目:gamesboard    文件:SimpleSocialUserDetailsService.java   
/**
 * Loads the username by using the account ID of the user.
 * @param userId    The account ID of the requested user.
 * @return  The information of the requested user.
 * @throws UsernameNotFoundException    Thrown if no user is found.
 * @throws DataAccessException
 */
@Override
public SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException, DataAccessException {
    LOGGER.debug("Loading user by user id: {}", userId);

    UserDetails userDetails = userDetailsService.loadUserByUsername(userId);
    LOGGER.debug("Found user details: {}", userDetails);

    return (SocialUserDetails) userDetails;
}