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/09 17:48:05 UTC

svn commit: r693492 [1/3] - /portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/

Author: vkumar
Date: Tue Sep  9 08:48:04 2008
New Revision: 693492

URL: http://svn.apache.org/viewvc?rev=693492&view=rev
Log:
Changes for new Security API's

Modified:
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java
    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/UserBrowserPortlet.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/WicketUserAdmin.java
    portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/WicketUserBrowser.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/GroupChooserPortlet.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/GroupChooserPortlet.java?rev=693492&r1=693491&r2=693492&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/GroupChooserPortlet.java Tue Sep  9 08:48:04 2008
@@ -62,7 +62,7 @@
         List resultSetTypeList = new ArrayList();
         try
         {
-            Iterator groups = groupManager.getGroups("");
+            Iterator groups = groupManager.getGroups("").iterator();
                         
             
             resultSetTypeList.add(String.valueOf(Types.VARCHAR));
@@ -74,8 +74,9 @@
             {
                 Group group = (Group)groups.next();
                 
-                Principal principal = group.getPrincipal();                
-                list.add(principal.getName());
+                //Principal principal = group.getPrincipal();                
+                //list.add(principal.getName());
+                list.add(group.getName());
             }            
             
             BrowserIterator iterator = new DatabaseBrowserIterator(

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.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/JetspeedUserBean.java?rev=693492&r1=693491&r2=693492&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java Tue Sep  9 08:48:04 2008
@@ -1,9 +1,9 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
@@ -21,78 +21,70 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
 
 import javax.security.auth.Subject;
 
 import org.apache.jetspeed.security.User;
-import org.apache.jetspeed.security.UserPrincipal;
 
 /**
  * User state.
- *
+ * 
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: JetspeedUserBean.java 348264 2005-11-22 22:06:45Z taylor $
  */
 public class JetspeedUserBean
 {
-    private String principal;    
-    private Map attributes = new LinkedHashMap();
-    
-    public JetspeedUserBean(User user)
-    {
-        Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);             
-        this.principal = userPrincipal.getName();
-        try
-        {
-            Preferences userAttributes = user.getUserAttributes();
-            String[] keys = userAttributes.keys();
-            for (int ix = 0; ix < keys.length; ix++)
-            {
-                attributes.put(keys[ix], userAttributes.get(keys[ix], null));
-            }
-        }
-        catch (BackingStoreException e)
-        {
-        }
-    }
-    
-    /**
-     * @return Returns the principal.
-     */
-    public String getPrincipal()
-    {
-        return principal;
-    }
-    /**
-     * @param principal The principal to set.
-     */
-    public void setPrincipal(String principal)
-    {
-        this.principal = principal;
-    }
-    
-    public Principal createPrincipal(Subject subject, Class classe)
-    {
-        Principal principal = null;
-        Iterator principals = subject.getPrincipals().iterator();
-        while (principals.hasNext())
-        {
-            Principal p = (Principal) principals.next();
-            if (classe.isInstance(p))
-            {
-                principal = p;
-                break;
-            }
-        }
-        return principal;
-    }
-    
-    /**
-     * @return Returns the attributes.
-     */
-    public Map getAttributes()
-    {
-        return attributes;
-    }
+	private String principal;
+	private Map attributes = new LinkedHashMap();
+
+	public JetspeedUserBean(User user)
+	{
+		// Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);
+		this.principal = user.getName();
+
+		// Preferences userAttributes = user.getUserAttributes();
+		Map<String, String> userAttributes = user.getInfoMap();
+		attributes.putAll(userAttributes);
+	}
+
+	/**
+	 * @return Returns the principal.
+	 */
+	public String getPrincipal()
+	{
+		return principal;
+	}
+
+	/**
+	 * @param principal
+	 *            The principal to set.
+	 */
+	public void setPrincipal(String principal)
+	{
+		this.principal = principal;
+	}
+
+	public Principal createPrincipal(Subject subject, Class classe)
+	{
+		Principal principal = null;
+		Iterator principals = subject.getPrincipals().iterator();
+		while (principals.hasNext())
+		{
+			Principal p = (Principal) principals.next();
+			if (classe.isInstance(p))
+			{
+				principal = p;
+				break;
+			}
+		}
+		return principal;
+	}
+
+	/**
+	 * @return Returns the attributes.
+	 */
+	public Map getAttributes()
+	{
+		return attributes;
+	}
 }
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.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/RoleChooserPortlet.java?rev=693492&r1=693491&r2=693492&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/RoleChooserPortlet.java Tue Sep  9 08:48:04 2008
@@ -62,7 +62,7 @@
         List resultSetTypeList = new ArrayList();
         try
         {
-            Iterator roles = roleManager.getRoles("");
+            Iterator roles = roleManager.getRoles("").iterator();
                         
             
             resultSetTypeList.add(String.valueOf(Types.VARCHAR));
@@ -74,8 +74,9 @@
             {
                 Role role = (Role)roles.next();
                 
-                Principal principal = role.getPrincipal();                
-                list.add(principal.getName());
+                //Principal principal = role.getPrincipal();                
+                //list.add(principal.getName());
+                list.add(role.getName());
             }            
             BrowserIterator iterator = new DatabaseBrowserIterator(
                     list, resultSetTitleList, resultSetTypeList,

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=693492&r1=693491&r2=693492&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 Tue Sep  9 08:48:04 2008
@@ -16,35 +16,34 @@
 */
 package org.apache.jetspeed.portlets.security.users;
 
-import java.io.IOException;
-import java.security.Principal;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-import javax.portlet.PortletMode;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.security.auth.Subject;
-
-import org.apache.jetspeed.CommonPortletServices;
-import org.apache.jetspeed.portlets.security.SecurityResources;
-import org.apache.jetspeed.portlets.security.SecurityUtil;
-import org.apache.jetspeed.security.SecurityException;
-import org.apache.jetspeed.security.User;
-import org.apache.jetspeed.security.UserManager;
-import org.apache.jetspeed.security.UserPrincipal;
-import org.apache.portals.gems.browser.BrowserIterator;
-import org.apache.portals.gems.browser.BrowserPortlet;
-import org.apache.portals.gems.browser.DatabaseBrowserIterator;
-import org.apache.portals.gems.util.StatusMessage;
-import org.apache.portals.messaging.PortletMessaging;
-import org.apache.velocity.context.Context;
+import java.io.IOException;
+import java.security.Principal;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.security.auth.Subject;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.portlets.security.SecurityResources;
+import org.apache.jetspeed.portlets.security.SecurityUtil;
+import org.apache.jetspeed.security.SecurityException;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.BrowserPortlet;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import org.apache.portals.gems.util.StatusMessage;
+import org.apache.portals.messaging.PortletMessaging;
+import org.apache.velocity.context.Context;
 
 /**
  * Role Browser - flat non-hierarchical view
@@ -159,13 +158,14 @@
                 {
                     // NOTE: this can be a bit costly if you have a lot of users in a role
                     User user = (User)users.next();
-                    Principal pr = getBestPrincipal(user.getSubject(), UserPrincipal.class);
-                    list.add(pr.getName());
+                    //Principal pr = getBestPrincipal(user.getSubject(), UserPrincipal.class);
+                    //list.add(pr.getName());
+                    list.add(user.getName());
                 }                            
             }
             else
             {
-                Iterator users = userManager.getUserNames(filter);
+                Iterator users = userManager.getUserNames(filter).iterator();
                 while (users.hasNext())
                 {
                     list.add(users.next());

Modified: portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.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/UserBrowserPortlet.java?rev=693492&r1=693491&r2=693492&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java (original)
+++ portals/jetspeed-2/applications/j2-admin/branches/security-refactoring/src/main/java/org/apache/jetspeed/portlets/security/users/UserBrowserPortlet.java Tue Sep  9 08:48:04 2008
@@ -38,12 +38,12 @@
 import org.apache.jetspeed.portlets.tags.TreeControl;
 import org.apache.jetspeed.portlets.tags.TreeControlNode;
 import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.security.PasswordCredential;
 import org.apache.jetspeed.security.Role;
 import org.apache.jetspeed.security.RoleManager;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
-import org.apache.jetspeed.security.UserPrincipal;
 import org.apache.portals.bridges.common.GenericServletPortlet;
 import org.apache.portals.messaging.PortletMessaging;
 
@@ -133,7 +133,7 @@
         {
             if (control == null)
             {
-                Iterator users = userManager.getUsers(USER_FILTER);
+                Iterator users = userManager.getUsers(USER_FILTER).iterator();
                 control = buildTree(users, request.getLocale());
                 request.getPortletSession().setAttribute(TREE_CONTROL, control);
             }
@@ -158,11 +158,12 @@
             if (roles == null)
             {
                 roles = new LinkedList();
-                Iterator fullRoles = roleManager.getRoles("");
+                Iterator fullRoles = roleManager.getRoles("").iterator();
                 while (fullRoles.hasNext())
                 {
                     Role role = (Role)fullRoles.next();
-                    roles.add(role.getPrincipal().getName());
+                    //roles.add(role.getPrincipal().getName());
+                    roles.add(role.getName());
                 }
                 request.getPortletSession().setAttribute(ROLES_CONTROL, roles);
             }
@@ -214,9 +215,13 @@
             {
                 try
                 {            
-                    userManager.addUser(userName, password);
+                    //userManager.addUser(userName, password);
+                	User tmpUser = userManager.addUser(userName);
+                	PasswordCredential credential = userManager.getPasswordCredential(tmpUser);
+                	credential.setPassword(null,password);
+                	userManager.storePasswordCredential(credential);
                     TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute(TREE_CONTROL);
-                    Iterator users = userManager.getUsers(USER_FILTER);
+                    Iterator users = userManager.getUsers(USER_FILTER).iterator();
                     control = buildTree(users, actionRequest.getLocale());
                     actionRequest.getPortletSession().setAttribute(TREE_CONTROL, control);
                     selectNode(actionRequest, control, userName);
@@ -231,8 +236,9 @@
                     String rule = actionRequest.getParameter(RULES_CONTROL);
                     if (!isEmpty(rule) && user != null) 
                     {
-                        Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);                         
-                        profiler.setRuleForPrincipal(principal, profiler.getRule(rule), "page");
+                    	
+                    	//Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);                         
+                        profiler.setRuleForPrincipal(user, profiler.getRule(rule), "page");
                     }
                     
                 }
@@ -312,9 +318,9 @@
         while (users.hasNext())
         {
             User user = (User) users.next();
-            Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);
+            //Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);
 
-            TreeControlNode userNode = new TreeControlNode(principal.getName(), null, principal.getName(),
+            TreeControlNode userNode = new TreeControlNode(user.getName(), null, user.getName(),
                     SecurityResources.PORTLET_URL, null, false, USER_DETAIL_DOMAIN);
             userTree.addChild(userNode);
         }

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=693492&r1=693491&r2=693492&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 Tue Sep  9 08:48:04 2008
@@ -16,23 +16,21 @@
 */
 package org.apache.jetspeed.portlets.security.users;
 
-import java.security.Principal;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-import javax.portlet.RenderRequest;
-
-import org.apache.jetspeed.CommonPortletServices;
-import org.apache.jetspeed.portlets.security.SecurityUtil;
-import org.apache.jetspeed.security.User;
-import org.apache.jetspeed.security.UserManager;
-import org.apache.jetspeed.security.UserPrincipal;
-import org.apache.portals.gems.browser.BrowserIterator;
-import org.apache.portals.gems.browser.DatabaseBrowserIterator;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletException;
+import javax.portlet.RenderRequest;
+
+import org.apache.jetspeed.CommonPortletServices;
+import org.apache.jetspeed.portlets.security.SecurityUtil;
+import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserManager;
+import org.apache.portals.gems.browser.BrowserIterator;
+import org.apache.portals.gems.browser.DatabaseBrowserIterator;
 
 /**
  * SSOBrowser
@@ -63,7 +61,7 @@
         List resultSetTypeList = new ArrayList();
         try
         {
-            Iterator users = userManager.getUsers("");
+            Iterator users = userManager.getUsers("").iterator();
                         
             
             resultSetTypeList.add(String.valueOf(Types.VARCHAR));
@@ -74,9 +72,9 @@
             while (users.hasNext())
             {
                 User user = (User)users.next();
-                Principal principal = getPrincipal(user.getSubject(),
-                        UserPrincipal.class);                
-                list.add(principal.getName());
+                //Principal principal = getPrincipal(user.getSubject(),UserPrincipal.class);                
+                //list.add(principal.getName());
+                list.add(user.getName());                
             }            
             BrowserIterator iterator = new DatabaseBrowserIterator(
                     list, resultSetTitleList, resultSetTypeList,



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