Search in sources :

Example 21 with User

use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.

the class JWTAdminServicesImpl method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
    User user = null;
    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    try {
        LOGGER.debug("Loading user by user id: {}", userName);
        user = userService.getByUserName(userName);
        if (user == null) {
            // return null;
            throw new UsernameNotFoundException("User " + userName + " not found");
        }
        // required to login
        GrantedAuthority role = new SimpleGrantedAuthority(ROLE_PREFIX + Constants.PERMISSION_AUTHENTICATED);
        authorities.add(role);
        List<Integer> groupsId = new ArrayList<Integer>();
        List<Group> groups = user.getGroups();
        for (Group group : groups) {
            groupsId.add(group.getId());
        }
        if (CollectionUtils.isNotEmpty(groupsId)) {
            List<Permission> permissions = permissionService.getPermissions(groupsId);
            for (Permission permission : permissions) {
                GrantedAuthority auth = new SimpleGrantedAuthority(permission.getPermissionName());
                authorities.add(auth);
            }
        }
    } catch (ServiceException e) {
        LOGGER.error("Exception while querrying customer", e);
        throw new SecurityDataAccessException("Cannot authenticate customer", e);
    }
    return userDetails(userName, user, authorities);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Group(com.salesmanager.core.model.user.Group) User(com.salesmanager.core.model.user.User) JWTUser(com.salesmanager.shop.store.security.user.JWTUser) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SecurityDataAccessException(com.salesmanager.shop.admin.security.SecurityDataAccessException) ArrayList(java.util.ArrayList) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ServiceException(com.salesmanager.core.business.exception.ServiceException) Permission(com.salesmanager.core.model.user.Permission)

Aggregations

User (com.salesmanager.core.model.user.User)21 ServiceException (com.salesmanager.core.business.exception.ServiceException)16 PersistableUser (com.salesmanager.shop.model.user.PersistableUser)15 ReadableUser (com.salesmanager.shop.model.user.ReadableUser)14 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)13 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)7 Group (com.salesmanager.core.model.user.Group)6 ConversionException (com.salesmanager.core.business.exception.ConversionException)5 PersistableGroup (com.salesmanager.shop.model.security.PersistableGroup)5 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)5 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)5 ReadableGroup (com.salesmanager.shop.model.security.ReadableGroup)4 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)4 GenericRuntimeException (com.salesmanager.shop.store.api.exception.GenericRuntimeException)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 CredentialsReset (com.salesmanager.core.model.common.CredentialsReset)3 GenericEntityList (com.salesmanager.core.model.common.GenericEntityList)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 Language (com.salesmanager.core.model.reference.language.Language)3