Search in sources :

Example 1 with RolePrivilegeEntity

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);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) RolePrivilegeEntity(org.codenergic.theskeleton.role.RolePrivilegeEntity)

Example 2 with RolePrivilegeEntity

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);
}
Also used : RolePrivilegeEntity(org.codenergic.theskeleton.role.RolePrivilegeEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RolePrivilegeEntity

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();
}
Also used : RoleEntity(org.codenergic.theskeleton.role.RoleEntity) RolePrivilegeEntity(org.codenergic.theskeleton.role.RolePrivilegeEntity) RolePrivilegeEntity(org.codenergic.theskeleton.role.RolePrivilegeEntity) PrivilegeEntity(org.codenergic.theskeleton.privilege.PrivilegeEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RolePrivilegeEntity (org.codenergic.theskeleton.role.RolePrivilegeEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)2 PrivilegeEntity (org.codenergic.theskeleton.privilege.PrivilegeEntity)1 RoleEntity (org.codenergic.theskeleton.role.RoleEntity)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1