use of com.salesmanager.core.model.user.Permission in project shopizer by shopizer-ecommerce.
the class SecurityGroupsBuilder method addPermission.
public SecurityGroupsBuilder addPermission(String name) {
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;
}
}
Permission permission = new Permission();
permission.setPermissionName(name);
lastGroup.getPermissions().add(permission);
return this;
}
use of com.salesmanager.core.model.user.Permission in project shopizer by shopizer-ecommerce.
the class UserServicesImpl method loadUserByUsername.
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
com.salesmanager.core.model.user.User user = null;
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
try {
user = userService.getByUserName(userName);
if (user == null) {
return null;
}
// 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());
}
List<Permission> permissions = permissionService.getPermissions(groupsId);
for (Permission permission : permissions) {
GrantedAuthority auth = new SimpleGrantedAuthority(ROLE_PREFIX + permission.getPermissionName());
authorities.add(auth);
}
} catch (Exception e) {
LOGGER.error("Exception while querrying user", e);
throw new SecurityDataAccessException("Exception while querrying user", e);
}
User secUser = new User(userName, user.getAdminPassword(), user.isActive(), true, true, true, authorities);
return secUser;
}
use of com.salesmanager.core.model.user.Permission in project shopizer by shopizer-ecommerce.
the class AbstractCustomerServices method loadUserByUsername.
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
Customer user = null;
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
try {
LOGGER.debug("Loading user by user id: {}", userName);
user = customerService.getByNick(userName);
if (user == null) {
// return null;
throw new UsernameNotFoundException("User " + userName + " not found");
}
// required to login
GrantedAuthority role = new SimpleGrantedAuthority(ROLE_PREFIX + Constants.PERMISSION_CUSTOMER_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);
}
use of com.salesmanager.core.model.user.Permission in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method authenticate.
public void authenticate(Customer customer, String userName, String password) throws Exception {
Validate.notNull(customer, "Customer cannot be null");
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
GrantedAuthority role = // required
new SimpleGrantedAuthority(ROLE_PREFIX + Constants.PERMISSION_CUSTOMER_AUTHENTICATED);
// to
// login
authorities.add(role);
List<Integer> groupsId = new ArrayList<Integer>();
List<Group> groups = customer.getGroups();
if (groups != null) {
for (Group group : groups) {
groupsId.add(group.getId());
}
if (groupsId != null && groupsId.size() > 0) {
List<Permission> permissions = permissionService.getPermissions(groupsId);
for (Permission permission : permissions) {
GrantedAuthority auth = new SimpleGrantedAuthority(permission.getPermissionName());
authorities.add(auth);
}
}
}
Authentication authenticationToken = new UsernamePasswordAuthenticationToken(userName, password, authorities);
Authentication authentication = customerAuthenticationManager.authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
use of com.salesmanager.core.model.user.Permission in project shopizer by shopizer-ecommerce.
the class SecurityApi method permissions.
/**
* Permissions Requires service user authentication
*
* @return
*/
@GetMapping("/private/permissions")
public List<ReadablePermission> permissions() {
List<Permission> permissions = permissionService.list();
List<ReadablePermission> readablePermissions = new ArrayList<ReadablePermission>();
for (Permission permission : permissions) {
ReadablePermission readablePermission = new ReadablePermission();
readablePermission.setName(permission.getPermissionName());
readablePermission.setId(permission.getId());
readablePermissions.add(readablePermission);
}
return readablePermissions;
}
Aggregations