Search in sources :

Example 1 with UserRoleDetails

use of com.epam.ta.reportportal.database.entity.UserRoleDetails in project service-authorization by reportportal.

the class DatabaseUserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    UserRoleDetails userEntity = userRepository.aggregateUserProjects(username.toLowerCase());
    if (null == userEntity || null == userEntity.getUser()) {
        throw new UsernameNotFoundException("Username '" + username + "' not found");
    }
    String login = userEntity.getUser().getLogin();
    String password = userEntity.getUser().getPassword() == null ? "" : userEntity.getUser().getPassword();
    org.springframework.security.core.userdetails.User u = new org.springframework.security.core.userdetails.User(login, password, true, true, true, true, AuthUtils.AS_AUTHORITIES.apply(userEntity.getUser().getRole()));
    return new ReportPortalUser(u, userEntity.getProjects().stream().collect(Collectors.toMap(UserRoleDetails.ProjectDetails::getProject, UserRoleDetails.ProjectDetails::getProjectRole)));
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) User(com.epam.ta.reportportal.database.entity.user.User) UserRoleDetails(com.epam.ta.reportportal.database.entity.UserRoleDetails)

Aggregations

UserRoleDetails (com.epam.ta.reportportal.database.entity.UserRoleDetails)1 User (com.epam.ta.reportportal.database.entity.user.User)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1