001/*
002 * (C) Copyright 2006-2007 Nuxeo SAS (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.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 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.usermanager;
021
022import java.util.List;
023
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.core.api.NuxeoPrincipal;
026
027/**
028 * Describes a detached NuxeoPrincipal.
029 *
030 * @author Mariana Cedica
031 */
032public class DetachedNuxeoPrincipal implements NuxeoPrincipal {
033
034    public static DetachedNuxeoPrincipal detach(NuxeoPrincipal principal) {
035        DetachedNuxeoPrincipal detachedPrincipal = new DetachedNuxeoPrincipal(principal.getPrincipalId());
036        detachedPrincipal.name = principal.getName();
037        detachedPrincipal.firstName = principal.getFirstName();
038        detachedPrincipal.lastName = principal.getLastName();
039        detachedPrincipal.password = principal.getPassword();
040        detachedPrincipal.company = principal.getCompany();
041        detachedPrincipal.groups = principal.getGroups();
042        detachedPrincipal.allGroups = principal.getAllGroups();
043        detachedPrincipal.roles = principal.getRoles();
044        detachedPrincipal.isAdministrator = principal.isAdministrator();
045        detachedPrincipal.isAnonymous = principal.isAnonymous();
046        detachedPrincipal.email = principal.getEmail();
047        return detachedPrincipal;
048    }
049
050    protected DetachedNuxeoPrincipal(String principalId) {
051        this.principalId = principalId;
052    }
053
054    public DetachedNuxeoPrincipal(String principalId, String name, String firstName, String lastName, String password,
055            String email, String company, List<String> groups, List<String> allGroups, List<String> roles,
056            boolean isAdministrator, boolean isAnonymous) {
057        this.password = principalId;
058        this.name = name;
059        this.firstName = firstName;
060        this.lastName = lastName;
061        this.password = password;
062        this.email = email;
063        this.company = company;
064        this.groups = groups;
065        this.allGroups = allGroups;
066        this.roles = roles;
067        this.isAdministrator = isAdministrator;
068        this.isAnonymous = isAnonymous;
069    }
070
071    private static final long serialVersionUID = 1L;
072
073    protected String principalId;
074
075    protected String name;
076
077    protected String firstName;
078
079    protected String lastName;
080
081    protected String password;
082
083    protected String email;
084
085    protected String company;
086
087    protected List<String> groups;
088
089    protected List<String> allGroups;
090
091    protected List<String> roles;
092
093    protected boolean isAdministrator;
094
095    protected boolean isAnonymous;
096
097    public String getName() {
098        return name;
099    }
100
101    public String getFirstName() {
102        return firstName;
103    }
104
105    public String getLastName() {
106        return lastName;
107    }
108
109    public String getPassword() {
110        return password;
111    }
112
113    public String getCompany() {
114        return company;
115    }
116
117    public String getEmail() {
118        return email;
119    }
120
121    public List<String> getGroups() {
122        return groups;
123    }
124
125    public List<String> getAllGroups() {
126        return allGroups;
127    }
128
129    public boolean isMemberOf(String group) {
130        throw new UnsupportedOperationException();
131    }
132
133    public List<String> getRoles() {
134        return roles;
135    }
136
137    public void setName(String name) {
138        throw new UnsupportedOperationException();
139
140    }
141
142    public void setFirstName(String firstName) {
143        throw new UnsupportedOperationException();
144
145    }
146
147    public void setLastName(String lastName) {
148        throw new UnsupportedOperationException();
149    }
150
151    public void setGroups(List<String> groups) {
152        throw new UnsupportedOperationException();
153
154    }
155
156    public void setRoles(List<String> roles) {
157        throw new UnsupportedOperationException();
158
159    }
160
161    @Override
162    public void setEmail(String email) {
163        this.email = email;
164    }
165
166    public void setCompany(String company) {
167        throw new UnsupportedOperationException();
168
169    }
170
171    public void setPassword(String password) {
172        throw new UnsupportedOperationException();
173
174    }
175
176    public String getPrincipalId() {
177        return principalId;
178    }
179
180    public void setPrincipalId(String principalId) {
181        throw new UnsupportedOperationException();
182    }
183
184    public DocumentModel getModel() {
185        throw new UnsupportedOperationException();
186    }
187
188    public void setModel(DocumentModel model) {
189        throw new UnsupportedOperationException();
190
191    }
192
193    public boolean isAdministrator() {
194        return isAdministrator;
195    }
196
197    @Override
198    public String getTenantId() {
199        return null;
200    }
201
202    public boolean isAnonymous() {
203        return isAnonymous;
204    }
205
206    public String getOriginatingUser() {
207        throw new UnsupportedOperationException();
208    }
209
210    public void setOriginatingUser(String originatingUser) {
211        throw new UnsupportedOperationException();
212    }
213
214    @Override
215    public String getActingUser() {
216        return getName();
217    }
218
219}