Author: chathura
Date: Mon Jan 14 09:30:20 2008
New Revision: 12225
Log:
AJAXifying permission settings UI.
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/PermissionUtil.java
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
trunk/registry/modules/webapps/src/main/webapp/admin/permisions.jsp
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
Mon Jan 14 09:30:20 2008
@@ -196,18 +196,26 @@
} else if (command.equals("/authorize/mass")) {
- MassAuthorizationAction massAuthorizationAction = new
MassAuthorizationAction();
- massAuthorizationAction.setResourcePath(path);
-
massAuthorizationAction.setPermissionString(request.getParameter("permissionInput"));
-
try {
- massAuthorizationAction.execute(request);
+ PermissionUtil.applyMassUserPermissions(request, response);
} catch (RegistryException e) {
+ // todo: implement a general AJAX error segment
setErrorMessage(request, e.getMessage());
- e.printStackTrace();
+ forwardToResources(request, response, path);
}
- response.sendRedirect("/wso2registry/web" + path);
+ //MassAuthorizationAction massAuthorizationAction = new
MassAuthorizationAction();
+ //massAuthorizationAction.setResourcePath(path);
+
//massAuthorizationAction.setPermissionString(request.getParameter("permissionInput"));
+ //
+ //try {
+ // massAuthorizationAction.execute(request);
+ //} catch (RegistryException e) {
+ // setErrorMessage(request, e.getMessage());
+ // e.printStackTrace();
+ //}
+ //
+ //response.sendRedirect("/wso2registry/web" + path);
//forwardToResources(request, response, path);
} else if (command.equals("/authorizeRole")) {
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/UIConstants.java
Mon Jan 14 09:30:20 2008
@@ -52,6 +52,7 @@
public static final String USER_JSP = "/admin/user.jsp";
public static final String VERSIONS_JSP = "/admin/versions.jsp";
public static final String AJAX_RATING_JSP = "/admin/ajax_rating.jsp";
+ public static final String AJAX_PERMISSIONS_JSP = "/admin/permisions.jsp";
public static final String AJAX_DESCRIPTION_JSP = "/admin/ajax_desc.jsp";
public static final String AJAX_PROPERTIES_JSP =
"/admin/ajax/resource-properties.jsp";
public static final String RESOURCE_DETAILS_JSP =
"/admin/resources_details.jsp";
Added:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/PermissionUtil.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/PermissionUtil.java
Mon Jan 14 09:30:20 2008
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.web.utils;
+
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.ActionConstants;
+import org.wso2.registry.web.actions.ResourceDetailsAction;
+import org.wso2.registry.web.UIConstants;
+import org.wso2.usermanager.Realm;
+import org.wso2.usermanager.AccessControlAdmin;
+import org.wso2.usermanager.UserManagerException;
+import org.wso2.usermanager.UserManagerConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+
+public class PermissionUtil {
+
+ public static void applyMassUserPermissions(
+ HttpServletRequest request, HttpServletResponse response)
+ throws RegistryException, ServletException, IOException {
+
+ String permissionString = request.getParameter("permissionInput");
+ String resourcePath = request.getParameter("resourcePath");
+
+ SecureRegistry secureRegistry = CommonUtil.getUserRegistry(request);
+ Realm realm = secureRegistry.getUserRealm();
+
+ AccessControlAdmin accessControlAdmin = null;
+ try {
+ accessControlAdmin = realm.getAccessControlAdmin();
+ } catch (UserManagerException e) {
+ String msg = "Couldn't get access control admin for changing
authorizations. Caused by: " + e.getMessage();
+ throw new RegistryException(msg);
+ }
+
+ try {
+
+ String[] userPermissions = permissionString.split("1");
+ for (int i = 0; i < userPermissions.length; i++) {
+
+ if (userPermissions[i].trim().length() == 0) {
+ continue;
+ }
+
+ String[] permissions = userPermissions[i].split("2");
+ String permUser = permissions[0];
+
+ if (!(permUser.equals(RegistryConstants.SYSTEM_USER) ||
+ permUser.equals(RegistryConstants.ADMIN_USER))) {
+
+ accessControlAdmin.clearUserAuthorization(permUser,
resourcePath, ActionConstants.GET);
+ accessControlAdmin.clearUserAuthorization(permUser,
resourcePath, ActionConstants.PUT);
+ accessControlAdmin.clearUserAuthorization(permUser,
resourcePath, ActionConstants.DELETE);
+ accessControlAdmin.clearUserAuthorization(permUser,
resourcePath, UserManagerConstants.AUTHORIZE);
+ }
+
+ for (int j = 1; j < permissions.length; j++) {
+ String[] permission = permissions[j].split("3");
+
+ String action = permission[0];
+ String checked = permission[1];
+
+ if (action.equals("ra")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.authorizeUser(permUser,
resourcePath, ActionConstants.GET);
+ }
+ } else if (action.equals("rd")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.denyUser(permUser,
resourcePath, ActionConstants.GET);
+ }
+ } else if (action.equals("wa")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.authorizeUser(permUser,
resourcePath, ActionConstants.PUT);
+ }
+ } else if (action.equals("wd")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.denyUser(permUser,
resourcePath, ActionConstants.PUT);
+ }
+ } else if (action.equals("da")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.authorizeUser(permUser,
resourcePath, ActionConstants.DELETE);
+ }
+ } else if (action.equals("dd")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.denyUser(permUser,
resourcePath, ActionConstants.DELETE);
+ }
+ } else if (action.equals("aa")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.authorizeUser(permUser,
resourcePath, UserManagerConstants.AUTHORIZE);
+ }
+ } else if (action.equals("ad")) {
+ if (checked.equals("true")) {
+ accessControlAdmin.denyUser(permUser,
resourcePath, UserManagerConstants.AUTHORIZE);
+ }
+ }
+ }
+ }
+ } catch (UserManagerException e) {
+ String msg = "Couldn't set authorizations. Caused by: " +
e.getMessage();
+ throw new RegistryException(msg);
+ }
+
+ ResourceDetailsAction resourceDetailsAction = new
ResourceDetailsAction();
+ resourceDetailsAction.setPath(resourcePath);
+ resourceDetailsAction.execute(request);
+
+ request.getSession().setAttribute(UIConstants.RESOURCE_BEAN,
resourceDetailsAction);
+
request.getRequestDispatcher(UIConstants.AJAX_PERMISSIONS_JSP).forward(request,
response);
+ }
+}
Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js Mon Jan
14 09:30:20 2008
@@ -98,7 +98,7 @@
}
-function processPermissions()
+function processPermissions(resourcePath)
{
var pForm = document.forms["permissions"];
var len = pForm.elements.length;
@@ -118,8 +118,10 @@
}
}
- document.getElementById("pInput").value = msgBody;
- pForm.submit();
+ //document.getElementById("pInput").value = msgBody;
+ //pForm.submit();
+
+ new Ajax.Updater('perExpanded', '/wso2registry/system/authorize/mass', {
method: 'post', parameters: {permissionInput: msgBody, resourcePath:
resourcePath} });
}
function processRolePermissions()
Modified: trunk/registry/modules/webapps/src/main/webapp/admin/permisions.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/permisions.jsp
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/permisions.jsp Mon Jan
14 09:30:20 2008
@@ -10,10 +10,10 @@
<div id="userPermisionsDiv" class="userPermisionsDiv leftSpace">
<h4>Add New Permissions</h4>
+<form action="/wso2registry/system/authorize" theme="simple" method="post">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
- <form action="/wso2registry/system/authorize" theme="simple"
method="post">
- <input type="hidden" name="pathToAuthorize" value="%{path}"/>
+ <input type="hidden" name="pathToAuthorize"
value="<%=resource.getPath()%>"/>
<td>User</td>
<td>
<select name="userToAuthorize">
@@ -41,13 +41,13 @@
<input type="radio" name="permissionType" value="1" />Allow
<input type="radio" name="permissionType" value="2" />Deny
</td>
<td align="right"><input type="submit" class="button" value="Add
Permision"/></td>
- </form>
</tr>
</table>
+</form>
<h4 style="margin-top:10px;">Defined User Permissions</h4>
-<form name="permissions" action="/wso2registry/system/authorize/mass"
theme="simple" method="post">
+<form name="permissions" theme="simple" method="post">
<input type="hidden" id="pInput" name="permissionInput" value=""/>
- <input type="hidden" name="pathToAuthorize" value="%{path}"/>
+ <input type="hidden" name="pathToAuthorize"
value="<%=resource.getPath()%>"/>
<table width="100%" class="data-table" border="0" cellpadding="3"
cellspacing="0">
<tr >
<th rowspan="2" align="left" style="width:120px;" >User Name </th>
@@ -86,7 +86,7 @@
</tr>
<% } %>
<tr>
- <td colspan="7" align="right"><input type="submit" class="button"
value="Apply All Permissions" onclick="processPermissions();"
style="margin-top:5px; float:right;" /><span style="clear:both;" /></td>
+ <td colspan="7" align="right"><input type="button" class="button"
value="Apply All Permissions"
onclick="processPermissions('<%=resource.getPath()%>');" style="margin-top:5px;
float:right;" /><span style="clear:both;" /></td>
</tr>
</table>
</form>
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev