This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroleeditor.jsp
462 lines (436 loc) · 17.3 KB
/
roleeditor.jsp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<%-- $HeadURL$
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2009 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact information:
lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/
Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/
e-mail: [email protected]
--%>
<%@ page contentType="text/html" %>
<jsp:include page="header.jsp" flush="true"/>
<jsp:include page="logotable.jsp" flush="true"/>
<jsp:include page="menutable.jsp" flush="true"/>
<%@ page import="org.deegree.security.drm.*" %>
<%@ page import="org.deegree.security.drm.model.*" %>
<%@ page import="org.deegree.framework.util.StringTools" %>
<%
Role[] roles = (Role[]) request.getAttribute( "ROLES" );
Group[] groups = (Group[]) request.getAttribute( "GROUPS" );
SecurityAccess access = (SecurityAccess) request.getAttribute( "ACCESS" );
String s = (String) request.getAttribute( "supportManyServices" );
boolean manyServices = false;
if ( s != null ) {
manyServices = s.equalsIgnoreCase( "true" );
}
%>
<script language="JavaScript1.2" type="text/javascript">
<!--
var roles, allGroups, changed;
/**
* Constructs a new Group-object, consisting of:
* - id: unique identifier
* - name: display name
*/
function Group( id, name ) {
this.id = id;
this.name = name;
}
/**
* Constructs a new Role-object, consisting of:
* - id: unique identifier
* - name: display name
* - groups: array of groups (associated with this role)
* - isGrantable: is current editor allowed to grant this role?
* - isDeletable: is current editor allowed to delete this role?
* - isUpdatable: is current editor allowed to modify this role?
* - lookup: lookup-array of associated groups
*/
function Role( id, name, groups, isGrantable, isDeletable, isUpdatable ) {
this.id = id;
this.name = name;
this.groups = groups;
this.isGrantable = isGrantable;
this.isDeletable = isDeletable;
this.isUpdatable = isUpdatable;
this.lookup = new Array();
for ( i = 0; i < groups.length; i++ ) {
this.lookup["ID" + groups[i].id] = groups[i].name;
}
}
/**
* Initializes all listboxes with the data from the roles- and
* allGroups-Arrays.
*/
function initForm() {
refreshRolesListBox(0);
refreshGroupsListBox();
refreshAllGroupsListBox();
}
/**
* Fills the roles listbox with all roles from the roles-Array and
* selects the entry with the given index.
*/
function refreshRolesListBox( roleIdx ) {
var oldCount = document.roleForm.roleSelect.length;
for ( i = oldCount - 1; i >= 0; i-- ) {
document.roleForm.roleSelect.options[i] = null;
}
for ( i = 0; i < roles.length; i++ ) {
document.roleForm.roleSelect.options[document.roleForm.roleSelect.length] =
new Option( roles[i].name, roles[i].id );
}
if ( roles.length > 0 ) {
document.roleForm.roleSelect.selectedIndex = roleIdx;
}
}
/**
* Fills the associated groups listbox with all groups from that are
* associated with the currently selected role.
*/
function refreshGroupsListBox() {
var roleIdx = document.roleForm.roleSelect.selectedIndex;
var oldCount = document.groupForm.groupSelect1.length;
for ( i = oldCount - 1; i >= 0; i-- ) {
document.groupForm.groupSelect1.options[i] = null;
}
if ( roleIdx == -1 ) return;
var groups = roles[roleIdx].groups;
for ( i = 0; i < groups.length; i++ ) {
document.groupForm.groupSelect1.options[document.groupForm.groupSelect1.length] =
new Option( groups[i].name, groups[i].id );
}
}
/**
* Fills the available groups listbox with all groups from the groups-Array
* that are not associated with the currently selected role.
*/
function refreshAllGroupsListBox() {
var roleIdx = document.roleForm.roleSelect.selectedIndex;
var oldCount = document.groupForm.groupSelect2.length;
for ( i = oldCount - 1; i >= 0 ; i-- ) {
document.groupForm.groupSelect2.options[i] = null;
}
if ( roleIdx == -1 ) return;
var lookup = roles[roleIdx].lookup;
for ( i = 0; i < allGroups.length; i++ ) {
if ( lookup["ID" + allGroups[i].id] == null ) {
document.groupForm.groupSelect2.options[document.groupForm.groupSelect2.length] =
new Option( allGroups[i].name, allGroups[i].id );
}
}
}
/**
* Adds a new role to the roles-array. Keeps the array in alphabetical order.
*/
function createRole() {
roleName = document.roleForm.roleName.value;
if ( roleName == null || roleName == '' ) {
alert( "Bitte geben Sie einen Namen ein." );
return;
}
for ( i = 0; i < roles.length; i++ ) {
if ( roleName == roles[i].name ) {
alert( "Es existiert bereits eine Rolle namens '" + roleName + "'!" );
return;
}
}
var roleIdx = roles.length;
roles[roleIdx] = new Role( -1, roleName, new Array (), true, true );
roles.sort( namesort );
refreshRolesListBox( roleIdx );
refreshGroupsListBox();
refreshAllGroupsListBox();
changed = true;
document.roleForm.roleName.value = "";
}
/**
* Deletes the selected roles.
*/
function deleteRole() {
var roleIdx = document.roleForm.roleSelect.selectedIndex;
if ( roleIdx == -1 ) {
alert( "W\u00E4hlen Sie bitte zuerst eine Rolle aus." );
return;
}
if ( !roles[roleIdx].isDeletable ) {
alert( "Sie haben nicht die Berechtigung, diese Rolle zu l\u00F6schen." );
return;
}
changed = true;
for ( i = roleIdx + 1; i < roles.length; i++ ) {
roles[i - 1] = roles[i];
}
roles.length = roles.length - 1;
initForm();
}
/**
* Sets the currently selected groups to be associated with the
* selected role.
*/
function associateGroups() {
var roleIdx = document.roleForm.roleSelect.options.selectedIndex;
var selected = getSelectedOptions( document.groupForm.groupSelect2.options );
if ( selected.length == 0 || roleIdx == -1 ) {
return;
}
if ( !roles [roleIdx].isGrantable ) {
alert( "Sie haben nicht die Berechtigung, diese Rolle zuzuweisen." );
return;
}
var groups = roles[roleIdx].groups;
var lookup = roles[roleIdx].lookup;
for ( i = 0; i < selected.length; i++ ) {
var groupId = selected [i].value;
for ( j = 0; j < allGroups.length; j++ ) {
if ( allGroups[j].id == groupId ) {
var newGroup = allGroups[j];
groups[groups.length] = newGroup;
lookup["ID" + newGroup.id] = newGroup.name;
}
}
}
groups.sort( namesort );
refreshGroupsListBox();
refreshAllGroupsListBox();
changed = true;
}
/**
* Withdraws the currently selected role from the selected groups.
*/
function withdrawRole() {
var roleIdx = document.roleForm.roleSelect.options.selectedIndex;
var selected = getSelectedOptions( document.groupForm.groupSelect1.options );
if ( selected.length == 0 || roleIdx == -1 ) {
return;
}
if ( !roles[roleIdx].isGrantable ) {
alert( "Sie haben nicht die Berechtigung, die Zuweisung dieser Rolle zu \u00E4ndern." );
return;
}
var lookup = roles[roleIdx].lookup;
var groups = roles[roleIdx].groups;
for ( i = 0; i < selected.length; i++ ) {
lookup["ID" + selected[i].value] = null;
}
selected = getSelectedOptionsIdx( document.groupForm.groupSelect1.options );
for ( i = 0; i < selected.length; i++ ) {
var groupIdx = selected[i];
var nextIdx;
if ( i != selected.length - 1 ) {
nextIdx = selected[i + 1];
} else {
nextIdx = groups.length;
}
for ( j = groupIdx + 1; j < nextIdx; j++ ) {
groups[j - (i + 1)] = groups[j];
}
}
groups.length = groups.length - selected.length;
refreshGroupsListBox();
refreshAllGroupsListBox();
changed = true;
}
function init() {
changed = false
<%
out.println( " allGroups = new Array (" + groups.length + " );" );
for ( int i = 0; i < groups.length; i++ ) {
out.println( " allGroups[" + i + "] = new Group( " + groups [i].getID() + ", '"
+ StringTools.replace( groups[i].getName(), "'", "\\'", true) + "' );" );
}
out.println( " allGroups.sort( namesort );" );
out.println( " roles = new Array( " + roles.length + " );" );
for ( int i = 0; i < roles.length; i++ ) {
Group[] groups1 = roles[i].getGroups( access );
out.println( " groups" + i + "= new Array( " + groups1.length + " );" );
for ( int j = 0; j < groups1.length; j++ ) {
out.println( " groups" + i + " [" + j + "] = new Group( " + groups1[j].getID() + ", '"
+ StringTools.replace( groups1[j].getName(), "'", "\\'", true ) + "' );" );
}
out.println( " groups" + i + ".sort( namesort );" );
boolean isGrantable = access.getUser().hasRight( access, RightType.GRANT, roles [i] );
boolean isDeletable = access.getUser().hasRight( access, RightType.DELETE, roles [i] );
boolean isUpdatable = access.getUser().hasRight( access, RightType.UPDATE, roles [i] );
out.println( " roles[" + i + "] = new Role( " + roles[i].getID() + ", '"
+ StringTools.replace( roles[i].getName(), "'", "\\'", true ) + "', groups" + i + ", "
+ isGrantable + "," + isDeletable + "," + isUpdatable + " );" );
}
out.println( " roles.sort( namesort );" );
%>
changed = false;
initForm();
}
function editRights() {
var roleIdx = document.roleForm.roleSelect.options.selectedIndex;
if ( roleIdx == -1 ) {
alert( "W\u00E4hlen Sie bitte eine Rolle aus." );
} else if ( changed ) {
alert( "Es gibt nichtgespeicherte \u00C4nderungen. Sie m\u00FCssen '\u00C4nderungen speichern' oder " +
"'\u00C4nderungen verwerfen' w\u00E4hlen, bevor Sie eine Rolle editieren k\u00F6nnen.");
} else {
if ( !roles[roleIdx].isUpdatable ) {
alert( "Sie haben nicht die Berechtigung, diese Rolle zu editieren." );
} else {
editRightsRPC( roles[roleIdx].id );
}
}
}
function editServiceRights() {
var roleIdx = document.roleForm.roleSelect.options.selectedIndex
if ( roleIdx == -1 ) {
alert( "W\u00E4hlen Sie bitte eine Rolle aus." )
} else if ( changed ) {
alert( "Es gibt nichtgespeicherte \u00C4nderungen. Sie m\u00FCssen '\u00C4nderungen speichern' oder " +
"'\u00C4nderungen verwerfen' w\u00E4hlen, bevor Sie eine Rolle editieren k\u00F6nnen.")
} else {
if ( !roles[roleIdx].isUpdatable ) {
alert( "Sie haben nicht die Berechtigung, diese Rolle zu editieren." )
} else {
editServiceRightsRPC( roles[roleIdx].id )
}
}
}
function perform() {
if ( confirm( "Wollen Sie die vorgenommenen \u00C4nderungen wirklich speichern?" ) ) {
storeRoles(roles);
}
}
//-->
</script>
<table class="maintable">
<tr>
<td valign="top">
<h2>Rollen-Editor</h2>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td valign="top">
<form action="javascript:createRole()" name="roleForm">
<table border="0">
<tr>
<td class="caption">Rollen</td>
</tr>
<tr>
<td>
<select class="largeselect" style="width:280px" name="roleSelect" size="17" onchange="refreshGroupsListBox();refreshAllGroupsListBox();">
<option>Formularinitialisierung...</option>
</select>
</td>
</tr>
<tr>
<td height="10"/>
</tr>
<tr>
<td>
<table border="0" cellspacing="5" cellpadding="2">
<tr>
<td>
<table border="0" cellspacing="5" cellpadding="2">
<tr>
<td class="menu">
<a href="javascript:createRole()">neue Rolle</a>
</td>
</tr>
</table>
</td>
<td>
<input type="text" name="roleName"/>
</td>
</tr>
<tr>
<td colspan="2">
<table border="0" cellspacing="5" cellpadding="2">
<tr>
<td class="menu">
<a href="javascript:deleteRole()">Rolle löschen</a>
</td>
<td class="menu">
<a href="javascript:editRights()">Rechte editieren</a>
</td>
</tr>
<%
if(manyServices){
%>
<tr>
<td></td>
<td class="menu">
<a href="javascript:editServiceRights()">Dienste zuordnen</a>
</td>
</tr>
<%
}
%>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</td>
<td valign="top">
<table border="0">
<tr>
<td>
<form action="" name="groupForm">
<table border="0">
<tr>
<td class="caption">zugewiesene Gruppen</td>
<td></td>
<td class="caption">verfügbare Gruppen</td>
</tr>
<tr>
<td>
<select class="largeselect" style="width:280px" name="groupSelect1" size="17" multiple="multiple">
<option>Formularinitialisierung...</option>
</select>
</td>
<td valign="middle" align="center">
<a href="javascript:associateGroups()">
<img src="images/admin_bt_add.gif" alt="+" border="0"/>
</a>
<br/>
<a href="javascript:withdrawRole()">
<img src="images/admin_bt_remove.gif" alt="-" border="0"/>
</a>
</td>
<td>
<select class="largeselect" style="width:280px" name="groupSelect2" size="17" multiple="multiple">
<option>Formularinitialisierung...</option>
</select>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<jsp:include page="submittable.jsp" flush="true"/>
<jsp:include page="footer.jsp" flush="true"/>