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/17 20:40:34 UTC
cvs commit: jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users JetspeedUserBean.java
taylor 2004/09/17 11:40:34
Modified: applications/pam/src/java/org/apache/jetspeed/portlets/security
UserBrowserPortlet.java UserDetailsPortlet.java
applications/pam/src/java/org/apache/jetspeed/portlets/security/resources
SecurityResources.properties
Added: applications/pam/src/java/org/apache/jetspeed/portlets/security/resources
SecurityResources_en.properties
applications/pam/src/java/org/apache/jetspeed/portlets/security/users
JetspeedUserBean.java
Log:
checkpoint for continuing work on User Manager
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 +58 -36 jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserBrowserPortlet.java
Index: UserBrowserPortlet.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserBrowserPortlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserBrowserPortlet.java 17 Sep 2004 00:18:59 -0000 1.1
+++ UserBrowserPortlet.java 17 Sep 2004 18:40:34 -0000 1.2
@@ -24,6 +24,7 @@
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.security.auth.Subject;
@@ -46,6 +47,22 @@
{
private UserManager manager;
+ /** the id of the tree control */
+ private static final String TREE_CONTROL = "j2_tree";
+ /** query filter for selecting users */
+ private static final String USER_FILTER = "";
+ /** the id of the root node of the tree control */
+ private static final String SECURITY_NODE_ID = "SECURITY-NODE";
+ /** the domain of the security sub-tree */
+ private static final String SECURITY_DOMAIN = "SECURITY_DOMAIN";
+ /** the id of the user node of the tree control */
+ private static final String USER_NODE_ID = "USER-NODE";
+ /** the domain of the user sub-tree */
+ private static final String USER_DOMAIN = "USER_DOMAIN";
+ /** the domain of the users leaf nodes */
+ private static final String USER_DETAIL_DOMAIN = "USER_DETAIL_DOMAIN";
+
+
public void init(PortletConfig config)
throws PortletException
{
@@ -62,14 +79,14 @@
{
response.setContentType("text/html");
- TreeControl control = (TreeControl) request.getPortletSession().getAttribute("j2_tree");
+ TreeControl control = (TreeControl) request.getPortletSession().getAttribute(TREE_CONTROL);
if(control == null)
{
- Iterator users = manager.getUsers("");
+ Iterator users = manager.getUsers(USER_FILTER);
control = buildTree(users, request.getLocale());
- request.getPortletSession().setAttribute("j2_tree", control);
+ request.getPortletSession().setAttribute(TREE_CONTROL, control);
}
- request.setAttribute("j2_tree", control);
+ request.setAttribute(TREE_CONTROL, control);
super.doView(request, response);
@@ -77,11 +94,12 @@
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException
{
- TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute("j2_tree");
+ TreeControl control = (TreeControl) actionRequest.getPortletSession().getAttribute(TREE_CONTROL);
//assert control != null
if(control != null)
{
- String node = actionRequest.getParameter("node");
+ // expand or contact non-leaf nodes
+ String node = actionRequest.getParameter(PortletApplicationResources.REQUEST_NODE);
if(node != null)
{
TreeControlNode controlNode = control.findNode(node);
@@ -91,59 +109,54 @@
}
}
+ // select a node
String selectedNode = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_NODE);
if(selectedNode != null)
{
control.selectNode(selectedNode);
TreeControlNode child = control.findNode(selectedNode);
- if(child != null)
+ if (child != null)
{
- User user = null;
-
String domain = child.getDomain();
- if(domain.equals("USER_DOMAIN"))
+ if(domain.equals(USER_DETAIL_DOMAIN))
{
System.out.println("SELECTED NODE = " + selectedNode);
- /*pa = registry.getPortletApplicationByIdentifier(selectedNode);
- if(pa != null)
+ if (selectedNode != null)
{
- actionRequest.getPortletSession().removeAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET, PortletSession.APPLICATION_SCOPE);
- }*/
- }
- else
- {
- //warn about not recognized domain
- }
-
- if (user != null)
- {
- // actionRequest.getPortletSession().setAttribute(PortletApplicationResources.PAM_CURRENT_PA, pa.getName(), PortletSession.APPLICATION_SCOPE);
+ actionRequest.getPortletSession().setAttribute(
+ PortletApplicationResources.PAM_CURRENT_USER,
+ selectedNode,
+ PortletSession.APPLICATION_SCOPE);
+ }
}
}
}
}
}
-
-
+
private TreeControl buildTree(Iterator users, Locale locale)
{
+
TreeControlNode root =
- new TreeControlNode("SECURITY-NODE",
- null, "SECURITY_ROOT",
+ new TreeControlNode(SECURITY_NODE_ID, // node id
+ null, // icon
+ getMessage(MSG_SECURITY_ROOT, locale), // title
PortletApplicationResources.PORTLET_URL,
- null, true, "SECURITY_DOMAIN");
+ null, // target window
+ true, // expand initially
+ SECURITY_DOMAIN); // domain
TreeControl control = new TreeControl(root);
TreeControlNode userTree =
- new TreeControlNode("USER_ROOT",
- null,
- "USER_ROOT",
+ new TreeControlNode(USER_NODE_ID, // node id
+ null, // icon
+ getMessage(MSG_USER_ROOT, locale), // title
PortletApplicationResources.PORTLET_URL,
- null,
- false,
- "SECURITY_DOMAIN");
+ null, // target window
+ false, // expand initially
+ USER_DOMAIN); // domain
root.addChild(userTree);
while (users.hasNext())
@@ -157,7 +170,7 @@
PortletApplicationResources.PORTLET_URL,
null,
false,
- "USER_APP_DOMAIN");
+ USER_DETAIL_DOMAIN);
userTree.addChild(userNode);
}
@@ -178,6 +191,15 @@
}
}
return principal;
+ }
+
+ /** Messages */
+ private static final String MSG_SECURITY_ROOT = "tree.security.root";
+ private static final String MSG_USER_ROOT = "tree.user.root";
+
+ private String getMessage(String key, Locale locale)
+ {
+ return getResourceBundle(locale).getString(key);
}
}
1.2 +50 -17 jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java
Index: UserDetailsPortlet.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserDetailsPortlet.java 17 Sep 2004 00:18:59 -0000 1.1
+++ UserDetailsPortlet.java 17 Sep 2004 18:40:34 -0000 1.2
@@ -18,6 +18,8 @@
import java.io.IOException;
import java.util.LinkedHashMap;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletSession;
@@ -26,7 +28,9 @@
import org.apache.jetspeed.portlet.ServletPortlet;
import org.apache.jetspeed.portlets.pam.PortletApplicationResources;
+import org.apache.jetspeed.portlets.pam.beans.PortletApplicationBean;
import org.apache.jetspeed.portlets.pam.beans.TabBean;
+import org.apache.jetspeed.portlets.security.users.JetspeedUserBean;
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserManager;
@@ -74,24 +78,22 @@
response.setContentType("text/html");
String userName = (String)
- request.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
- PortletSession.APPLICATION_SCOPE);
- User user;
- try
- {
- user = manager.getUser(userName);
- }
- catch (Exception e)
+ request.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_USER,
+ PortletSession.APPLICATION_SCOPE);
+
+ User user = null;
+ if (userName != null)
{
- throw new PortletException(e);
+ // TODO: don't lookup with every view call
+ user = lookupUser(userName);
}
- if (null != user)
- {
- request.setAttribute(VIEW_USER, user); // TODO: bean
-
- request.setAttribute("tabs", userTabMap.values());
+ if (user != null)
+ {
+ request.setAttribute(VIEW_USER, new JetspeedUserBean(user));
+ // Tabs
+ request.setAttribute("tabs", userTabMap.values());
TabBean selectedTab = (TabBean) request.getPortletSession().getAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, PortletSession.APPLICATION_SCOPE);
if(selectedTab == null)
{
@@ -99,10 +101,41 @@
}
request.setAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, selectedTab);
-
}
+
super.doView(request, response);
}
-
+ public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
+ throws PortletException, IOException
+ {
+ String selectedTab = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_TAB);
+ System.out.println("SELECTED TAB = " + selectedTab);
+ if (selectedTab != null)
+ {
+ TabBean tab = (TabBean) userTabMap.get(selectedTab);
+ if (tab != null)
+ {
+ actionRequest.getPortletSession().setAttribute(
+ PortletApplicationResources.REQUEST_SELECT_TAB, tab);
+ }
+ }
+
+ }
+
+ private User lookupUser(String userName)
+ {
+ User user = null;
+ try
+ {
+ user = manager.getUser(userName);
+ }
+ catch (Exception e)
+ {
+ // TODO: logging
+ System.err.println("user not found: " + userName + ", " + e);
+ }
+ return user;
+ }
+
}
1.2 +7 -88 jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties
Index: SecurityResources.properties
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecurityResources.properties 17 Sep 2004 00:18:59 -0000 1.1
+++ SecurityResources.properties 17 Sep 2004 18:40:34 -0000 1.2
@@ -15,92 +15,11 @@
# $Id$
#
-user.details.name=Name
-user.details.name.description=The Name of this item
-
-user.details.description=Description
-user.details.description.description=A descriptive phrase for this item
-
-user.details.value=Value
-user.details.value.description=The value for this item
-
-user.details.locale=Locale
-user.details.locale.description=A valid 2 letter country code
-
-user.details.version=Version
-user.details.type=Type
-user.details.type.webapp=WEBAPP
-user.details.type.local=Local
-user.details.id=ID
-user.details.services=Services
-
-user.details.choose_portlet=Please Chooose a Portlet
-user.details.edit=Edit
-user.details.remove=Remove Selected
-user.details.add_user_attribute=Add User Attribute
-
-##Metadata view
-user.details.add_metadata=Add MetaData
-
-##Portlet view
-user.details.expiration_cache=Expiration Cache
-user.details.unique_name=Unique Name
-user.details.preference_validator=Preference Validator
-user.details.class_name=Class Name
-
-##Preference view
-user.details.add_preference=Add Preference
-
-##Language view
-user.details.title=Title
-user.details.short_title=Short Title
-user.details.keyword=Keyword
-user.details.title.description=Title to appear in title bar
-user.details.short_title.description=A short descriptive title
-user.details.keyword.description=Comma delimited list of keywords
-user.details.add_language=Add Language
-
-##Parameter View
-user.details.add_parameter=Add Parameter
-
-##Security View
-user.details.role_name=Role Name
-user.details.role_name.description=The name of the role
-
-user.details.role_link=Role Link
-user.details.role_link.description=The id of the role link
-
-user.details.add_security=Add Security
-
-##Content Type View
-user.details.content_type=Content Type
-user.details.content_type.description=MimeType like text/html. Wildcards are allowed.
-
-user.details.modes=Modes
-user.details.portlet_mode=Portlet Mode
-user.details.porltet_mode.view=View
-user.details.porltet_mode.edit=Edit
-user.details.porltet_mode.help=Help
-user.details.portlet_mode.description=Standard portlet modes that the portlet supports
-
-user.details.custom_mode=Custom Modes
-user.details.custom_modes.description=Custom Modes that the portlet supports
-
-user.details.add_content_type=Add Content Type
-
-##Portlet Application Tabs
-user.details.tabs.pa_details=Details
-user.details.tabs.pa_metadata=MetaData
-user.details.tabs.pa_portlets=Portlets
-user.details.tabs.pa_user_attribtues=User Attributes
-
-##Portlet Definition Tabs
-user.details.tabs.pd_details=Details
-user.details.tabs.pd_metadata=MetaData
-user.details.tabs.pd_preferences=Preferences
-user.details.tabs.pd_languages=Languages
-user.details.tabs.pd_parameters=Parameters
-user.details.tabs.pd_security=Security
-user.details.tabs.pd_content_type=Content Type
+## User Information Tabs
+pam.details.tabs.user_attributes=User Attributes
+pam.details.tabs.user_security=Security
+tree.security.root=Jetspeed Security
+tree.user.root=Users
+user.principal.name=Principal
1.1 jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/resources/SecurityResources_en.properties
Index: SecurityResources_en.properties
===================================================================
# Copyright 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.
#
# $Id: SecurityResources_en.properties,v 1.1 2004/09/17 18:40:34 taylor Exp $
#
## User Information Tabs
pam.details.tabs.user_attributes=User Attributes
pam.details.tabs.user_security=Security
tree.security.root=Jetspeed Security
tree.user.root=Users
user.principal.name=Principal
1.1 jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/users/JetspeedUserBean.java
Index: JetspeedUserBean.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.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,v 1.1 2004/09/17 18:40:34 taylor Exp $
*/
public class JetspeedUserBean
{
private String principal;
public JetspeedUserBean(User user)
{
Principal userPrincipal = createPrincipal(user.getSubject(), UserPrincipal.class);
this.principal = userPrincipal.getName();
System.out.println("principal = " + principal);
}
/**
* @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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org