001/* 002 * (C) Copyright 2013 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * dmetzler 016 */ 017package org.nuxeo.ecm.restapi.server.jaxrs.usermanager; 018 019import javax.ws.rs.Path; 020import javax.ws.rs.PathParam; 021import javax.ws.rs.Produces; 022import javax.ws.rs.core.MediaType; 023 024import org.nuxeo.ecm.core.api.NuxeoException; 025import org.nuxeo.ecm.core.api.NuxeoGroup; 026import org.nuxeo.ecm.core.api.NuxeoPrincipal; 027import org.nuxeo.ecm.webengine.WebException; 028import org.nuxeo.ecm.webengine.model.WebObject; 029import org.nuxeo.ecm.webengine.model.exceptions.WebResourceNotFoundException; 030 031/** 032 * @since 5.7.3 033 */ 034@WebObject(type = "user") 035@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON + "+nxentity" }) 036public class UserObject extends AbstractUMObject<NuxeoPrincipal> { 037 038 @Path("group/{groupName}") 039 public Object doGetUserToGroup(@PathParam("groupName") String groupName) { 040 try { 041 NuxeoGroup group = um.getGroup(groupName); 042 if (group == null) { 043 throw new WebResourceNotFoundException("Group not found"); 044 } 045 046 return newObject("userToGroup", currentArtifact, group); 047 } catch (NuxeoException e) { 048 throw WebException.wrap(e); 049 } 050 } 051 052 @Override 053 protected NuxeoPrincipal updateArtifact(NuxeoPrincipal principal) { 054 um.updateUser(principal.getModel()); 055 return um.getPrincipal(principal.getName()); 056 } 057 058 @Override 059 protected void deleteArtifact() { 060 um.deleteUser(currentArtifact.getModel()); 061 } 062 063 @Override 064 protected boolean isAPowerUserEditableArtifact() { 065 return UserRootObject.isAPowerUserEditableUser(currentArtifact); 066 067 } 068 069}