Author: tyrell
Date: Fri Dec 7 04:54:25 2007
New Revision: 10698
Log:
Adding user and role based filtering to the Tasks Panel in the Mashup page.
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
Fri Dec 7 04:54:25 2007
@@ -16,10 +16,15 @@
package org.wso2.mashup.webapp.utils;
import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.MashupFault;
import org.wso2.mashup.utils.QueryResult;
import org.wso2.mashup.utils.QueryResults;
import org.wso2.mashup.webapp.userprofile.User;
-import org.wso2.registry.*;
+import org.wso2.registry.LogEntry;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
import org.wso2.registry.jdbc.JDBCRegistry;
import org.wso2.registry.secure.RegistryUserManager;
import org.wso2.registry.secure.SecureRegistry;
@@ -31,10 +36,11 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Map;
-import java.util.Date;
import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.Map;
public class RegistryUtils {
@@ -78,6 +84,31 @@
return false;
}
+ public static boolean isAdminRole(Registry registry) throws
RegistryException {
+
+ if (registry instanceof SecureRegistry) {
+ SecureRegistry secureRegistry = (SecureRegistry) registry;
+ String[] userRoles = null;
+ try {
+ userRoles =
secureRegistry.getUserManager().getRealm().getUserStoreReader()
+ .getUserRoles(secureRegistry.getUserID());
+ } catch (UserManagerException e) {
+ return false;
+ }
+
+ if(userRoles != null){
+ for (int x = 0; x < userRoles.length; x++) {
+ if
(userRoles[x].equalsIgnoreCase(RegistryConstants.ADMIN_ROLE)) {
+ return true;
+ }
+ }
+ }
+
+ }
+
+ return false;
+ }
+
public static String getCurrentUser(Registry registry) throws
RegistryException {
@@ -89,7 +120,8 @@
return RegistryConstants.ANONYMOUS_USER;
}
- public static RegistryUserManager getRegistryUserManager(Registry
registry) throws RegistryException {
+ public static RegistryUserManager getRegistryUserManager(Registry registry)
+ throws RegistryException {
SecureRegistry secureRegistry = (SecureRegistry) registry;
return secureRegistry.getUserManager();
@@ -102,7 +134,8 @@
* @return User's full name.
* @throws RegistryException
*/
- public static String getCurrentUserFullName(HttpServletRequest request)
throws RegistryException {
+ public static String getCurrentUserFullName(HttpServletRequest request)
+ throws RegistryException {
String currentUserFullName = null;
String currentUser;
@@ -116,7 +149,8 @@
return currentUserFullName;
}
- public static String getFullName(HttpServletRequest request, String
userName) throws RegistryException {
+ public static String getFullName(HttpServletRequest request, String
userName)
+ throws RegistryException {
String fullName = null;
Map userProperties;
@@ -162,7 +196,8 @@
return user;
}
- public static void setUserProfile(String userID, Registry registry, User
user) throws RegistryException {
+ public static void setUserProfile(String userID, Registry registry, User
user)
+ throws RegistryException {
SecureRegistry secureRegistry = (SecureRegistry) registry;
String profilePath = "/users/" + userID + "/profile";
@@ -172,7 +207,8 @@
registry.put(profilePath, userProfile);
}
- public static QueryResults doQuery(Registry registry, String queryHeading,
String queryPath, String[] params, int maxResults)
+ public static QueryResults doQuery(Registry registry, String queryHeading,
String queryPath,
+ String[] params, int maxResults)
throws RegistryException {
String currentUser = getCurrentUser(registry);
@@ -233,25 +269,29 @@
if (logEntry.getAction() == LogEntry.UPDATE) {
if (!logEntry.getResourcePath().contains("/users/")) {
entry = logEntry.getUserName() + " has updated the
resource '" +
- logEntry.getResourcePath() + "' on " +
logEntry.getDate().toString() +
+ logEntry.getResourcePath() + "' on " +
+ logEntry.getDate().toString() +
".";
} else {
continue;
}
} else if (logEntry.getAction() == LogEntry.COMMENT) {
entry = logEntry.getUserName() + " has commented on
resource '" +
- logEntry.getResourcePath() + "' on " +
logEntry.getDate().toString() +
+ logEntry.getResourcePath() + "' on " +
+ logEntry.getDate().toString() +
" with the following comment.<br/>" +
logEntry.getActionData();
} else if (logEntry.getAction() == LogEntry.TAG) {
entry = logEntry.getUserName() + " has tagged the
resource '" +
- logEntry.getResourcePath() + "' with tag '" +
logEntry.getActionData() +
+ logEntry.getResourcePath() + "' with tag '" +
+ logEntry.getActionData() +
"' on " + logEntry.getDate().toString() + ".";
} else if (logEntry.getAction() == LogEntry.RATING) {
entry = logEntry.getUserName() + " has rated the
resource '" +
logEntry.getResourcePath() + "' with rating " +
- logEntry.getActionData() + " on " +
logEntry.getDate().toString() + ".";
+ logEntry.getActionData() + " on " +
logEntry.getDate().toString() +
+ ".";
}
queryResult.setContentString(entry);
@@ -287,8 +327,10 @@
queryResult.setResultType("resource");
queryResult.setPath(resultArtifact.getPath());
queryResult.setDescription(resultArtifact.getDescription());
-
queryResult.setRating(registry.getRating(resultArtifact.getPath(),
currentUser));
-
queryResult.setAverageRating(registry.getAverageRating(resultArtifact.getPath()));
+ queryResult
+
.setRating(registry.getRating(resultArtifact.getPath(), currentUser));
+ queryResult
+
.setAverageRating(registry.getAverageRating(resultArtifact.getPath()));
}
qResults.addResult(queryResult);
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev