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 00:43:07 UTC

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

taylor      2004/09/15 15:43:07

  Added:       applications/pam/src/java/org/apache/jetspeed/portlets/security/users
                        UserData.java UserBean.java UserManagerPortlet.java
  Log:
  user manager portlet (start of)
  
  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.1                  jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserData.java
  
  Index: UserData.java
  ===================================================================
  package org.apache.jetspeed.portlets.security.users;
  
  
  public class UserData
  {
      private static final UserBean[] users = new UserBean[]     
      { 
              new UserBean("Taylor", "David"),
              new UserBean("Weaver", "Scott"),
              new UserBean("Ford", "Jeremy")
      };
      
      public UserBean[] getUsers()
      {
          return users;
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserBean.java
  
  Index: UserBean.java
  ===================================================================
  package org.apache.jetspeed.portlets.security.users;
  
  
  public class UserBean
  {
      private String first;
      private String last;
      
      public UserBean(String first, String last)
      {
          this.first = first;
          this.last = last;
      }
      
      public void setFirst(String first)
      {
          this.first = first;
      }
  
      
      /**
       * @return Returns the last.
       */
      public String getLast()
      {
          return last;
      }
      /**
       * @param last The last to set.
       */
      public void setLast(String last)
      {
          this.last = last;
      }
      /**
       * @return Returns the first.
       */
      public String getFirst()
      {
          return first;
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/UserManagerPortlet.java
  
  Index: UserManagerPortlet.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * 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.apache.jetspeed.portlets.security.users;
  
  import java.security.Principal;
  import java.util.Iterator;
  
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletContext;
  import javax.portlet.PortletException;
  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.portals.bridges.myfaces.FacesPortlet;
  
  
  /**
   * Provides maintenance capabilities for User Administration.
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: UserManagerPortlet.java,v 1.1 2004/09/15 22:43:07 taylor Exp $
   */
  public class UserManagerPortlet extends FacesPortlet
  {
      private PortletContext context;
      private UserManager userManager;
      
      public void init(PortletConfig config)
      throws PortletException 
      {
          super.init(config);
          context = getPortletContext();                
          userManager = (UserManager)context.getAttribute(PortletApplicationResources.CPS_USERMANAGER_COMPONENT);
          if (null == userManager)
          {
              throw new PortletException("Failed to find the User Manager on portlet initialization");
          }
          System.out.println("user manager = " + userManager);
          Iterator users = userManager.getUsers("");
          while (users.hasNext())
          {
              User user = (User)users.next();
              System.out.println("++++ User = " + user);
              Principal principal = getPrincipal(user.getSubject(), UserPrincipal.class);             
              System.out.println("principal = " + principal.getName());
          }
      }
      
      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;
      }
      
  
  }
  
  
  

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