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 wo...@apache.org on 2010/04/13 14:02:50 UTC

svn commit: r933570 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/ jetspeed-portal-resources/src/main/resou...

Author: woonsan
Date: Tue Apr 13 12:02:49 2010
New Revision: 933570

URL: http://svn.apache.org/viewvc?rev=933570&view=rev
Log:
JS2-1186: Committing the patch provided by Joachim Müller. Thanks a lot!

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java   (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java   (with props)
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java   (with props)
Modified:
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java?rev=933570&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java Tue Apr 13 12:02:49 2010
@@ -0,0 +1,172 @@
+/* 
+ * 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
+ *
+ * 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.services.beans;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.jetspeed.security.JetspeedPrincipal;
+import org.apache.jetspeed.security.JetspeedPrincipalResultList;
+
+/**
+ * DTO for user search result list to be displayed in the view. The object will
+ * be transformed to JSON to be transfered to the JS client.
+ * 
+ * @author <a href="mailto:joachim@wemove.com">Joachim Mueller</a>
+ * 
+ */
+@XmlRootElement(name = "data")
+public class UserDataTableBean implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private long recordsReturned = 5;
+	private long totalRecords;
+	private long startIndex = 5;
+	private String sort = "userName";
+	private String dir = "asc";
+	private long pageSize = 5;
+	private List<HashMap<String, String>> records = null;
+
+	public UserDataTableBean() {
+	}
+
+	public UserDataTableBean(JetspeedPrincipalResultList resultList) {
+		totalRecords = resultList.getTotalSize();
+		this.records = new ArrayList<HashMap<String, String>>();
+		HashMap<String, String> record = null;
+		for (JetspeedPrincipal p : resultList.getResults()) {
+			record = new HashMap<String, String>();
+			record.put("userName", p.getName());
+			record.put("firstName", p.getInfoMap().get("user.name.given") == null ? "" : p.getInfoMap().get(
+					"user.name.given"));
+			record.put("lastName", p.getInfoMap().get("user.name.family") == null ? "" : p.getInfoMap().get(
+					"user.name.family"));
+			this.records.add(record);
+		}
+	}
+
+	/**
+	 * @return the recordsReturned
+	 */
+	public long getRecordsReturned() {
+		return recordsReturned;
+	}
+
+	/**
+	 * @param recordsReturned
+	 *            the recordsReturned to set
+	 */
+	public void setRecordsReturned(long recordsReturned) {
+		this.recordsReturned = recordsReturned;
+	}
+
+	/**
+	 * @return the totalRecords
+	 */
+	public long getTotalRecords() {
+		return totalRecords;
+	}
+
+	/**
+	 * @param totalRecords
+	 *            the totalRecords to set
+	 */
+	public void setTotalRecords(long totalRecords) {
+		this.totalRecords = totalRecords;
+	}
+
+	/**
+	 * @return the startIndex
+	 */
+	public long getStartIndex() {
+		return startIndex;
+	}
+
+	/**
+	 * @param startIndex
+	 *            the startIndex to set
+	 */
+	public void setStartIndex(long startIndex) {
+		this.startIndex = startIndex;
+	}
+
+	/**
+	 * @return the sort
+	 */
+	public String getSort() {
+		return sort;
+	}
+
+	/**
+	 * @param sort
+	 *            the sort to set
+	 */
+	public void setSort(String sort) {
+		this.sort = sort;
+	}
+
+	/**
+	 * @return the dir
+	 */
+	public String getDir() {
+		return dir;
+	}
+
+	/**
+	 * @param dir
+	 *            the dir to set
+	 */
+	public void setDir(String dir) {
+		this.dir = dir;
+	}
+
+	/**
+	 * @return the pageSize
+	 */
+	public long getPageSize() {
+		return pageSize;
+	}
+
+	/**
+	 * @param pageSize
+	 *            the pageSize to set
+	 */
+	public void setPageSize(long pageSize) {
+		this.pageSize = pageSize;
+	}
+
+	/**
+	 * @return the records
+	 */
+	public List<HashMap<String, String>> getRecords() {
+		return records;
+	}
+
+	/**
+	 * @param records
+	 *            the records to set
+	 */
+	public void setRecords(List<HashMap<String, String>> records) {
+		this.records = records;
+	}
+
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDataTableBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java?rev=933570&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java Tue Apr 13 12:02:49 2010
@@ -0,0 +1,225 @@
+/* 
+ * 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
+ *
+ * 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.services.beans;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.jetspeed.security.Group;
+import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.Role;
+import org.apache.jetspeed.security.User;
+
+/**
+ * DTO for user details data. The object will be transformed to JSON to be
+ * transfered to the JS client.
+ * 
+ * @author <a href="mailto:joachim@wemove.com">Joachim Mueller</a>
+ * 
+ */
+@XmlRootElement(name = "data")
+public class UserDetailBean implements Serializable {
+
+	private Map<String, String> infoMap;
+	private Timestamp creationDate;
+	private Timestamp modifiedDate;
+	private boolean enabled = true;
+	private boolean credentialUpdateRequired = false;
+	private List<String> roles = null;
+	private List<String> groups = null;
+	private List<String> availableRoles = null;
+	private List<String> availableGroups = null;
+
+	private static final long serialVersionUID = 1L;
+
+	public UserDetailBean() {
+	}
+
+	public UserDetailBean(User user, PasswordCredential credential, List<Role> roles, List<Group> groups, List<String> allRoles, List<String> allGroups) {
+		this.name = user.getName();
+		this.infoMap = user.getInfoMap();
+		this.creationDate = user.getCreationDate();
+		this.modifiedDate = user.getModifiedDate();
+		this.enabled = user.isEnabled();
+		this.availableRoles = allRoles;
+		this.availableGroups = allGroups;
+		this.credentialUpdateRequired = credential.isUpdateRequired();
+		for (Role role : roles) {
+			this.roles = (this.roles == null ? new ArrayList<String>() : this.roles);
+			this.roles.add(role.getName());
+			if (availableRoles.contains(role.getName())) {
+				availableRoles.remove(role.getName());
+			}
+		}
+		for (Group group : groups) {
+			this.groups = (this.groups == null ? new ArrayList<String>() : this.groups);
+			this.groups.add(group.getName());
+			if (availableGroups.contains(group.getName())) {
+				availableGroups.remove(group.getName());
+			}
+		}
+	}
+
+	private String name;
+
+	/**
+	 * @return the name
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * @param name
+	 *            the name to set
+	 */
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	/**
+	 * @return the infoMap
+	 */
+	public Map<String, String> getInfoMap() {
+		return infoMap;
+	}
+
+	/**
+	 * @param infoMap
+	 *            the infoMap to set
+	 */
+	public void setInfoMap(Map<String, String> infoMap) {
+		this.infoMap = infoMap;
+	}
+
+	/**
+	 * @return the creationDate
+	 */
+	public Timestamp getCreationDate() {
+		return creationDate;
+	}
+
+	/**
+	 * @param creationDate
+	 *            the creationDate to set
+	 */
+	public void setCreationDate(Timestamp creationDate) {
+		this.creationDate = creationDate;
+	}
+
+	/**
+	 * @return the modifiedDate
+	 */
+	public Timestamp getModifiedDate() {
+		return modifiedDate;
+	}
+
+	/**
+	 * @param modifiedDate
+	 *            the modifiedDate to set
+	 */
+	public void setModifiedDate(Timestamp modifiedDate) {
+		this.modifiedDate = modifiedDate;
+	}
+
+	/**
+	 * @return the enabled
+	 */
+	public boolean isEnabled() {
+		return enabled;
+	}
+
+	/**
+	 * @param enabled
+	 *            the enabled to set
+	 */
+	public void setEnabled(boolean enabled) {
+		this.enabled = enabled;
+	}
+
+	/**
+	 * @return the groups
+	 */
+	public List<String> getGroups() {
+		return groups;
+	}
+
+	/**
+	 * @param groups
+	 *            the groups to set
+	 */
+	public void setGroups(List<String> groups) {
+		this.groups = groups;
+	}
+
+	/**
+	 * @return the roles
+	 */
+	public List<String> getRoles() {
+		return roles;
+	}
+
+	/**
+	 * @param roles
+	 *            the roles to set
+	 */
+	public void setRoles(List<String> roles) {
+		this.roles = roles;
+	}
+
+	/**
+	 * @return the availableRoles
+	 */
+	public List<String> getAvailableRoles() {
+		return availableRoles;
+	}
+
+	/**
+	 * @param availableRoles
+	 *            the availableRoles to set
+	 */
+	public void setAvailableRoles(List<String> availableRoles) {
+		this.availableRoles = availableRoles;
+	}
+
+	/**
+	 * @return the availableGroups
+	 */
+	public List<String> getAvailableGroups() {
+		return availableGroups;
+	}
+
+	/**
+	 * @param availableGroups
+	 *            the availableGroups to set
+	 */
+	public void setAvailableGroups(List<String> availableGroups) {
+		this.availableGroups = availableGroups;
+	}
+	
+	/**
+	 * @return the credentialUpdateRequired
+	 */
+	public boolean isCredentialUpdateRequired() {
+		return credentialUpdateRequired;
+	}
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/beans/UserDetailBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java?rev=933570&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java (added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java Tue Apr 13 12:02:49 2010
@@ -0,0 +1,505 @@
+/*
+ * 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
+ * 
+ * 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.services.rest;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.jetspeed.Jetspeed;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.administration.PortalConfigurationConstants;
+import org.apache.jetspeed.exception.JetspeedException;
+import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.om.folder.Folder;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.profiler.Profiler;
+import org.apache.jetspeed.profiler.rules.ProfilingRule;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.Group;
+import org.apache.jetspeed.security.GroupManager;
+import org.apache.jetspeed.security.JetspeedPrincipalQueryContext;
+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.UserResultList;
+import org.apache.jetspeed.services.beans.UserDataTableBean;
+import org.apache.jetspeed.services.beans.UserDetailBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * UserManagerService. This REST service provides access to the jetspeed user manager. The access of all methods are restricted to the users with the 'admin'
+ * role.
+ * 
+ * @version $Id$
+ */
+@Path("/usermanager/")
+public class UserManagerService
+{
+    
+    private static Logger log = LoggerFactory.getLogger(UserManagerService.class);
+    
+    private UserManager userManager;
+    private RoleManager roleManager;
+    private GroupManager groupManager;
+    private Profiler profiler;
+    private PageManager pageManager;
+    private PortletActionSecurityBehavior securityBehavior;
+
+    public UserManagerService(UserManager userManager, RoleManager roleManager, GroupManager groupManager, Profiler profiler, PageManager pageManager,
+                              PortletActionSecurityBehavior securityBehavior)
+    {
+        this.userManager = userManager;
+        this.roleManager = roleManager;
+        this.groupManager = groupManager;
+        this.profiler = profiler;
+        this.pageManager = pageManager;
+        this.securityBehavior = securityBehavior;
+    }
+
+    /**
+     * Find users according to query parameters.
+     * 
+     * @param servletRequest
+     * @param uriInfo
+     * @param userName
+     * @param roles
+     * @param groups
+     * @param startIndex
+     * @param results
+     * @param sortDirection
+     * @param attributeKeys
+     * @param attributeValues
+     * @return
+     */
+    @GET
+    @Path("/users/")
+    public UserDataTableBean findUsers(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @QueryParam("name") String userName,
+                                       @QueryParam("roles") List<String> roles, @QueryParam("groups") List<String> groups,
+                                       @QueryParam("start") long startIndex, @QueryParam("results") long results, @QueryParam("sort") String sortDirection,
+                                       @QueryParam("attribute_key") List<String> attributeKeys, @QueryParam("attribute_value") List<String> attributeValues)
+    {
+        checkPrivilege(servletRequest, JetspeedActions.VIEW);
+        
+        Map<String, String> attributeMap = null;
+        
+        if (attributeKeys != null && attributeKeys.size() > 0 && attributeKeys.size() == attributeValues.size())
+        {
+            attributeMap = new HashMap<String, String>();
+            
+            for (int i = 0; i < attributeKeys.size(); i++)
+            {
+                if (attributeValues.get(i) != null && attributeValues.get(i).length() > 0)
+                {
+                    attributeMap.put(attributeKeys.get(i), attributeValues.get(i));
+                }
+            }
+        }
+        
+        JetspeedPrincipalQueryContext ctx = new JetspeedPrincipalQueryContext(userName, startIndex, results, sortDirection, roles, groups, null, attributeMap);
+        
+        try
+        {
+            UserResultList resultList = userManager.getUsersExtended(ctx);
+            UserDataTableBean result = new UserDataTableBean(resultList);
+            result.setStartIndex(startIndex);
+            result.setPageSize(results);
+            result.setRecordsReturned(results);
+            
+            return result;
+        }
+        catch (SecurityException e)
+        {
+            if (log.isDebugEnabled())
+            {
+                log.error("Error searching users:" + ctx, e);
+            }
+            else
+            {
+                log.error("Error searching users:" + ctx + ". " + e);
+            }
+        }
+        
+        return null;
+    }
+
+    /**
+     * Get users detail data, according to the users name. This method just gets all data that will be displayed in the view.
+     * 
+     * @param servletRequest
+     * @param uriInfo
+     * @param userName
+     * @return
+     */
+    @GET
+    @Path("/users/{name}/")
+    public UserDetailBean getUserByName(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("name") String userName)
+    {
+        checkPrivilege(servletRequest, JetspeedActions.VIEW);
+        
+        try
+        {
+            User user = userManager.getUser(userName);
+            PasswordCredential credential = userManager.getPasswordCredential(user);
+            List<Role> roles = roleManager.getRolesForUser(user.getName());
+            List<String> availableRoles = roleManager.getRoleNames(null);
+            List<Group> groups = groupManager.getGroupsForUser(user.getName());
+            List<String> availableGroups = groupManager.getGroupNames(null);
+            
+            return new UserDetailBean(user, credential, roles, groups, availableRoles, availableGroups);
+        }
+        catch (Exception e)
+        {
+            if (log.isDebugEnabled())
+            {
+                log.debug("Error requesting users datail data:" + userName, e);
+            }
+        }
+        
+        return null;
+    }
+
+    /**
+     * Update user data.
+     * 
+     * @param servletRequest
+     * @param uriInfo
+     * @param userName
+     * @return
+     */
+    @POST
+    @Path("/users/{name}/")
+    public Boolean updateUserDetail(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("name") String userName,
+                                    @FormParam("user_name_given") String userNameGiven, @FormParam("user_name_family") String userNameFamily,
+                                    @FormParam("user_email") String userEmail, @FormParam("password") String password,
+                                    @FormParam("password_confirm") String passwordConfirm, @FormParam("user_enabled") Boolean userEnabled,
+                                    @FormParam("credential_update_required") Boolean credentialUpdateRequired, @FormParam("roles") List<String> roles,
+                                    @FormParam("groups") List<String> groups)
+    {
+        checkPrivilege(servletRequest, JetspeedActions.VIEW);
+        
+        try
+        {
+            boolean changePassword = false;
+            
+            if (password != null && password.length() > 0)
+            {
+                if (!password.equals(passwordConfirm))
+                {
+                    ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
+                    builder.type("text/plain");
+                    builder.entity("password.confirmation.failed");
+                    throw new WebApplicationException(builder.build());
+                }
+                
+                changePassword = true;
+            }
+            
+            User user = userManager.getUser(userName);
+            user.getSecurityAttributes().getAttribute("user.name.given", true).setStringValue(userNameGiven);
+            user.getSecurityAttributes().getAttribute("user.name.family", true).setStringValue(userNameFamily);
+            user.getSecurityAttributes().getAttribute("user.email", true).setStringValue(userEmail);
+            
+            if (userEnabled == null)
+            {
+                userEnabled = false;
+            }
+            
+            user.setEnabled(userEnabled);
+            
+            userManager.updateUser(user);
+            
+            if (credentialUpdateRequired == null)
+            {
+                credentialUpdateRequired = false;
+            }
+            
+            PasswordCredential credential = userManager.getPasswordCredential(user);
+            
+            if (changePassword)
+            {
+                credential.setPassword(password, false);
+            }
+            
+            credential.setUpdateRequired(credentialUpdateRequired);
+            
+            userManager.storePasswordCredential(credential);
+            
+            // merge roles
+            List<Role> currentRoles = roleManager.getRolesForUser(user.getName());
+            for (Role currentRole : currentRoles)
+            {
+                if (roles != null && roles.contains(currentRole.getName()))
+                {
+                    roles.remove(currentRole.getName());
+                }
+                else
+                {
+                    roleManager.removeRoleFromUser(userName, currentRole.getName());
+                }
+            }
+            
+            if (roles != null)
+            {
+                for (String roleName : roles)
+                {
+                    roleManager.addRoleToUser(userName, roleName);
+                }
+            }
+            
+            // merge groups
+            List<Group> currentGroups = groupManager.getGroupsForUser(user.getName());
+            
+            for (Group currentGroup : currentGroups)
+            {
+                if (groups != null && groups.contains(currentGroup.getName()))
+                {
+                    groups.remove(currentGroup.getName());
+                }
+                else
+                {
+                    groupManager.removeUserFromGroup(userName, currentGroup.getName());
+                }
+            }
+            
+            if (groups != null)
+            {
+                for (String groupName : groups)
+                {
+                    groupManager.addUserToGroup(userName, groupName);
+                }
+            }
+            
+            return new Boolean(true);
+        }
+        catch (WebApplicationException e)
+        {
+            // re-throw exception
+            throw e;
+        }
+        catch (SecurityException e)
+        {
+            ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
+            builder.type("text/plain");
+            builder.entity(e.getKeyedMessage().getKey());
+            
+            throw new WebApplicationException(builder.build());
+        }
+        catch (Exception e)
+        {
+            // handle other exceptions
+            if (log.isErrorEnabled())
+            {
+                log.error("Error updating users :" + userName, e);
+            }
+            
+            throw new WebApplicationException(e);
+        }
+    }
+
+    /**
+     * <p> Create user data. </p> <p> It uses the property "registration.roles.default" from jetspeed.properties as default roles for new created users. </p>
+     * <p> It uses the property "registration.rules.default" from jetspeed.properties as default profiling rules for new created users. The locator name is
+     * always "default". </p> <p> It uses the property "psml.template.folder" from jetspeed.properties as PSML template folder to create new users. </p>
+     * 
+     * @param servletRequest
+     * @param uriInfo
+     * @param userName
+     * @param userNameGiven
+     * @param userNameFamily
+     * @param userEmail
+     * @param password
+     * @param passwordConfirm
+     * @param credentialUpdateRequired
+     * @return
+     */
+    @POST
+    @Path("/users/")
+    public Boolean createUser(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @FormParam("name") String userName,
+                              @FormParam("user_name_given") String userNameGiven, @FormParam("user_name_family") String userNameFamily,
+                              @FormParam("user_email") String userEmail, @FormParam("password") String password,
+                              @FormParam("password_confirm") String passwordConfirm, @FormParam("credential_update_required") Boolean credentialUpdateRequired)
+    {
+        checkPrivilege(servletRequest, JetspeedActions.VIEW);
+        
+        try
+        {
+            boolean changePassword = false;
+            
+            if (password != null && password.length() > 0)
+            {
+                if (!password.equals(passwordConfirm))
+                {
+                    ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
+                    builder.type("text/plain");
+                    builder.entity("password.confirmation.failed");
+                    throw new WebApplicationException(builder.build());
+                }
+                
+                changePassword = true;
+            }
+            
+            User user = userManager.addUser(userName);
+            
+            user.getSecurityAttributes().getAttribute("user.name.given", true).setStringValue(userNameGiven);
+            user.getSecurityAttributes().getAttribute("user.name.family", true).setStringValue(userNameFamily);
+            user.getSecurityAttributes().getAttribute("user.email", true).setStringValue(userEmail);
+            
+            userManager.updateUser(user);
+            
+            if (credentialUpdateRequired == null)
+            {
+                credentialUpdateRequired = false;
+            }
+            
+            PasswordCredential credential = userManager.getPasswordCredential(user);
+            
+            if (changePassword)
+            {
+                credential.setPassword(password, false);
+            }
+            
+            credential.setUpdateRequired(credentialUpdateRequired);
+            userManager.storePasswordCredential(credential);
+            
+            // add default user roles
+            String[] defaultUserRoles = Jetspeed.getConfiguration().getStringArray(PortalConfigurationConstants.REGISTRATION_ROLES_DEFAULT);
+            
+            for (String defaultUserRole : defaultUserRoles)
+            {
+                roleManager.addRoleToUser(userName, defaultUserRole);
+            }
+            
+            // add default user profiling rules
+            String[] defaultUserProfilingRules = Jetspeed.getConfiguration().getStringArray(PortalConfigurationConstants.REGISTRATION_ROLES_DEFAULT);
+            
+            for (String defaultUserProfilingRule : defaultUserProfilingRules)
+            {
+                ProfilingRule profilingRule = profiler.getRule(defaultUserProfilingRule);
+                
+                if (profilingRule != null)
+                {
+                    profiler.setRuleForPrincipal(user, profilingRule, "default");
+                }
+                else
+                {
+                    log.error("Failed to set profiling rule for principal. Invalid profiling rule: " + defaultUserProfilingRule);
+                }
+            }
+            
+            // copy the entire directory tree from the template folder
+            String templateFolder = Jetspeed.getConfiguration().getString(PortalConfigurationConstants.PSML_TEMPLATE_FOLDER);
+            
+            if (!(templateFolder == null || templateFolder.trim().length() == 0))
+            {
+                Folder source = pageManager.getFolder(templateFolder);
+                pageManager.deepCopyFolder(source, Folder.USER_FOLDER + userName, userName);
+            }
+            
+            return new Boolean(true);
+        }
+        catch (WebApplicationException e)
+        {
+            // re-throw exception
+            throw e;
+        }
+        catch (SecurityException e)
+        {
+            ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
+            builder.type("text/plain");
+            builder.entity(e.getKeyedMessage().getKey());
+            
+            throw new WebApplicationException(builder.build());
+        }
+        catch (Exception e)
+        {
+            // handle other exceptions
+            if (log.isErrorEnabled())
+            {
+                log.error("Error creating users :" + userName, e);
+            }
+            
+            throw new WebApplicationException(e);
+        }
+    }
+
+    /**
+     * Get users detail data, according to the users name. This method just gets all data that will be displayed in the view.
+     * 
+     * @param servletRequest
+     * @param uriInfo
+     * @param userName
+     * @return
+     */
+    @DELETE
+    @Path("/users/{name}/")
+    public Boolean deleteUserByName(@Context HttpServletRequest servletRequest, @Context UriInfo uriInfo, @PathParam("name") String userName)
+    {
+        checkPrivilege(servletRequest, JetspeedActions.VIEW);
+        
+        try
+        {
+            userManager.removeUser(userName);
+            return true;
+        }
+        catch (SecurityException e)
+        {
+            ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
+            builder.type("text/plain");
+            builder.entity(e.getKeyedMessage().getKey());
+            throw new WebApplicationException(builder.build());
+        }
+        catch (Exception e)
+        {
+            // handle other exceptions
+            if (log.isErrorEnabled())
+            {
+                log.error("Error creating users :" + userName, e);
+            }
+            throw new WebApplicationException(e);
+        }
+    }
+
+    protected void checkPrivilege(HttpServletRequest servletRequest, String action)
+    {
+        RequestContext requestContext = (RequestContext) servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV);
+        
+        if (securityBehavior != null && !securityBehavior.checkAccess(requestContext, action))
+        {
+            throw new WebApplicationException(new JetspeedException("Insufficient privilege to access this REST service."));
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/UserManagerService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml?rev=933570&r1=933569&r2=933570&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/jetspeed-restful-services.xml Tue Apr 13 12:02:49 2010
@@ -123,6 +123,10 @@
           <meta key="j2:cat" value="default" />
           <constructor-arg ref="jaxrsPageManagementService" />
         </bean>
+        <bean class="org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider">
+          <meta key="j2:cat" value="default" />
+          <constructor-arg ref="jaxrsUserManagerService" />
+        </bean>
       </list>
     </property>
   </bean>
@@ -142,7 +146,18 @@
     <constructor-arg ref="org.apache.jetspeed.components.portletregistry.PortletRegistry" />
     <constructor-arg ref="PortletActionSecurityBehavior" />
   </bean>
-  
+
+  <!-- User Management JAX-RS Service -->
+  <bean id="jaxrsUserManagerService" class="org.apache.jetspeed.services.rest.UserManagerService">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg ref="org.apache.jetspeed.security.UserManager" />
+    <constructor-arg ref="org.apache.jetspeed.security.RoleManager" />
+    <constructor-arg ref="org.apache.jetspeed.security.GroupManager" />
+    <constructor-arg ref="org.apache.jetspeed.profiler.Profiler" />
+    <constructor-arg ref="org.apache.jetspeed.page.PageManager" />
+    <constructor-arg ref="RolesSecurityBehavior" />
+  </bean>
+
   <!-- Portal Page Management JAX-RS Service -->
   <bean id="jaxrsPageManagementService" class="org.apache.jetspeed.services.rest.PageManagementService">
     <meta key="j2:cat" value="default" />

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties?rev=933570&r1=933569&r2=933570&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/conf/jetspeed/jetspeed.properties Tue Apr 13 12:02:49 2010
@@ -369,7 +369,7 @@ registration.roles.default = user
 registration.groups.default = 
 # Registration default profiling rules assigned during registration or new user creation
 # comma separated list
-registration.rules.default = 
+registration.rules.default = j2
 
 #-------------------------------------------------------------------------
 # J E T U I



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