use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method authorizedGroups.
@Override
public void authorizedGroups(String authenticatedUser, PersistableUser user) {
Validate.notNull(authenticatedUser, "Required authenticated user");
Validate.notNull(user, "Required persistable user");
try {
User currentUser = userService.getByUserName(authenticatedUser);
boolean isSuperAdmin = false;
for (Group g : currentUser.getGroups()) {
if (g.getGroupName().equals("SUPERADMIN")) {
isSuperAdmin = true;
break;
}
}
for (PersistableGroup g : user.getGroups()) {
if (g.getName().equals("SUPERADMIN")) {
if (!isSuperAdmin) {
throw new UnauthorizedException("Superadmin group not allowed");
}
}
}
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while looking for authorization", e);
}
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method listByCriteria.
@Override
public ReadableUserList listByCriteria(UserCriteria criteria, int page, int count, Language language) {
try {
ReadableUserList readableUserList = new ReadableUserList();
// filtering by userName is not in this implementation
Page<User> userList = null;
Optional<String> storeCode = Optional.ofNullable(criteria.getStoreCode());
if (storeCode.isPresent()) {
// get store
MerchantStore store = merchantStoreService.getByCode(storeCode.get());
if (store != null && (store.isRetailer() != null)) {
if (store.isRetailer().booleanValue()) {
// get group stores
List<MerchantStore> stores = merchantStoreService.findAllStoreNames(store.getCode());
List<Integer> intList = stores.stream().map(s -> s.getId()).collect(Collectors.toList());
criteria.setStoreIds(intList);
// search over store list
criteria.setStoreCode(null);
}
}
}
userList = userService.listByCriteria(criteria, page, count);
List<ReadableUser> readableUsers = new ArrayList<ReadableUser>();
if (userList != null) {
readableUsers = userList.getContent().stream().map(user -> convertUserToReadableUser(language, user)).collect(Collectors.toList());
readableUserList.setRecordsTotal(userList.getTotalElements());
readableUserList.setTotalPages(userList.getTotalPages());
readableUserList.setNumber(userList.getSize());
readableUserList.setRecordsFiltered(userList.getSize());
}
readableUserList.setData(readableUsers);
return readableUserList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot get users by criteria user", e);
}
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class SecurityGroupsBuilder method addGroup.
public SecurityGroupsBuilder addGroup(String name, GroupType type) {
Group g = new Group();
g.setGroupName(name);
g.setGroupType(type);
groups.add(g);
this.lastGroup = g;
return this;
}
use of com.salesmanager.core.model.user.Group in project shopizer by shopizer-ecommerce.
the class SecurityGroupsBuilder method addPermission.
public SecurityGroupsBuilder addPermission(Permission permission) {
if (this.lastGroup == null) {
Group g = this.groups.get(0);
if (g == null) {
g = new Group();
g.setGroupName("UNDEFINED");
g.setGroupType(GroupType.ADMIN);
groups.add(g);
this.lastGroup = g;
}
}
lastGroup.getPermissions().add(permission);
return this;
}
use of com.salesmanager.core.model.user.Group 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);
}
Aggregations