use of org.codenergic.theskeleton.role.RolePrivilegeEntity in project theskeleton by codenergic.
the class UserServiceImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) {
UserEntity user = findUserByUsername(username);
if (user == null)
user = findUserByEmail(username);
if (user == null)
user = userRepository.findOne(username);
if (user == null)
throw new UsernameNotFoundException("Cannot find user with username or email of " + username);
Set<RolePrivilegeEntity> rolePrivileges = new HashSet<>();
user.getRoles().forEach(role -> rolePrivileges.addAll(rolePrivilegeRepository.findByRoleCode(role.getRole().getCode())));
return user.setAuthorities(rolePrivileges);
}
use of org.codenergic.theskeleton.role.RolePrivilegeEntity in project theskeleton by codenergic.
the class RoleServiceImpl method removePrivilegeFromRole.
@Override
@Transactional
public RoleEntity removePrivilegeFromRole(String code, String privilegeName) {
RolePrivilegeEntity userRole = rolePrivilegeRepository.findByRoleCodeAndPrivilegeName(code, privilegeName);
rolePrivilegeRepository.delete(userRole);
return findRoleByCode(code);
}
use of org.codenergic.theskeleton.role.RolePrivilegeEntity in project theskeleton by codenergic.
the class RoleServiceImpl method addPrivilegeToRole.
@Override
@Transactional
public RoleEntity addPrivilegeToRole(String code, String privilegeName) {
RoleEntity role = findRoleByCode(code);
PrivilegeEntity privilege = privilegeRepository.findByName(privilegeName);
return rolePrivilegeRepository.save(new RolePrivilegeEntity(role, privilege)).getRole();
}
Aggregations