I have developed a security customizer that I would like to contribute back
to Jetspeed. It is based off of the PSML customizer. I have attached a
file with the necessary patches to integrate the security customizer as well
as the new templates and code that provide the functionality. There are two
templates attached. One allows a user to add more that one Allow to a
security access while the other only allows one Allow per security access.
I have seen posts on the list mentioning that multiple Allows might have not
been the intention even though they are allowed via the API. Instead, one
should have multiple accesses with the same action. I have provided both
templates for either case. If it turns out that multiple Allows should not
occur, you can greatly reduce the amount of code in the java file by
removing the unnecessary methods needed for Allows.
I will also log this in Bugzilla with the attachment.
If you have any questions, please feel free to let me know.
Jeremy Ford
How to use:
Adding a security entry
1) Click on "Add Security"
2) Enter a name for you security entry, along with title and description
4) Click on "Insert Security".
5) You will be taken back to the security update form where you can add
security accesses
Updating a security entry
1) Choose a security entry and click on "Edit"
2) Make modifications
3) Click on "Update Security"
4) The form should not reflect your changes
Adding a Security Access
1) Choose a security entry and click on "Edit"
2) Choose the action type
3) Choose the type of Allow
4) If user or role Allow, choose appropriate value from the combo box. If
owner, do nothing
5) Click "Add Security Access"
6) The security access should now appear in the access list
Removing a Security Access
1) Choose a security entry and click on "Edit"
2) Choose the accesses that you wish to remove
3) Click on "Remove Access"
4) The access list should no longer have the accesses in it
Deleting a security entry
1) Choose a security entry and click on "Delete"
2) Confirm your decision
3) The security entry will not be in the browser
Index: browser-security.vm
===================================================================
RCS file:
/home/cvspublic/jakarta-jetspeed/webapp/WEB-INF/templates/vm/portlets/html/browser-security.vm,v
retrieving revision 1.1
diff -u -r1.1 browser-security.vm
--- browser-security.vm 30 Jun 2002 19:41:36 -0000 1.1
+++ browser-security.vm 3 Apr 2003 04:35:36 -0000
@@ -4,12 +4,15 @@
<th>Security ID</th>
<th>Title</th>
<th>Description</th>
+ <th colspan="2">Actions</th>
</tr>
#foreach ( $entry in $registry )
<tr>
<td>$entry.Name</td>
<td>$!entry.Title</td>
<td>$!entry.Description</td>
+ <td width="5%"><a style="font-size:10"
href="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction").addQueryData("mode","update").addQueryData("security_name",
$entry.name)">Edit</a></td>
+ <td width="5%"><a style="font-size:10"
href="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction").addQueryData("mode","delete").addQueryData("security_name",
$entry.name)">Delete</a></td>
</tr>
#end
</table>
@@ -24,6 +27,11 @@
#if ($prev)
<input type="submit" value="Next > >">
#end
+ </td>
+ </tr>
+ <tr>
+ <td colspan=6 align="left">
+ <a style="font-size:10"
href="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction").addQueryData("mode","insert")">Add
Security</a>
</td>
</tr>
</table>
Index: security-form-multiple-allows.vm
===================================================================
RCS file: security-form-multiple-allows.vm
diff -N security-form-multiple-allows.vm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ security-form-multiple-allows.vm 3 Apr 2003 04:35:48 -0000
@@ -0,0 +1,364 @@
+<table bgcolor="#ffffff" cellpadding="5">
+ #if ($msg)
+ <tr>
+ <td colspan="2">
+ <table bgcolor="#ffffff">
+ <tr>
+ <td>
+ $msg
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ #end
+</table>
+
+ #if ($mode == "delete")
+ <form name="SecurityForm" method="post"
action="$jslink.getPaneByName("SecurityBrowser").setAction("portlets.SecurityUpdateAction")">
+ <table>
+ <tr>
+ <td colspan="2">Are you sure you want do delete this security
entry?</td>
+ </tr>
+ <tr>
+ #formReadOnlyCell ("Name" "security_name" $!entry.Name)
+ </tr>
+ </table>
+ <table border="0" cellspacing="0" cellpadding="5" width="30%">
+ <tr>
+ <td>
+ <input type="submit" name="eventSubmit_doDelete" value="Delete Security
Entry"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ #elseif($mode == "insert")
+ <form name="SecurityForm" method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+
+ <table>
+ <input type="hidden" name="mode" value="update"/>
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Name</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <input type="text" size="30" name="security_name"
value="$!data.user.getTemp("security_name")"/>
+ </font>
+ </td>
+ </tr>
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Title</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <input type="text" size="50" name="title"
value="$!data.user.getTemp("title")">
+ </font>
+ </td>
+ </tr>
+ <!--Consider making text area-->
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Description</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <textarea rows="10" cols="50" size="50"
name="description">$!data.user.getTemp("description")</textarea>
+ </font>
+ </td>
+ </tr>
+ </table>
+ <table border="0" cellspacing="0" cellpadding="5" width="30%">
+ <tr>
+ <td>
+ <input type="submit" name="eventSubmit_doInsert" value="Insert Security"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ #elseif($mode == "update")
+
+ #if($subMode == "allow")
+ ##Remove Form
+ <form method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="access_index" value="$!accessIndex"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ Current Access: $securityAccess.action
+ <hr />
+ <br />
+ Allows
+ <table>
+ #foreach($allow in $securityAccess.getAllows())
+ <tr>
+ <td><input type="checkbox" name="allow_index"
value="$!velocityCount"/></td>
+ <td>
+ #if($allow.user)
+ $allow.user
+ #elseif($allow.role)
+ $allow.role
+ #end
+ </td>
+ </tr>
+ #end
+ #if($securityAccess.getAllows().size() > 0)
+ <tr>
+ <td colspan="2"><input type="submit" name="eventSubmit_doRemoveallow"
value="Remove Allow"/>
+ </tr>
+ #end
+ </table>
+ </form>
+ <hr />
+ <br />
+ Owner Allows
+ <form method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="access_index" value="$!accessIndex"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ <input type="hidden" name="allow_type" value="owner"/>
+ <table>
+ #foreach($allow in $securityAccess.getOwnerAllows())
+ <tr>
+ <td><input type="checkbox" name="allow_index" value="$!velocityCount"/></td>
+ <td>
+ #if($allow.user)
+ $allow.user
+ #elseif($allow.role)
+ $allow.role
+ #elseif($allow.owner)
+ $allow.owner
+ #end
+ </td>
+ </tr>
+ #end
+ #if($securityAccess.getOwnerAllows().size() > 0)
+ <tr>
+ <td colspan="2"><input type="submit" name="eventSubmit_doRemoveallow"
value="Remove Allow"/>
+ </tr>
+ #end
+ </table>
+ </form>
+ <hr />
+ <br />
+ ##Add new allow to access form
+ <form method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="access_index" value="$!accessIndex"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ <table>
+ <tr>
+ <td>Type</td>
+ <td>
+ <select name="allow_type">
+ <option value="user">User</option>
+ <option value="role">Role</option>
+ <option value="owner">Owner</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>Value</td>
+ <td><input type="text" name="allow_value"
value="$!data.parameters.getString("allow_value")"/>
+ </tr>
+ <tr>
+ <td><input type="submit" name="eventSubmit_doAddallow" value="Add
Allow"/>
+ </tr>
+ </table>
+ </form>
+
+ <br />
+ <form method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+
+ <input type="submit" value="Back to Security Entry"/>
+ </form>
+ #else
+ <form name="SecurityForm" method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+
+ <table>
+ <input type="hidden" name="mode" value="update"/>
+ <tr>
+ #formReadOnlyCell ("Name" "security_name" $!entry.Name)
+ </tr>
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Title</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <input type="text" size="50" name="title" value="$!entry.title">
+ </font>
+ </td>
+ </tr>
+ <!--Consider making text area-->
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Description</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <textarea rows="10" cols="50" size="50"
name="description">$!entry.description</textarea>
+ </font>
+ </td>
+ </tr>
+ </table>
+ <table border="0" cellspacing="0" cellpadding="5" width="30%">
+ <tr>
+ <td>
+ <input type="submit" name="eventSubmit_doUpdate" value="Update
Security"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+
+ <form method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ <table border="1">
+ ##<th> </th>
+ ##<th>Action</th>
+ ##<th>Allows</th>
+ #foreach($securityAccess in $entry.getAccesses())
+ <tr>
+ <td><input type="checkbox" name="access_index"
value="$!velocityCount"/></td>
+ <td>
+ $securityAccess.action
+ </td>
+ <td>
+ <a
href="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction").addQueryData("mode",
"update").addQueryData("security_name",$entry.name).addQueryData("access_index",$velocityCount).addQueryData("subMode",
"allow")">More</a>
+ </td>
+ </tr>
+ #end
+ #if($entry.getAccesses().size() > 0)
+ <tr>
+ <td colspan="3"><input type="submit" name="eventSubmit_doRemoveaccess"
value="Remove Access"/>
+ </tr>
+ #end
+ </table>
+ </form>
+
+ <!--Add a new action entry-->
+ <script>
+
+ var userSelect = new Array;
+ var roleSelect = new Array;
+ var populated = false;
+
+ function populate()
+ {
+ #foreach($user in $users)
+ #set($myCount = $velocityCount - 1)
+ var userOption$myCount = new Option;
+ userOption${myCount}.value = "$user.userName";
+ userOption${myCount}.text = "$user.userName";
+
+ userSelect[$myCount] = userOption$myCount;
+ #end
+
+ #foreach($role in $roles)
+ #set($myCount = $velocityCount - 1)
+ var roleOption$myCount = new Option;
+ roleOption${myCount}.value = "$role.name";
+ roleOption${myCount}.text = "$role.name";
+
+ roleSelect[$myCount] = roleOption$myCount;
+ #end
+
+ populated = true;
+ }
+
+
+
+ function changeList(selectAction)
+ {
+ if(!populated)
+ {
+ populate();
+ }
+ var val =
selectAction.options[selectAction.selectedIndex].value;
+
+ var newOpts = new Array;
+
+ if(val == "user")
+ {
+ newOpts = userSelect;
+ }
+ else if(val == "role")
+ {
+ newOpts = roleSelect;
+ }
+
+ var select = document.NewSecurity.allow_value;
+
+ for(var i=0; i<newOpts.length; i++)
+ {
+ select.options[i] = newOpts[i];
+ }
+
+ for(var j=newOpts.length; j<select.options.length; j++)
+ {
+ select.options[j] = new Option;
+ }
+ }
+
+ </script>
+ <form name="NewSecurity" method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ <table>
+ <tr>
+ <td>Action</td>
+ <td>
+ <select name="access_action" >
+ <option value="*">*</option>
+ #foreach($permission in $permissions)
+ <option value="$!permission.name"
#if($data.user.getTemp("access_action") == $permission.name) selected="true"
#end>$!permission.name</option>
+ #end
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>Type</td>
+ <td>
+ <select name="allow_type" onChange="changeList(this); return
true;">
+ <option value="owner">Owner</option>
+ <option value="user">User</option>
+ <option value="role">Role</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>Value</td>
+ ##<td><input type="text" name="allow_value"
value="$!data.parameters.getString("allow_value")"/></td>
+
+ <td>
+ <select name="allow_value">
+ #*
+ #foreach($user in $users)
+ <option value="$user.name">$user.userName</option>
+ #end
+ *#
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td><input type="submit" name="eventSubmit_doAddaccess" value="Add
Security Access"/>
+ </tr>
+ </table>
+ </form>
+ #end
+ ##ends else of subMode==allow
+
+ #end
+
+<table>
+ <tr>
+ <td>
+ <form name="BackToBrowserForm" method="post"
action="$jslink.getPaneByName("SecurityBrowser").setAction("portlets.SecurityUpdateAction")">
+ <input type="submit" name="eventSubmit_doCancel" value="Back to
Browser"/>
+ </form>
+ </td>
+ </tr>
+</table>
+
Index: security-form.vm
===================================================================
RCS file: security-form.vm
diff -N security-form.vm
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ security-form.vm 3 Apr 2003 04:36:04 -0000
@@ -0,0 +1,282 @@
+<table bgcolor="#ffffff" cellpadding="5">
+ #if ($msg)
+ <tr>
+ <td colspan="2">
+ <table bgcolor="#ffffff">
+ <tr>
+ <td>
+ $msg
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ #end
+</table>
+
+ #if ($mode == "delete")
+ <form name="SecurityForm" method="post"
action="$jslink.getPaneByName("SecurityBrowser").setAction("portlets.SecurityUpdateAction")">
+ <table>
+ <tr>
+ <td colspan="2">Are you sure you want do delete this security
entry?</td>
+ </tr>
+ <tr>
+ #formReadOnlyCell ("Name" "security_name" $!entry.Name)
+ </tr>
+ </table>
+ <table border="0" cellspacing="0" cellpadding="5" width="30%">
+ <tr>
+ <td>
+ <input type="submit" name="eventSubmit_doDelete" value="Delete Security
Entry"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ #elseif($mode == "insert")
+ <form name="SecurityForm" method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+
+ <table>
+ <input type="hidden" name="mode" value="update"/>
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Name</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <input type="text" size="30" name="security_name"
value="$!data.user.getTemp("security_name")"/>
+ </font>
+ </td>
+ </tr>
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Title</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <input type="text" size="50" name="title"
value="$!data.user.getTemp("title")">
+ </font>
+ </td>
+ </tr>
+ <!--Consider making text area-->
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Description</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <textarea rows="10" cols="50" size="50"
name="description">$!data.user.getTemp("description")</textarea>
+ </font>
+ </td>
+ </tr>
+ </table>
+ <table border="0" cellspacing="0" cellpadding="5" width="30%">
+ <tr>
+ <td>
+ <input type="submit" name="eventSubmit_doInsert" value="Insert Security"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+ #elseif($mode == "update")
+ <form name="SecurityForm" method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+
+ <table>
+ <input type="hidden" name="mode" value="update"/>
+ <tr>
+ #formReadOnlyCell ("Name" "security_name" $!entry.Name)
+ </tr>
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Title</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <input type="text" size="50" name="title" value="$!entry.title">
+ </font>
+ </td>
+ </tr>
+ <!--Consider making text area-->
+ <tr>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <b><font face="$ui.sansSerifFonts">Description</font></b>
+ </td>
+ <td bgcolor="$!{skin.TitleBackgroundColor}">
+ <font face="$ui.sansSerifFonts">
+ <textarea rows="10" cols="50" size="50"
name="description">$!entry.description</textarea>
+ </font>
+ </td>
+ </tr>
+ </table>
+ <table border="0" cellspacing="0" cellpadding="5" width="30%">
+ <tr>
+ <td>
+ <input type="submit" name="eventSubmit_doUpdate" value="Update
Security"/>
+ </td>
+ </tr>
+ </table>
+ </form>
+
+ <form method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ <table border="1">
+ ##<th> </th>
+ ##<th>Action</th>
+ ##<th>Allows</th>
+ #foreach($securityAccess in $entry.getAccesses())
+ <tr>
+ <td><input type="checkbox" name="access_index"
value="$!velocityCount"/></td>
+ <td>
+ $securityAccess.action
+ </td>
+
+ #set($allowList = $securityAccess.getOwnerAllows())
+ #if($allowList.size() == 0)
+ #set($allowList = $securityAccess.getAllows())
+ #end
+
+ #if($allowList.size() == 1)
+ #set($allow = $allowList.get(0))
+ #end
+ <td>
+ #if($allow)
+ <table>
+ <tr>
+ <td>#if($allow.user)User
#elseif($allow.role)Role #else Owner #end</td>
+ <td>#if($allow.user)$allow.user
#elseif($allow.role)$allow.role #else #end</td>
+ <tr>
+ </table>
+ #else
+ No Allow Set
+ #end
+ </td>
+ </tr>
+ #end
+ #if($entry.getAccesses().size() > 0)
+ <tr>
+ <td colspan="3"><input type="submit" name="eventSubmit_doRemoveaccess"
value="Remove Access"/>
+ </tr>
+ #end
+ </table>
+ </form>
+
+ <!--Add a new action entry-->
+ <script>
+
+ var userSelect = new Array;
+ var roleSelect = new Array;
+ var populated = false;
+
+ function populate()
+ {
+ #foreach($user in $users)
+ #set($myCount = $velocityCount - 1)
+ var userOption$myCount = new Option;
+ userOption${myCount}.value = "$user.userName";
+ userOption${myCount}.text = "$user.userName";
+
+ userSelect[$myCount] = userOption$myCount;
+ #end
+
+ #foreach($role in $roles)
+ #set($myCount = $velocityCount - 1)
+ var roleOption$myCount = new Option;
+ roleOption${myCount}.value = "$role.name";
+ roleOption${myCount}.text = "$role.name";
+
+ roleSelect[$myCount] = roleOption$myCount;
+ #end
+
+ populated = true;
+ }
+
+
+
+ function changeList(selectAction)
+ {
+ if(!populated)
+ {
+ populate();
+ }
+ var val =
selectAction.options[selectAction.selectedIndex].value;
+
+ var newOpts = new Array;
+
+ if(val == "user")
+ {
+ newOpts = userSelect;
+ }
+ else if(val == "role")
+ {
+ newOpts = roleSelect;
+ }
+
+ var select = document.NewSecurity.allow_value;
+
+ for(var i=0; i<newOpts.length; i++)
+ {
+ select.options[i] = newOpts[i];
+ }
+
+ for(var j=newOpts.length; j<select.options.length; j++)
+ {
+ select.options[j] = new Option;
+ }
+ }
+
+ </script>
+ <form name="NewSecurity" method="post"
action="$jslink.getPaneByName("SecurityForm").setAction("portlets.SecurityUpdateAction")">
+ <input type="hidden" name="mode" value="update"/>
+ <input type="hidden" name="security_name" value="$!entry.name"/>
+ <table>
+ <tr>
+ <td>Action</td>
+ <td>
+ <select name="access_action" >
+ <option value="*">*</option>
+ #foreach($permission in $permissions)
+ <option value="$!permission.name"
#if($data.user.getTemp("access_action") == $permission.name) selected="true"
#end>$!permission.name</option>
+ #end
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>Type</td>
+ <td>
+ <select name="allow_type" onChange="changeList(this); return
true;">
+ <option value="owner">Owner</option>
+ <option value="user">User</option>
+ <option value="role">Role</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td>Value</td>
+ ##<td><input type="text" name="allow_value"
value="$!data.parameters.getString("allow_value")"/></td>
+
+ <td>
+ <select name="allow_value">
+ #*
+ #foreach($user in $users)
+ <option value="$user.name">$user.userName</option>
+ #end
+ *#
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td><input type="submit" name="eventSubmit_doAddaccess" value="Add
Security Access"/>
+ </tr>
+ </table>
+ </form>
+ #end
+
+<table>
+ <tr>
+ <td>
+ <form name="BackToBrowserForm" method="post"
action="$jslink.getPaneByName("SecurityBrowser").setAction("portlets.SecurityUpdateAction")">
+ <input type="submit" name="eventSubmit_doCancel" value="Back to
Browser"/>
+ </form>
+ </td>
+ </tr>
+</table>
+
Index: default.psml
===================================================================
RCS file:
/home/cvspublic/jakarta-jetspeed/webapp/WEB-INF/psml/user/admin/html/default.psml,v
retrieving revision 1.20
diff -u -r1.20 default.psml
--- default.psml 4 Mar 2003 17:39:42 -0000 1.20
+++ default.psml 3 Apr 2003 04:37:58 -0000
@@ -84,5 +84,8 @@
<entry id='349' parent="PortletForm">
<parameter name="_menustate" value="closed"/>
</entry>
+ <entry id='350' parent="SecurityForm">
+ <parameter name="_menustate" value="closed"/>
+ </entry>
</portlets>
</portlets>
Index: admin.xreg
===================================================================
RCS file: /home/cvspublic/jakarta-jetspeed/webapp/WEB-INF/conf/admin.xreg,v
retrieving revision 1.33
diff -u -r1.33 admin.xreg
--- admin.xreg 4 Mar 2003 17:39:42 -0000 1.33
+++ admin.xreg 3 Apr 2003 04:39:04 -0000
@@ -491,5 +491,22 @@
<url cachedOnURL="true"/>
<category group="Jetspeed">admin</category>
</portlet-entry>
+ <portlet-entry name="SecurityForm" hidden="true" type="ref"
+ parent="CustomizerVelocity" application="false">
+ <security role="admin"/>
+ <security-ref parent="admin-only"/>
+ <meta-info>
+ <title>Security</title>
+ <description>Security Portlet Maintenance for Jetspeed</description>
+ </meta-info>
+
<classname>org.apache.jetspeed.portal.portlets.CustomizerVelocityPortlet</classname>
+ <parameter name="template" value="security-form" hidden="true"
+ cachedOnName="true" cachedOnValue="true"/>
+ <parameter name="action" value="portlets.SecurityUpdateAction"
+ hidden="true" cachedOnName="true" cachedOnValue="true"/>
+ <media-type ref="html"/>
+ <url cachedOnURL="true"/>
+ <category group="Jetspeed">admin</category>
+ </portlet-entry>
</registry>
Index: SecurityUpdateAction.java
===================================================================
RCS file: SecurityUpdateAction.java
diff -N SecurityUpdateAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SecurityUpdateAction.java 4 Apr 2003 04:13:59 -0000
@@ -0,0 +1,930 @@
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ * "Apache Jetspeed" must not be used to endorse or promote products
+ * derived from this software without prior written permission. For
+ * written permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache" or
+ * "Apache Jetspeed", nor may "Apache" appear in their name, without
+ * prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+package org.apache.jetspeed.modules.actions.portlets;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
+import org.apache.jetspeed.om.registry.SecurityAccess;
+import org.apache.jetspeed.om.registry.SecurityAllow;
+import org.apache.jetspeed.om.registry.SecurityEntry;
+import org.apache.jetspeed.om.registry.base.BaseSecurityAccess;
+import org.apache.jetspeed.om.registry.base.BaseSecurityAllow;
+import org.apache.jetspeed.om.registry.base.BaseSecurityAllowOwner;
+import org.apache.jetspeed.om.registry.base.BaseSecurityEntry;
+import org.apache.jetspeed.portal.portlets.VelocityPortlet;
+import org.apache.jetspeed.services.JetspeedSecurity;
+import org.apache.jetspeed.services.Registry;
+import org.apache.jetspeed.util.template.JetspeedLink;
+import org.apache.jetspeed.util.template.JetspeedLinkFactory;
+import org.apache.turbine.util.DynamicURI;
+import org.apache.turbine.util.Log;
+import org.apache.turbine.util.RunData;
+import org.apache.turbine.util.security.EntityExistsException;
+import org.apache.velocity.context.Context;
+
+/**
+ * @author Administrator
+ *
+ *
+ */
+public class SecurityUpdateAction extends VelocityPortletAction
+{
+ private static final String SECURITY_UPDATE_PANE = "security-form";
+
+ /**
+ * @see
org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction#buildNormalContext(VelocityPortlet,
Context, RunData)
+ */
+ protected void buildNormalContext(
+ VelocityPortlet portlet,
+ Context context,
+ RunData rundata)
+ throws Exception
+ {
+ String mode =
+ rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
+ context.put(SecurityConstants.PARAM_MODE, mode);
+
+ String msgid =
+ rundata.getParameters().getString(SecurityConstants.PARAM_MSGID);
+ if (msgid != null)
+ {
+ int id = Integer.parseInt(msgid);
+ if (id < SecurityConstants.MESSAGES.length)
+ {
+ context.put(
+ SecurityConstants.PARAM_MSG,
+ SecurityConstants.MESSAGES[id]);
+ }
+ }
+
+ if (mode != null
+ && (mode.equals(SecurityConstants.PARAM_MODE_DELETE)
+ || mode.equals(SecurityConstants.PARAM_MODE_UPDATE)))
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+
+ String subMode = rundata.getParameters().getString("subMode");
+ if (subMode != null)
+ {
+ context.put("subMode", subMode);
+ int accessIndex =
+ rundata.getParameters().getInt("access_index", -1);
+ if (accessIndex != -1)
+ {
+ context.put("accessIndex", new Integer(accessIndex));
+ accessIndex--;
+ BaseSecurityAccess securityAccess =
+ (BaseSecurityAccess) securityEntry.getAccesses().get(
+ accessIndex);
+ context.put("securityAccess", securityAccess);
+ }
+ }
+
+ Iterator permissionIter = JetspeedSecurity.getPermissions();
+ Iterator userIter = JetspeedSecurity.getUsers();
+ Iterator roleIter = JetspeedSecurity.getRoles();
+
+ context.put("permissions", permissionIter);
+ context.put("users", userIter);
+ context.put("roles", roleIter);
+
+ context.put("entry", securityEntry);
+ }
+
+ if (mode != null && (mode.equals(SecurityConstants.PARAM_MODE_INSERT)))
+ {
+ Iterator permissionIter = JetspeedSecurity.getPermissions();
+ context.put("permissions", permissionIter);
+ }
+ }
+
+ /**
+ * Insert a security entry into the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doInsert(RunData rundata, Context context) throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+
+ if (securityName == null || securityName.length() == 0)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_INSERT)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_MISSING_PARAMETER);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ else
+ {
+ BaseSecurityEntry existingSecurityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+
+ if (existingSecurityEntry != null)
+ {
+ throw new EntityExistsException(
+ "SecurityEntry: " + securityName + " Already Exists!");
+ }
+
+ String title = rundata.getParameters().getString("title");
+ String description =
+ rundata.getParameters().getString("description");
+
+ BaseSecurityEntry securityEntry = new BaseSecurityEntry();
+ securityEntry.setName(securityName);
+
+ setSecurityFields(rundata, securityEntry);
+
+ Registry.addEntry(Registry.SECURITY, securityEntry);
+ clearUserData(rundata);
+ }
+ }
+ catch (EntityExistsException e)
+ {
+ //
+ // dup key found - display error message - bring back to same screen
+ //
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_INSERT)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+
+ //resetForm(rundata);
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_INSERT)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_UPDATE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+
+ }
+
+ /**
+ * Update a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doUpdate(RunData rundata, Context context) throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+
+ if (securityEntry != null)
+ {
+ setSecurityFields(rundata, securityEntry);
+ Registry.addEntry(Registry.SECURITY, securityEntry);
+ clearUserData(rundata);
+ }
+ else
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_UPDATE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+
+ private void setSecurityFields(
+ RunData rundata,
+ SecurityEntry securityEntry)
+ {
+ String title = rundata.getParameters().getString("title");
+ String description = rundata.getParameters().getString("description");
+
+ securityEntry.setTitle(title);
+ securityEntry.setDescription(description);
+ }
+
+ /**
+ * Update a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doDelete(RunData rundata, Context context) throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+
+ if (securityEntry != null)
+ {
+ Registry.removeEntry(Registry.SECURITY, securityName);
+ clearUserData(rundata);
+ }
+ else
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_DELETE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_DELETE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+
+ /**
+ * Update a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doAddaccess(RunData rundata, Context context) throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+
+ if (securityEntry != null)
+ {
+ String action =
+ rundata.getParameters().getString("access_action");
+
+ if (action != null && action.length() > 0)
+ {
+ BaseSecurityAccess securityAccess =
+ new BaseSecurityAccess();
+ securityAccess.setAction(action);
+
+ addAllow(rundata, securityAccess);
+
+ securityEntry.getAccesses().add(securityAccess);
+
+ Registry.addEntry(Registry.SECURITY, securityEntry);
+ clearUserData(rundata);
+ }
+ else
+ {
+ JetspeedLink link =
+ JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_MISSING_PARAMETER);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ else
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_UPDATE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+
+ /**
+ * Update a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doUpdateaccess(RunData rundata, Context context)
+ throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+ if (securityEntry != null)
+ {
+ int accessIndex =
+ rundata.getParameters().getInt("access_index", -1);
+ accessIndex--;
+ String action =
+ rundata.getParameters().getString("access_action");
+
+ if (accessIndex >= 0
+ && accessIndex < securityEntry.getAccesses().size())
+ {
+ BaseSecurityAccess securityAccess =
+ (BaseSecurityAccess) securityEntry.getAccesses().get(
+ accessIndex);
+ securityAccess.setAction(action);
+
+ Registry.addEntry(Registry.SECURITY, securityEntry);
+ clearUserData(rundata);
+ }
+ }
+ else
+ {
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ /**
+ * Remove a access entry from a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doRemoveaccess(RunData rundata, Context context)
+ throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+ if (securityEntry != null)
+ {
+ int[] accessIndexes =
+ rundata.getParameters().getInts("access_index");
+
+ if (accessIndexes != null && accessIndexes.length > 0)
+ {
+ ArrayList deleteList = new ArrayList();
+
+ for (int i = 0; i < accessIndexes.length; i++)
+ {
+ int accessIndex = accessIndexes[i];
+ accessIndex--;
+
+ if (accessIndex >= 0
+ && accessIndex < securityEntry.getAccesses().size())
+ {
+
deleteList.add(securityEntry.getAccesses().get(accessIndex));
+ }
+ else
+ {
+ Log.error(
+ "Access Index: " + i + " is out of range");
+ }
+ }
+
+ Iterator deleteIter = deleteList.iterator();
+ while(deleteIter.hasNext())
+ {
+ SecurityAccess sa = (SecurityAccess)deleteIter.next();
+ securityEntry.getAccesses().remove(sa);
+ }
+
+ Registry.addEntry(Registry.SECURITY, securityEntry);
+ clearUserData(rundata);
+ }
+ else
+ {
+ JetspeedLink link =
+ JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_MISSING_PARAMETER);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ else
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_DELETE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+
+ /**
+ * Update a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doAddallow(RunData rundata, Context context) throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+ if (securityEntry != null)
+ {
+ int accessIndex =
+ rundata.getParameters().getInt("access_index", -1);
+ accessIndex--;
+
+ if (accessIndex >= 0
+ && accessIndex < securityEntry.getAccesses().size())
+ {
+ BaseSecurityAccess securityAccess =
+ (BaseSecurityAccess) securityEntry.getAccesses().get(
+ accessIndex);
+ addAllow(rundata, securityAccess);
+ Registry.addEntry(Registry.SECURITY, securityEntry);
+ clearUserData(rundata);
+ }
+ else
+ {
+ JetspeedLink link =
+ JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_MISSING_PARAMETER);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ else
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_UPDATE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+
+ /**
+ * Update a security entry in the registry
+ * @param rundata The turbine rundata context for this request.
+ * @param context The velocity context for this request.
+ * @throws Exception
+ */
+ public void doRemoveallow(RunData rundata, Context context)
+ throws Exception
+ {
+ try
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ BaseSecurityEntry securityEntry =
+ (BaseSecurityEntry) Registry.getEntry(
+ Registry.SECURITY,
+ securityName);
+ if (securityEntry != null)
+ {
+ int accessIndex =
+ rundata.getParameters().getInt("access_index", -1);
+ accessIndex--;
+
+ if (accessIndex >= 0
+ && accessIndex < securityEntry.getAccesses().size())
+ {
+ BaseSecurityAccess securityAccess =
+ (BaseSecurityAccess) securityEntry.getAccesses().get(
+ accessIndex);
+
+ String allowType =
+ rundata.getParameters().getString(
+ "allow_type",
+ "allows");
+ int[] allowIndexes =
+ rundata.getParameters().getInts("allow_index");
+
+ if (allowIndexes != null && allowIndexes.length > 0)
+ {
+ for (int i = 0; i < allowIndexes.length; i++)
+ {
+ int allowIndex = allowIndexes[i];
+ allowIndex--;
+
+ if (allowIndex >= 0)
+ {
+ //TODO: more validation
+ if (allowType.equals("owner"))
+ {
+ securityAccess.getOwnerAllows().remove(
+ allowIndex);
+ }
+ else
+ {
+ securityAccess.getAllows().remove(
+ allowIndex);
+ }
+
+ Registry.addEntry(
+ Registry.SECURITY,
+ securityEntry);
+ clearUserData(rundata);
+ }
+ else
+ {
+ Log.error(
+ "Allow Index: "
+ + allowIndex
+ + " is out of range.");
+ }
+ }
+ }
+ else
+ {
+ JetspeedLink link =
+ JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_MISSING_PARAMETER);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ else
+ {
+ JetspeedLink link =
+ JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_MISSING_PARAMETER);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ else
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_INVALID_ENTITY_NAME);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+ catch (Exception e)
+ {
+ JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
+ DynamicURI duri =
+ link
+ .getPaneByName(SECURITY_UPDATE_PANE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MODE,
+ SecurityConstants.PARAM_MODE_UPDATE)
+ .addPathInfo(
+ SecurityConstants.PARAM_MSGID,
+ SecurityConstants.MID_DELETE_FAILED);
+ JetspeedLinkFactory.putInstance(link);
+ rundata.setRedirectURI(duri.toString());
+ resetForm(rundata);
+ }
+ }
+
+ private void addAllow(RunData rundata, BaseSecurityAccess securityAccess)
+ {
+ String allowType = rundata.getParameters().getString("allow_type");
+ String allowValue = rundata.getParameters().getString("allow_value");
+
+ SecurityAllow allow = null;
+ if (allowType.equals("user"))
+ {
+ allow = new BaseSecurityAllow();
+ allow.setUser(allowValue);
+ securityAccess.getAllows().add(allow);
+ }
+ else if (allowType.equals("role"))
+ {
+ allow = new BaseSecurityAllow();
+ allow.setRole(allowValue);
+
+ securityAccess.getAllows().add(allow);
+ }
+ else if (allowType.equals("owner"))
+ {
+ allow = new BaseSecurityAllowOwner();
+ allow.setOwner(true);
+
+ securityAccess.getOwnerAllows().add(allow);
+ }
+ else
+ {
+ //throw exception?
+ }
+ }
+
+ /**
+ * Clears the temporary storage of any data that was used
+ * @param rundata
+ */
+ private void clearUserData(RunData rundata)
+ {
+ try
+ {
+ rundata.getUser().removeTemp("security_name");
+ rundata.getUser().removeTemp("allow_type");
+ rundata.getUser().removeTemp("allow_value");
+ rundata.getUser().removeTemp("access_index");
+ rundata.getUser().removeTemp("access_action");
+ rundata.getUser().removeTemp("title");
+ rundata.getUser().removeTemp("description");
+ }
+ catch (Exception e)
+ {
+ if (Log.getLogger().isDebugEnabled())
+ {
+ Log.debug("SkinUpdateAction: Failed to clear user data");
+ }
+ }
+ }
+
+ /**
+ * Populates the user's temp storage with form data
+ * @param rundata The turbine rundata context for this request.
+ */
+ private void resetForm(RunData rundata)
+ {
+ String securityName =
+ rundata.getParameters().getString("security_name");
+ String allowType = rundata.getParameters().getString("allow_type");
+ String allowValue = rundata.getParameters().getString("allow_value");
+ String accessIndex = rundata.getParameters().getString("access_index");
+ String accessAction =
+ rundata.getParameters().getString("access_action");
+ String title = rundata.getParameters().getString("title");
+ String description = rundata.getParameters().getString("description");
+
+ rundata.getUser().setTemp("security_name", securityName);
+ rundata.getUser().setTemp("allow_type", allowType);
+ rundata.getUser().setTemp("allow_value", allowValue);
+ rundata.getUser().setTemp("access_index", accessIndex);
+ rundata.getUser().setTemp("access_action", accessAction);
+ rundata.getUser().setTemp("title", title);
+ rundata.getUser().setTemp("description", description);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]