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 ta...@apache.org on 2004/09/16 08:36:09 UTC

cvs commit: jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users TabbedPaneBean.java UserData.java UserManagerPortlet.java

taylor      2004/09/15 23:36:09

  Modified:    applications/pam/src/java/org/apache/jetspeed/portlets/security/users
                        UserData.java UserManagerPortlet.java
  Added:       applications/pam/src/java/org/apache/jetspeed/portlets/security/users
                        TabbedPaneBean.java
  Log:
  user management continued, added basics for tabbed data entry
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.2       +64 -3     jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserData.java
  
  Index: UserData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UserData.java	15 Sep 2004 22:43:07 -0000	1.1
  +++ UserData.java	16 Sep 2004 06:36:09 -0000	1.2
  @@ -1,9 +1,23 @@
   package org.apache.jetspeed.portlets.security.users;
   
  +import java.security.Principal;
  +import java.util.Iterator;
  +
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
  +import javax.security.auth.Subject;
  +
  +import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
  +import org.apache.jetspeed.security.User;
  +import org.apache.jetspeed.security.UserManager;
  +import org.apache.jetspeed.security.UserPrincipal;
  +import org.apache.jetspeed.services.JetspeedPortletServices;
  +import org.apache.jetspeed.services.PortletServices;
  +
   
   public class UserData
   {
  -    private static final UserBean[] users = new UserBean[]     
  +    private static final UserBean[] xusers = new UserBean[]     
       { 
               new UserBean("Taylor", "David"),
               new UserBean("Weaver", "Scott"),
  @@ -12,6 +26,53 @@
       
       public UserBean[] getUsers()
       {
  -        return users;
  +        try
  +        {
  +            //Context ctx = new InitialContext();
  +            //UserManager userManager = (UserManager)ctx.lookup("java:comp/UserManager");
  +            PortletServices services = JetspeedPortletServices.getSingleton();
  +            UserManager userManager = 
  +                (UserManager)services.getService("UserManager");
  +            
  +            if (userManager == null)
  +            {
  +                return xusers;
  +            }
  +            UserBean[] xu = new UserBean[10];
  +            Iterator it = userManager.getUsers("");
  +            int ix = 0;
  +            while (it.hasNext())
  +            {
  +                User user = (User)it.next();
  +                Principal princ = getPrincipal(user.getSubject(), UserPrincipal.class);
  +                UserBean bean  = new UserBean(princ.getName(), princ.getName());
  +                xu[ix] = bean;
  +                ix++;
  +                //preferences.node(userinfo)
  +            }
  +            return xu;
  +        }
  +        catch (Exception e)
  +        { 
  +            e.printStackTrace();
  +        }
  +        return xusers;
       }
  -}
  \ No newline at end of file
  +    
  +    public Principal getPrincipal(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;
  +    }
  +    
  +}
  
  
  
  1.2       +22 -1     jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java
  
  Index: UserManagerPortlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UserManagerPortlet.java	15 Sep 2004 22:43:07 -0000	1.1
  +++ UserManagerPortlet.java	16 Sep 2004 06:36:09 -0000	1.2
  @@ -16,8 +16,11 @@
   package org.apache.jetspeed.portlets.security.users;
   
   import java.security.Principal;
  +import java.util.Hashtable;
   import java.util.Iterator;
   
  +import javax.naming.Context;
  +import javax.naming.InitialContext;
   import javax.portlet.PortletConfig;
   import javax.portlet.PortletContext;
   import javax.portlet.PortletException;
  @@ -29,6 +32,9 @@
   import org.apache.jetspeed.security.UserPrincipal;
   import org.apache.portals.bridges.myfaces.FacesPortlet;
   
  +import tyrex.naming.MemoryContext;
  +import tyrex.tm.RuntimeContext;
  +
   
   /**
    * Provides maintenance capabilities for User Administration.
  @@ -60,6 +66,21 @@
               Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);             
               System.out.println("principal = " + principal.getName());
           }
  +        try
  +        {
  +            Hashtable env = new Hashtable();
  +            env.put(Context.INITIAL_CONTEXT_FACTORY, "tyrex.naming.MemoryContextFactory");
  +            Context root = new MemoryContext(null);                                   
  +            Context ctx = root.createSubcontext("comp");
  +            ctx.bind("UserManager", userManager); 
  +            RuntimeContext runCtx = RuntimeContext.newRuntimeContext(root, null);
  +            RuntimeContext.setRuntimeContext(runCtx);            
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();            
  +        }
  +        
       }
       
       public Principal getPrincipal(Subject subject, Class classe)
  
  
  
  1.1                  jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/TabbedPaneBean.java
  
  Index: TabbedPaneBean.java
  ===================================================================
  package org.apache.jetspeed.portlets.security.users;
  
  import java.io.Serializable;
  
  public class TabbedPaneBean
          implements Serializable
  {
      //private static final Log log = LogFactory.getLog(TabbedPaneBean.class);
  
      private boolean _tab1Visible = true;
      private boolean _tab2Visible = true;
      private boolean _tab3Visible = true;
  
      public boolean isTab1Visible()
      {
          return _tab1Visible;
      }
  
      public void setTab1Visible(boolean tab1Visible)
      {
          _tab1Visible = tab1Visible;
      }
  
      public boolean isTab2Visible()
      {
          return _tab2Visible;
      }
  
      public void setTab2Visible(boolean tab2Visible)
      {
          _tab2Visible = tab2Visible;
      }
  
      public boolean isTab3Visible()
      {
          return _tab3Visible;
      }
  
      public void setTab3Visible(boolean tab3Visible)
      {
          _tab3Visible = tab3Visible;
      }
  }
  
  
  

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