Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
924 | dev | 1 | package ak.hostadmiral.core.model; |
919 | dev | 2 | |
924 | dev | 3 | import ak.hostadmiral.util.ModelException; |
4 | import ak.hostadmiral.util.ModelSecurityException; |
||
921 | dev | 5 | |
919 | dev | 6 | /** |
7 | * |
||
8 | * @hibernate.class table="systemusers" |
||
9 | */ |
||
10 | public class SystemUser |
||
11 | extends GeneralModelObject |
||
12 | { |
||
13 | private Long id; |
||
14 | |||
15 | /** user id in the OS */ |
||
16 | private Integer uid; |
||
17 | private String name; |
||
911 | dev | 18 | private User owner; |
19 | |||
919 | dev | 20 | protected SystemUser() |
21 | { |
||
22 | } |
||
23 | |||
911 | dev | 24 | /** |
25 | * |
||
919 | dev | 26 | * @hibernate.id generator-class="native" |
27 | */ |
||
28 | public Long getId() |
||
29 | { |
||
30 | return id; |
||
31 | } |
||
32 | |||
921 | dev | 33 | protected void setId(Long id) |
919 | dev | 34 | { |
35 | this.id = id; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * |
||
40 | * @hibernate.property |
||
41 | */ |
||
42 | public Integer getUid() |
||
43 | { |
||
44 | return uid; |
||
45 | } |
||
46 | |||
921 | dev | 47 | protected void setUid(Integer uid) |
919 | dev | 48 | { |
49 | this.uid = uid; |
||
50 | } |
||
51 | |||
921 | dev | 52 | public void setUid(User editor, Integer uid) |
53 | throws ModelException |
||
54 | { |
||
55 | if(!editableBy(editor)) |
||
56 | throw new ModelSecurityException(); |
||
57 | |||
58 | this.uid = uid; |
||
59 | } |
||
60 | |||
919 | dev | 61 | /** |
62 | * |
||
63 | * @hibernate.property |
||
64 | */ |
||
65 | public String getName() |
||
66 | { |
||
67 | return name; |
||
68 | } |
||
69 | |||
921 | dev | 70 | protected void setName(String name) |
919 | dev | 71 | { |
72 | this.name = name; |
||
73 | } |
||
74 | |||
921 | dev | 75 | public void setName(User editor, String name) |
76 | throws ModelException |
||
77 | { |
||
78 | if(!editableBy(editor)) |
||
79 | throw new ModelSecurityException(); |
||
80 | |||
81 | this.name = name; |
||
82 | } |
||
83 | |||
919 | dev | 84 | /** |
85 | * |
||
911 | dev | 86 | * @hibernate.many-to-one |
87 | */ |
||
88 | public User getOwner() |
||
89 | { |
||
90 | return owner; |
||
91 | } |
||
92 | |||
921 | dev | 93 | protected void setOwner(User owner) |
911 | dev | 94 | { |
95 | this.owner = owner; |
||
96 | } |
||
97 | |||
921 | dev | 98 | public void setOwner(User editor, User owner) |
99 | throws ModelException |
||
100 | { |
||
101 | if(!editableBy(editor)) |
||
102 | throw new ModelSecurityException(); |
||
103 | |||
104 | this.owner = owner; |
||
105 | } |
||
106 | |||
919 | dev | 107 | public String getTypeKey() |
108 | { |
||
924 | dev | 109 | return ak.hostadmiral.core.CoreResources.TYPE_SYSTEM_USER; |
919 | dev | 110 | } |
111 | |||
112 | public String getIdentKey() |
||
113 | { |
||
924 | dev | 114 | return ak.hostadmiral.core.CoreResources.IDENT_SYSTEM_USER; |
919 | dev | 115 | } |
116 | |||
117 | public Object[] getIdentParams() |
||
118 | { |
||
119 | return new Object[] { getName(), getUid() }; |
||
120 | } |
||
121 | |||
122 | public boolean viewableBy(User user) |
||
123 | { |
||
124 | return user.isSuperuser() || (owner == null) || user.equals(owner); |
||
125 | } |
||
126 | |||
127 | public boolean editableBy(User user) |
||
128 | { |
||
129 | return user.isSuperuser(); |
||
130 | } |
||
131 | |||
132 | public boolean deleteableBy(User user) |
||
133 | { |
||
134 | return user.isSuperuser(); |
||
135 | } |
||
921 | dev | 136 | |
137 | protected static boolean allowedToCreate(SystemUserManager manager, User editor) |
||
138 | throws ModelException |
||
139 | { |
||
140 | return editor.isSuperuser(); |
||
141 | } |
||
919 | dev | 142 | } |