Commit 9be83c7b authored by michael.simon's avatar michael.simon
Browse files

Merge branch 'feature-1' into 'branch-2.5'

Make roles configurable in admin menue

Roles can be configured via admin menue:
* Add users and groups to roles
* Remove users and groups to roles

See merge request !1
parents 297bc8cd c91a9d68
......@@ -50,5 +50,9 @@ public interface RoleDao extends BaseDao<RoleEntity, Long> {
List<RoleEntity> findByGroups(Set<GroupEntity> groups);
void addUserToRole(UserEntity user, String roleName);
List<UserEntity> findUsersForRole(RoleEntity role);
List<GroupEntity> findGroupsForRole(RoleEntity role);
}
......@@ -112,6 +112,20 @@ public class JpaRoleDao extends JpaBaseDao<RoleEntity, Long> implements RoleDao
.setParameter("userId", userId).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<UserEntity> findUsersForRole(RoleEntity role) {
return em.createQuery("select u from UserEntity u left join u.roles ur where ur.role = :role")
.setParameter("role", role).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<GroupEntity> findGroupsForRole(RoleEntity role) {
return em.createQuery("select g from GroupEntity g left join g.roles gr where gr.role = :role")
.setParameter("role", role).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public Boolean checkUserInRole(Long userId, String roleName) {
......
......@@ -46,6 +46,9 @@ public class GroupEntity extends AbstractBaseEntity {
@OneToMany(targetEntity = UserGroupEntity.class, mappedBy="group")
private Set<UserGroupEntity> users;
@OneToMany(targetEntity = RoleGroupEntity.class, mappedBy="group")
private Set<RoleGroupEntity> roles;
@ManyToMany(targetEntity=RoleEntity.class, cascade = CascadeType.ALL)
@JoinTable(name = "group_role",
joinColumns = @JoinColumn(name="role_id"),
......
......@@ -12,12 +12,10 @@ package edu.kit.scc.webreg.entity.as;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.GlobalGroupEntity;
@Entity(name = "AttributeSourceGroupEntity")
@Table(name = "attribute_src_group")
public class AttributeSourceGroupEntity extends GlobalGroupEntity {
private static final long serialVersionUID = 1L;
......
......@@ -37,4 +37,12 @@ public interface RoleService extends BaseService<RoleEntity, Long> {
List<RoleEntity> findByGroups(Set<GroupEntity> groups);
List<UserEntity> findUsersForRole(RoleEntity role);
List<GroupEntity> findGroupsForRole(RoleEntity role);
void addGroupToRole(GroupEntity group, RoleEntity role);
void removeGroupFromRole(GroupEntity group, RoleEntity role);
}
......@@ -41,6 +41,16 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleEntity, Long> implement
dao.deleteUserRole(user.getId(), roleName);
}
@Override
public void addGroupToRole(GroupEntity group, RoleEntity role) {
dao.addGroupToRole(group, role);
}
@Override
public void removeGroupFromRole(GroupEntity group, RoleEntity role) {
dao.removeGroupFromRole(group, role);
}
@Override
public List<RoleEntity> findByUser(UserEntity user) {
return dao.findByUser(user);
......@@ -71,6 +81,16 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleEntity, Long> implement
return dao.findWithUsers(id);
}
@Override
public List<UserEntity> findUsersForRole(RoleEntity role) {
return dao.findUsersForRole(role);
}
@Override
public List<GroupEntity> findGroupsForRole(RoleEntity role) {
return dao.findGroupsForRole(role);
}
@Override
public RoleEntity findByName(String name) {
return dao.findByName(name);
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import edu.kit.scc.webreg.entity.AdminRoleEntity;
import edu.kit.scc.webreg.service.AdminRoleService;
import edu.kit.scc.webreg.util.ViewIds;
@ManagedBean
@ViewScoped
public class EditAdminRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private AdminRoleService service;
private AdminRoleEntity entity;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findWithUsers(id);
}
}
public String save() {
entity = service.save(entity);
return ViewIds.SHOW_ADMIN_ROLE + "?faces-redirect=true&id=" + entity.getId();
}
public String cancel() {
return ViewIds.SHOW_ADMIN_ROLE + "?faces-redirect=true&id=" + entity.getId();
}
public AdminRoleEntity getEntity() {
return entity;
}
public void setEntity(AdminRoleEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import edu.kit.scc.webreg.entity.ApproverRoleEntity;
import edu.kit.scc.webreg.service.ApproverRoleService;
import edu.kit.scc.webreg.util.ViewIds;
@ManagedBean
@ViewScoped
public class EditApproverRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private ApproverRoleService service;
private ApproverRoleEntity entity;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findWithUsers(id);
}
}
public String save() {
entity = service.save(entity);
return ViewIds.SHOW_APPROVER_ROLE + "?faces-redirect=true&id=" + entity.getId();
}
public String cancel() {
return ViewIds.SHOW_APPROVER_ROLE + "?faces-redirect=true&id=" + entity.getId();
}
public ApproverRoleEntity getEntity() {
return entity;
}
public void setEntity(ApproverRoleEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import edu.kit.scc.webreg.entity.GroupAdminRoleEntity;
import edu.kit.scc.webreg.service.GroupAdminRoleService;
import edu.kit.scc.webreg.util.ViewIds;
@ManagedBean
@ViewScoped
public class EditGroupAdminRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private GroupAdminRoleService service;
private GroupAdminRoleEntity entity;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
if (entity == null) {
entity = service.findWithUsers(id);
}
}
public String save() {
entity = service.save(entity);
return ViewIds.SHOW_GROUP_ADMIN_ROLE + "?faces-redirect=true&id=" + entity.getId();
}
public String cancel() {
return ViewIds.SHOW_GROUP_ADMIN_ROLE + "?faces-redirect=true&id=" + entity.getId();
}
public GroupAdminRoleEntity getEntity() {
return entity;
}
public void setEntity(GroupAdminRoleEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.AdminRoleEntity;
import edu.kit.scc.webreg.service.AdminRoleService;
@Named("showAdminRoleBean")
@RequestScoped
public class ShowAdminRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private AdminRoleService service;
private AdminRoleEntity entity;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
entity = service.findWithUsers(id);
}
public AdminRoleEntity getEntity() {
return entity;
}
public void setEntity(AdminRoleEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.ApproverRoleEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.service.ApproverRoleService;
@Named("showApproverRoleBean")
@RequestScoped
public class ShowApproverRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private ApproverRoleService service;
private ApproverRoleEntity entity;
private List<UserEntity> userInRoleList;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
entity = service.findWithUsers(id);
}
public ApproverRoleEntity getEntity() {
return entity;
}
public void setEntity(ApproverRoleEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<UserEntity> getUserInRoleList() {
return userInRoleList;
}
public void setUserInRoleList(List<UserEntity> userInRoleList) {
this.userInRoleList = userInRoleList;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;
import edu.kit.scc.webreg.entity.GroupAdminRoleEntity;
import edu.kit.scc.webreg.service.GroupAdminRoleService;
@Named("showGroupAdminRoleBean")
@RequestScoped
public class ShowGroupAdminRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private GroupAdminRoleService service;
private GroupAdminRoleEntity entity;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
entity = service.findWithUsers(id);
}
public GroupAdminRoleEntity getEntity() {
return entity;
}
public void setEntity(GroupAdminRoleEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
......@@ -11,17 +11,25 @@
package edu.kit.scc.webreg.bean.admin.role;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.model.LazyDataModel;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.model.GenericLazyDataModelImpl;
import edu.kit.scc.webreg.service.GroupService;
import edu.kit.scc.webreg.service.RoleService;
import edu.kit.scc.webreg.service.UserService;
@Named("showRoleBean")
@RequestScoped
@ManagedBean
@ViewScoped
public class ShowRoleBean implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -29,12 +37,50 @@ public class ShowRoleBean implements Serializable {
@Inject
private RoleService service;
private RoleEntity entity;
@Inject
private UserService userService;
@Inject
private GroupService groupService;
private RoleEntity entity;
private List<UserEntity> userList;
private List<GroupEntity> groupList;
private LazyDataModel<UserEntity> allUserList;
private LazyDataModel<GroupEntity> allGroupList;
private Long id;
public void preRenderView(ComponentSystemEvent ev) {
entity = service.findWithUsers(id);
if (entity == null) {
entity = service.findById(id);
userList = service.findUsersForRole(entity);
groupList = service.findGroupsForRole(entity);
allUserList = new GenericLazyDataModelImpl<UserEntity, UserService, Long>(userService);
allGroupList = new GenericLazyDataModelImpl<GroupEntity, GroupService, Long>(groupService);
}
}
public void removeUserFromRole(UserEntity user) {
service.removeUserFromRole(user, entity.getName());
userList = service.findUsersForRole(entity);
}
public void removeGroupFromRole(GroupEntity group) {
service.removeGroupFromRole(group, entity);
groupList = service.findGroupsForRole(entity);
}
public void addUserToRole(UserEntity user) {
service.addUserToRole(user, entity.getName());
userList = service.findUsersForRole(entity);
}
public void addGroupToRole(GroupEntity group) {
service.addGroupToRole(group, entity);
groupList = service.findGroupsForRole(entity);
}
public RoleEntity getEntity() {
......@@ -52,4 +98,20 @@ public class ShowRoleBean implements Serializable {
public void setId(Long id) {
this.id = id;
}
public List<UserEntity> getUserList() {
return userList;