Commit 89814e7b authored by michael.simon's avatar michael.simon
Browse files

add Group in Roles func

parent 119eeb69
......@@ -45,5 +45,7 @@ public interface RoleDao extends BaseDao<RoleEntity, Long> {
RoleGroupEntity createNewRoleGroup();
RoleGroupEntity findRoleGroupEntity(GroupEntity group, RoleEntity role);
List<RoleEntity> findByGroups(List<Long> groups);
}
......@@ -81,6 +81,13 @@ public class JpaRoleDao extends JpaBaseDao<RoleEntity, Long> implements RoleDao
em.remove(roleEntity);
}
@SuppressWarnings("unchecked")
@Override
public List<RoleEntity> findByGroups(List<Long> groups) {
return em.createQuery("select r.role from RoleGroupEntity r where r.group.id in (:groups)")
.setParameter("groups", groups).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<RoleEntity> findByUser(UserEntity user) {
......
......@@ -32,5 +32,7 @@ public interface RoleService extends BaseService<RoleEntity, Long> {
Boolean checkUserInRole(Long userId, String roleName);
Boolean checkAdminUserInRole(Long userId, String roleName);
List<RoleEntity> findByGroups(List<Long> groups);
}
......@@ -49,6 +49,11 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleEntity, Long> implement
return dao.findByUser(user);
}
@Override
public List<RoleEntity> findByGroups(List<Long> groups) {
return dao.findByGroups(groups);
}
@Override
public List<RoleEntity> findByUserId(Long userId) {
return dao.findByUserId(userId);
......
......@@ -12,6 +12,7 @@ package edu.kit.scc.webreg.sec;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -84,13 +85,13 @@ public class AuthorizationBean implements Serializable {
return;
Long rolesTimeout;
if (appConfig.getConfigValue("AuthorizationBean_rolesTimeout") == null)
if (appConfig.getConfigValue("AuthorizationBean_rolesTimeout") != null)
rolesTimeout = Long.parseLong(appConfig.getConfigValue("AuthorizationBean_rolesTimeout"));
else
rolesTimeout = 1 * 60 * 1000L;
Long groupsTimeout;
if (appConfig.getConfigValue("AuthorizationBean_groupsTimeout") == null)
if (appConfig.getConfigValue("AuthorizationBean_groupsTimeout") != null)
groupsTimeout = Long.parseLong(appConfig.getConfigValue("AuthorizationBean_groupsTimeout"));
else
groupsTimeout = 1 * 60 * 1000L;
......@@ -107,6 +108,7 @@ public class AuthorizationBean implements Serializable {
start = System.currentTimeMillis();
Set<GroupEntity> groupList = groupService.findByUserWithParents(user);
sessionManager.clearGroupList();
sessionManager.setGroupString(groupsToString(groupList));
for (GroupEntity g : groupList) {
......@@ -161,10 +163,14 @@ public class AuthorizationBean implements Serializable {
if (sessionManager.getRoleSetCreated() == null ||
(System.currentTimeMillis() - sessionManager.getRoleSetCreated()) > rolesTimeout) {
start = System.currentTimeMillis();
List<RoleEntity> roleList = roleService.findByUser(user);
sessionManager.clearRoleList();
for (RoleEntity role : roleList) {
Set<RoleEntity> roles = new HashSet<RoleEntity>(roleService.findByUser(user));
List<RoleEntity> rolesForGroupList = roleService.findByGroups(sessionManager.getGroupList());
roles.addAll(rolesForGroupList);
for (RoleEntity role : roles) {
sessionManager.addRole(role.getId());
if (role instanceof AdminRoleEntity) {
for (ServiceEntity s : serviceService.findByAdminRole(role))
......
......@@ -65,6 +65,17 @@ public class SessionManager implements Serializable {
groupList = new ArrayList<Long>();
}
public void clearRoleList() {
serviceApproverList.clear();
serviceAdminList.clear();
serviceHotlineList.clear();
serviceGroupAdminList.clear();
}
public void clearGroupList() {
groupList.clear();
}
public Long getUserId() {
return userId;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment