You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by vk...@apache.org on 2008/09/10 14:15:27 UTC

svn commit: r693812 - /portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/

Author: vkumar
Date: Wed Sep 10 05:15:26 2008
New Revision: 693812

URL: http://svn.apache.org/viewvc?rev=693812&view=rev
Log:
Optimizing portlet functionality with  new security API's

Modified:
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserAdd.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java?rev=693812&r1=693811&r2=693812&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowser.java Wed Sep 10 05:15:26 2008
@@ -165,12 +165,7 @@
             }
             else
             {
-                Iterator users = userManager.getUserNames(filter).iterator();
-                while (users.hasNext())
-                {
-                    list.add(users.next());
-                }            
-                
+            	list = userManager.getUserNames(filter);                            
             }                            
         }
         catch (SecurityException sex)

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java?rev=693812&r1=693811&r2=693812&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserChooserPortlet.java Wed Sep 10 05:15:26 2008
@@ -61,21 +61,8 @@
         List resultSetTypeList = new ArrayList();
         try
         {
-            Iterator users = userManager.getUsers("").iterator();
-                        
+            List list = userManager.getUserNames("");
             
-            resultSetTypeList.add(String.valueOf(Types.VARCHAR));
-            resultSetTitleList.add("User");
-
-            // TODO: need to try to normalize List/Collection/Iterators
-            List list = new ArrayList();
-            while (users.hasNext())
-            {
-                User user = (User)users.next();
-                //Principal principal = getPrincipal(user.getSubject(),UserPrincipal.class);                
-                //list.add(principal.getName());
-                list.add(user.getName());                
-            }            
             BrowserIterator iterator = new DatabaseBrowserIterator(
                     list, resultSetTitleList, resultSetTypeList,
                     windowSize);

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java?rev=693812&r1=693811&r2=693812&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserDetailsPortlet.java Wed Sep 10 05:15:26 2008
@@ -59,6 +59,10 @@
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.profiler.rules.PrincipalRule;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.AttributeAlreadyExistsException;
+import org.apache.jetspeed.security.AttributeTypeAlreadyDefinedException;
+import org.apache.jetspeed.security.AttributesNotExtendableException;
+import org.apache.jetspeed.security.AttributesReadOnlyException;
 import org.apache.jetspeed.security.Group;
 import org.apache.jetspeed.security.GroupManager;
 import org.apache.jetspeed.security.InvalidNewPasswordException;
@@ -67,6 +71,7 @@
 import org.apache.jetspeed.security.PasswordCredential;
 import org.apache.jetspeed.security.Role;
 import org.apache.jetspeed.security.RoleManager;
+import org.apache.jetspeed.security.SecurityAttributeType;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
@@ -262,14 +267,7 @@
 				{
 					if (roles == null)
 					{
-						roles = new LinkedList();
-						Iterator fullRoles = roleManager.getRoles("").iterator();
-						while (fullRoles.hasNext())
-						{
-							Role role = (Role) fullRoles.next();
-							// roles.add(role.getPrincipal().getName());
-							roles.add(role.getName());
-						}
+						roles = roleManager.getRoleNames("");
 						request.getPortletSession().setAttribute(ROLES_CONTROL, roles);
 					}
 				}
@@ -309,13 +307,7 @@
 				{
 					if (groups == null)
 					{
-						groups = new LinkedList();
-						Iterator fullGroups = groupManager.getGroups("").iterator();
-						while (fullGroups.hasNext())
-						{
-							Group group = (Group) fullGroups.next();
-							groups.add(group.getName());
-						}
+						groups = groupManager.getGroupNames("");
 						request.getPortletSession().setAttribute(GROUPS_CONTROL, groups);
 					}
 				}
@@ -794,7 +786,27 @@
 				value = actionRequest.getParameter("attr_" + attr.getName());
 				if (value != null)
 				{
-					user.getInfoMap().put(attr.getName(), value);
+					try
+					{
+						user.getSecurityAttributes().addNewInfoAttribute(attr.getName(),SecurityAttributeType.DataType.STRING).setStringValue(value);
+					}
+					catch (AttributesReadOnlyException aroe)
+					{
+						SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"ReadOnly expecton");
+					}
+					catch (AttributeTypeAlreadyDefinedException e)
+					{
+						SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"Alreadydefined expecton");
+					}
+					catch (AttributeAlreadyExistsException e)
+					{
+						SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"AlreadyExits expecton");
+					}
+					catch (AttributesNotExtendableException e)
+					{
+						SecurityUtil.publishErrorMessage(actionRequest, SecurityResources.TOPIC_USER,"NotExtendable expecton");
+					}
+					//user.getInfoMap().put(attr.getName(), value);
 					audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
 							AuditActivity.USER_ADD_ATTRIBUTE, attr.getName(), value, value, USER_ADMINISTRATION);
 				}
@@ -820,7 +832,7 @@
 					String userAttrName = userAttrNames[i];
 					String value = actionRequest.getParameter(userAttrName + ":value");
 					String before = user.getInfoMap().get(userAttrName);
-					user.getInfoMap().put(userAttrName, value);
+					user.getSecurityAttributes().getAttribute(userAttrName).setStringValue(value);
 					audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
 							AuditActivity.USER_UPDATE_ATTRIBUTE, userAttrName, before, value, USER_ADMINISTRATION);
 				}
@@ -828,7 +840,7 @@
 		}
 	}
 
-	private void addUserAttribute(ActionRequest actionRequest, ActionResponse actionResponse)
+	private void addUserAttribute(ActionRequest actionRequest, ActionResponse actionResponse) 
 	{
 		String userName = (String) PortletMessaging.receive(actionRequest, SecurityResources.TOPIC_USERS, SecurityResources.MESSAGE_SELECTED);
 		User user = lookupUser(actionRequest, userName);
@@ -839,6 +851,30 @@
 			if (userAttrName != null && userAttrName.trim().length() > 0)
 			{
 				Map<String,String> attributes = user.getInfoMap();
+				try
+				{
+					user.getSecurityAttributes().addNewInfoAttribute(userAttrName, SecurityAttributeType.DataType.STRING).setStringValue(userAttrValue);
+				}
+				catch (AttributesReadOnlyException e)
+				{
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				catch (AttributeTypeAlreadyDefinedException e)
+				{
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				catch (AttributeAlreadyExistsException e)
+				{
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+				catch (AttributesNotExtendableException e)
+				{
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
 				attributes.put(userAttrName, userAttrValue);
 				audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
 						AuditActivity.USER_ADD_ATTRIBUTE, userAttrName, "", userAttrValue, USER_ADMINISTRATION);
@@ -864,7 +900,7 @@
 					try
 					{
 						String before = userAttributes.get(userAttrNames[ix]);
-						userAttributes.remove(userAttrNames[ix]);
+						user.getSecurityAttributes().removeAttribute(userAttrNames[ix]);						
 						audit.logAdminAttributeActivity(actionRequest.getUserPrincipal().getName(), getIPAddress(actionRequest), userName,
 								AuditActivity.USER_DELETE_ATTRIBUTE, userAttrNames[ix], before, "", USER_ADMINISTRATION);
 					}

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java?rev=693812&r1=693811&r2=693812&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java Wed Sep 10 05:15:26 2008
@@ -28,6 +28,7 @@
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
+import org.apache.portals.bridges.jsf.FacesPortlet;
 
 /**
  * Provides maintenance capabilities for User Administration.

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserAdd.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserAdd.java?rev=693812&r1=693811&r2=693812&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserAdd.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserAdd.java Wed Sep 10 05:15:26 2008
@@ -150,20 +150,17 @@
         CheckBox changePasswordRequiredOnFirstLoginField = new CheckBox("jetspeedChangePasswordRequiredOnFirstLogin", new PropertyModel(this, "changePasswordRequiredOnFirstLogin"));
         userAddForm.add(changePasswordRequiredOnFirstLoginField);
         
-        List roles = new LinkedList();
+        List<String> roles = null;
         
         try
         {
-            for (Iterator it = getRoleManager().getRoles("").iterator(); it.hasNext(); )
-            {
-                Role role = (Role) it.next();
-                roles.add(role.getName());
-            }
+        	 roles = getRoleManager().getRoleNames("");
         }
         catch (SecurityException e)
         {
             SecurityUtil.publishErrorMessage(getPortletRequest(), SecurityResources.TOPIC_USERS, e.getMessage());
-        }                                    
+        }    
+               
         
         DropDownChoice roleField = new DropDownChoice("jetspeedRole", new PropertyModel(this, "role"), roles);
         userAddForm.add(roleField);

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java?rev=693812&r1=693811&r2=693812&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserDetails.java Wed Sep 10 05:15:26 2008
@@ -40,12 +40,17 @@
 import org.apache.jetspeed.portlets.wicket.component.TextFieldPropertyColumn;
 import org.apache.jetspeed.profiler.rules.PrincipalRule;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.security.AttributeAlreadyExistsException;
+import org.apache.jetspeed.security.AttributeTypeAlreadyDefinedException;
+import org.apache.jetspeed.security.AttributesNotExtendableException;
+import org.apache.jetspeed.security.AttributesReadOnlyException;
 import org.apache.jetspeed.security.Group;
 import org.apache.jetspeed.security.InvalidNewPasswordException;
 import org.apache.jetspeed.security.InvalidPasswordException;
 import org.apache.jetspeed.security.PasswordAlreadyUsedException;
 import org.apache.jetspeed.security.PasswordCredential;
 import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.SecurityAttributeType;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.User;
 import org.apache.portals.messaging.PortletMessaging;
@@ -402,7 +407,30 @@
                     {
                         //Preferences prefs = user.getUserAttributes();
                         //prefs.put(userAttrName, userAttrValue);
-                    	user.getInfoMap().put(userAttrName, userAttrValue);
+                    	try
+						{
+							user.getSecurityAttributes().addNewInfoAttribute(userAttrName,SecurityAttributeType.DataType.STRING).setStringValue(userAttrValue);
+						}
+						catch (AttributesReadOnlyException e)
+						{
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
+						catch (AttributeTypeAlreadyDefinedException e)
+						{
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
+						catch (AttributeAlreadyExistsException e)
+						{
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
+						catch (AttributesNotExtendableException e)
+						{
+							// TODO Auto-generated catch block
+							e.printStackTrace();
+						}
                         getAuditActivity().logAdminAttributeActivity(getPortletRequest().getUserPrincipal().getName(), getIPAddress(), getUserName(), AuditActivity.USER_ADD_ATTRIBUTE, userAttrName, "", userAttrValue, USER_ADMINISTRATION);                                                
                     }
                     



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org