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: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.usermanager; 021 022import java.io.Serializable; 023import java.util.ArrayList; 024import java.util.HashMap; 025import java.util.LinkedHashMap; 026import java.util.List; 027import java.util.Map; 028import java.util.regex.Pattern; 029 030import org.nuxeo.common.xmap.annotation.XNode; 031import org.nuxeo.common.xmap.annotation.XNodeList; 032import org.nuxeo.common.xmap.annotation.XNodeMap; 033import org.nuxeo.common.xmap.annotation.XObject; 034import org.nuxeo.ecm.platform.usermanager.UserManager.MatchType; 035 036/** 037 * APG-240 All attributes are defined public because the user manager service do not get access to the fields. OSGI 038 * don't allow splitted packages having access to public members defined from an another package provider. 039 * 040 * @author matic 041 */ 042@XObject(value = "userManager") 043public class UserManagerDescriptor implements Serializable { 044 045 private static final long serialVersionUID = 1L; 046 047 @XNode("@class") 048 public Class<?> userManagerClass; 049 050 @XNode("defaultGroup") 051 public String defaultGroup; 052 053 @XNodeList(value = "defaultAdministratorId", type = ArrayList.class, componentType = String.class) 054 public List<String> defaultAdministratorIds; 055 056 @XNodeList(value = "administratorsGroup", type = ArrayList.class, componentType = String.class) 057 public List<String> administratorsGroups; 058 059 @XNode("disableDefaultAdministratorsGroup") 060 public Boolean disableDefaultAdministratorsGroup; 061 062 @XNode("userSortField") 063 public String userSortField; 064 065 @XNode("groupSortField") 066 public String groupSortField; 067 068 @XNode("users/directory") 069 public String userDirectoryName; 070 071 @XNode("users/emailField") 072 public String userEmailField; 073 074 @XNode("users/listingMode") 075 public String userListingMode; 076 077 // BBB old syntax 078 @XNode("userListingMode") 079 public void setUserListingMode(String userListingMode) { 080 this.userListingMode = userListingMode; 081 } 082 083 public boolean userSearchFieldsPresent = false; 084 085 @XNode("users/searchFields") 086 public void setUserSearchFieldsPresent(@SuppressWarnings("unused") String text) { 087 userSearchFieldsPresent = true; 088 } 089 090 @XNode("users/searchFields@append") 091 public boolean userSearchFieldsAppend; 092 093 public Map<String, MatchType> userSearchFields = new LinkedHashMap<String, MatchType>(); 094 095 @XNodeList(value = "users/searchFields/exactMatchSearchField", componentType = String.class, type = String[].class) 096 public void setExactMatchUserSearchFields(String[] fields) { 097 for (String field : fields) { 098 userSearchFields.put(field, MatchType.EXACT); 099 } 100 } 101 102 @XNodeList(value = "users/searchFields/substringMatchSearchField", componentType = String.class, type = String[].class) 103 public void setSubstringMatchUserSearchFields(String[] fields) { 104 for (String field : fields) { 105 userSearchFields.put(field, MatchType.SUBSTRING); 106 } 107 } 108 109 /** 110 * @deprecated use setSubstringMatchUserSearchFields instead 111 */ 112 @Deprecated 113 @XNodeList(value = "users/searchFields/searchField", componentType = String.class, type = String[].class) 114 public void setUserSearchFields(String[] fields) { 115 setSubstringMatchUserSearchFields(fields); 116 } 117 118 public Pattern userPasswordPattern; 119 120 @XNode("userPasswordPattern") 121 public void setUserPasswordPattern(String pattern) { 122 userPasswordPattern = Pattern.compile(pattern); 123 } 124 125 @XNode("users/anonymousUser") 126 public VirtualUserDescriptor anonymousUser; 127 128 @XNodeMap(value = "users/virtualUser", key = "@id", type = HashMap.class, componentType = VirtualUserDescriptor.class) 129 public Map<String, VirtualUserDescriptor> virtualUsers; 130 131 @XNode("groups/directory") 132 public String groupDirectoryName; 133 134 @XNode("groups/groupLabelField") 135 public String groupLabelField; 136 137 @XNode("groups/membersField") 138 public String groupMembersField; 139 140 @XNode("groups/subGroupsField") 141 public String groupSubGroupsField; 142 143 @XNode("groups/parentGroupsField") 144 public String groupParentGroupsField; 145 146 @XNode("groups/listingMode") 147 public String groupListingMode; 148 149 public boolean groupSearchFieldsPresent = false; 150 151 @XNode("groups/searchFields") 152 public void setGroupSearchFieldsPresent(@SuppressWarnings("unused") String text) { 153 groupSearchFieldsPresent = true; 154 } 155 156 @XNode("groups/searchFields@append") 157 public boolean groupSearchFieldsAppend; 158 159 public Map<String, MatchType> groupSearchFields = new LinkedHashMap<String, MatchType>(); 160 161 @XNodeList(value = "groups/searchFields/exactMatchSearchField", componentType = String.class, type = String[].class) 162 public void setExactMatchGroupSearchFields(String[] fields) { 163 for (String field : fields) { 164 groupSearchFields.put(field, MatchType.EXACT); 165 } 166 } 167 168 @XNodeList(value = "groups/searchFields/substringMatchSearchField", componentType = String.class, type = String[].class) 169 public void setSubstringMatchGroupSearchFields(String[] fields) { 170 for (String field : fields) { 171 groupSearchFields.put(field, MatchType.SUBSTRING); 172 } 173 } 174 175 @XNode("digestAuthDirectory") 176 public String digestAuthDirectory; 177 178 @XNode("digestAuthRealm") 179 public String digestAuthRealm; 180 181 @XNode("userCacheName") 182 public String userCacheName; 183 184 /** 185 * Merge with data from another descriptor. 186 */ 187 public void merge(UserManagerDescriptor other) { 188 if (other.userManagerClass != null) { 189 userManagerClass = other.userManagerClass; 190 } 191 if (other.userCacheName != null) { 192 userCacheName = other.userCacheName; 193 } 194 if (other.userListingMode != null) { 195 userListingMode = other.userListingMode; 196 } 197 if (other.groupListingMode != null) { 198 groupListingMode = other.groupListingMode; 199 } 200 if (other.defaultGroup != null) { 201 defaultGroup = other.defaultGroup; 202 } 203 if (other.defaultAdministratorIds != null) { 204 if (defaultAdministratorIds == null) { 205 defaultAdministratorIds = new ArrayList<String>(); 206 } 207 defaultAdministratorIds.addAll(other.defaultAdministratorIds); 208 } 209 if (other.administratorsGroups != null) { 210 if (administratorsGroups == null) { 211 administratorsGroups = new ArrayList<String>(); 212 } 213 administratorsGroups.addAll(other.administratorsGroups); 214 } 215 if (other.disableDefaultAdministratorsGroup != null) { 216 disableDefaultAdministratorsGroup = other.disableDefaultAdministratorsGroup; 217 } 218 if (other.userSearchFieldsPresent) { 219 if (other.userSearchFieldsAppend) { 220 userSearchFields.putAll(other.userSearchFields); 221 } else { 222 userSearchFields = other.userSearchFields; 223 } 224 } 225 226 if (other.userSortField != null) { 227 userSortField = other.userSortField; 228 } 229 if (other.groupSortField != null) { 230 groupSortField = other.groupSortField; 231 } 232 if (other.userDirectoryName != null) { 233 userDirectoryName = other.userDirectoryName; 234 } 235 if (other.userEmailField != null) { 236 userEmailField = other.userEmailField; 237 } 238 if (other.userSearchFieldsPresent) { 239 if (other.userSearchFieldsAppend) { 240 userSearchFields.putAll(other.userSearchFields); 241 } else { 242 userSearchFields = other.userSearchFields; 243 } 244 } 245 if (other.userPasswordPattern != null) { 246 userPasswordPattern = other.userPasswordPattern; 247 } 248 if (other.groupDirectoryName != null) { 249 groupDirectoryName = other.groupDirectoryName; 250 } 251 if (other.groupLabelField != null) { 252 groupLabelField = other.groupLabelField; 253 } 254 if (other.groupMembersField != null) { 255 groupMembersField = other.groupMembersField; 256 } 257 if (other.groupSubGroupsField != null) { 258 groupSubGroupsField = other.groupSubGroupsField; 259 } 260 if (other.groupParentGroupsField != null) { 261 groupParentGroupsField = other.groupParentGroupsField; 262 } 263 if (other.groupSearchFieldsPresent) { 264 if (other.groupSearchFieldsAppend) { 265 groupSearchFields.putAll(other.groupSearchFields); 266 } else { 267 groupSearchFields = other.groupSearchFields; 268 } 269 } 270 if (other.anonymousUser != null) { 271 if (other.anonymousUser.remove) { 272 anonymousUser = null; 273 } else { 274 anonymousUser = other.anonymousUser; 275 } 276 } 277 if (other.virtualUsers != null) { 278 if (virtualUsers == null) { 279 virtualUsers = other.virtualUsers; 280 } else { 281 for (VirtualUserDescriptor otherVirtualUser : other.virtualUsers.values()) { 282 if (virtualUsers.containsKey(otherVirtualUser.id) && otherVirtualUser.remove) { 283 virtualUsers.remove(otherVirtualUser.id); 284 } else { 285 virtualUsers.put(otherVirtualUser.id, otherVirtualUser); 286 } 287 } 288 } 289 } 290 if (other.digestAuthDirectory != null) { 291 digestAuthDirectory = other.digestAuthDirectory; 292 } 293 if (other.digestAuthRealm != null) { 294 digestAuthRealm = other.digestAuthRealm; 295 } 296 } 297 298}