001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.usermanager; 023 024import java.util.List; 025 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.NuxeoPrincipal; 028 029/** 030 * Describes a detached NuxeoPrincipal. 031 * 032 * @author Mariana Cedica 033 */ 034public class DetachedNuxeoPrincipal implements NuxeoPrincipal { 035 036 public static DetachedNuxeoPrincipal detach(NuxeoPrincipal principal) { 037 DetachedNuxeoPrincipal detachedPrincipal = new DetachedNuxeoPrincipal(principal.getPrincipalId()); 038 detachedPrincipal.name = principal.getName(); 039 detachedPrincipal.firstName = principal.getFirstName(); 040 detachedPrincipal.lastName = principal.getLastName(); 041 detachedPrincipal.password = principal.getPassword(); 042 detachedPrincipal.company = principal.getCompany(); 043 detachedPrincipal.groups = principal.getGroups(); 044 detachedPrincipal.allGroups = principal.getAllGroups(); 045 detachedPrincipal.roles = principal.getRoles(); 046 detachedPrincipal.isAdministrator = principal.isAdministrator(); 047 detachedPrincipal.isAnonymous = principal.isAnonymous(); 048 detachedPrincipal.email = principal.getEmail(); 049 return detachedPrincipal; 050 } 051 052 protected DetachedNuxeoPrincipal(String principalId) { 053 this.principalId = principalId; 054 } 055 056 public DetachedNuxeoPrincipal(String principalId, String name, String firstName, String lastName, String password, 057 String email, String company, List<String> groups, List<String> allGroups, List<String> roles, 058 boolean isAdministrator, boolean isAnonymous) { 059 this.password = principalId; 060 this.name = name; 061 this.firstName = firstName; 062 this.lastName = lastName; 063 this.password = password; 064 this.email = email; 065 this.company = company; 066 this.groups = groups; 067 this.allGroups = allGroups; 068 this.roles = roles; 069 this.isAdministrator = isAdministrator; 070 this.isAnonymous = isAnonymous; 071 } 072 073 private static final long serialVersionUID = 1L; 074 075 protected String principalId; 076 077 protected String name; 078 079 protected String firstName; 080 081 protected String lastName; 082 083 protected String password; 084 085 protected String email; 086 087 protected String company; 088 089 protected List<String> groups; 090 091 protected List<String> allGroups; 092 093 protected List<String> roles; 094 095 protected boolean isAdministrator; 096 097 protected boolean isAnonymous; 098 099 public String getName() { 100 return name; 101 } 102 103 public String getFirstName() { 104 return firstName; 105 } 106 107 public String getLastName() { 108 return lastName; 109 } 110 111 public String getPassword() { 112 return password; 113 } 114 115 public String getCompany() { 116 return company; 117 } 118 119 public String getEmail() { 120 return email; 121 } 122 123 public List<String> getGroups() { 124 return groups; 125 } 126 127 public List<String> getAllGroups() { 128 return allGroups; 129 } 130 131 public boolean isMemberOf(String group) { 132 throw new UnsupportedOperationException(); 133 } 134 135 public List<String> getRoles() { 136 return roles; 137 } 138 139 public void setName(String name) { 140 throw new UnsupportedOperationException(); 141 142 } 143 144 public void setFirstName(String firstName) { 145 throw new UnsupportedOperationException(); 146 147 } 148 149 public void setLastName(String lastName) { 150 throw new UnsupportedOperationException(); 151 } 152 153 public void setGroups(List<String> groups) { 154 throw new UnsupportedOperationException(); 155 156 } 157 158 public void setRoles(List<String> roles) { 159 throw new UnsupportedOperationException(); 160 161 } 162 163 @Override 164 public void setEmail(String email) { 165 this.email = email; 166 } 167 168 public void setCompany(String company) { 169 throw new UnsupportedOperationException(); 170 171 } 172 173 public void setPassword(String password) { 174 throw new UnsupportedOperationException(); 175 176 } 177 178 public String getPrincipalId() { 179 return principalId; 180 } 181 182 public void setPrincipalId(String principalId) { 183 throw new UnsupportedOperationException(); 184 } 185 186 public DocumentModel getModel() { 187 throw new UnsupportedOperationException(); 188 } 189 190 public void setModel(DocumentModel model) { 191 throw new UnsupportedOperationException(); 192 193 } 194 195 public boolean isAdministrator() { 196 return isAdministrator; 197 } 198 199 @Override 200 public String getTenantId() { 201 return null; 202 } 203 204 public boolean isAnonymous() { 205 return isAnonymous; 206 } 207 208 public String getOriginatingUser() { 209 throw new UnsupportedOperationException(); 210 } 211 212 public void setOriginatingUser(String originatingUser) { 213 throw new UnsupportedOperationException(); 214 } 215 216 @Override 217 public String getActingUser() { 218 return getName(); 219 } 220 221 @Override 222 public boolean isTransient() { 223 String name = getName(); 224 return name != null && name.startsWith(TRANSIENT_USER_PREFIX); 225 } 226}