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