RoleView.java
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.insomnia.bortal.view;
import fi.insomnia.bortal.beans.RoleBeanLocal;
import fi.insomnia.bortal.beans.SecurityBeanLocal;
import fi.insomnia.bortal.exceptions.PermissionDeniedException;
import fi.insomnia.bortal.handler.SessionHandler;
import fi.insomnia.bortal.model.Role;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author tuukka
*/
@ManagedBean(name = "roleView")
@SessionScoped
public class RoleView {
@ManagedProperty("#{sessionHandler}")
private SessionHandler sessionhandler;
@EJB
private RoleBeanLocal roleBean;
private static final Logger logger = LoggerFactory.getLogger(RoleView.class);
@EJB
private SecurityBeanLocal securitybean;
private Role role = new Role();
DataModel<Role> items;
public DataModel<Role> getRoles() {
items = new ListDataModel<Role>(roleBean.listRoles());
logger.info("Fetching roles. Found {}", items.getRowCount());
return items;
}
public String save() {
if (!sessionhandler.canWrite("roleManagement")) {
// Give message to administration what happened here.
throw new PermissionDeniedException(securitybean, getSessionhandler().getUser(), "User " + getSessionhandler().getUser() + " does not have permission to modify role!");
}
roleBean.mergeChanges(role);
return "roleSave";
}
public String edit() {
setRole(items.getRowData());
return "roleEdit";
}
/** Creates a new instance of RoleView */
public RoleView() {
}
/**
* @return the role
*/
public Role getRole() {
return role;
}
/**
* @param role the role to set
*/
public void setRole(Role role) {
this.role = role;
}
/**
* @return the sessionhandler
*/
public SessionHandler getSessionhandler() {
return sessionhandler;
}
/**
* @param sessionhandler the sessionhandler to set
*/
public void setSessionhandler(SessionHandler sessionhandler) {
this.sessionhandler = sessionhandler;
}
}