1 package org.enhydra.shark.usergroup; 2 3 import org.enhydra.shark.api.internal.working.CallbackUtilities; 4 5 11 public class LDAPOptions { 12 private int ldapPort; 13 private int searchScope = 2; private boolean attributeOnly = false; private String ldapHost; 16 private int structureType; 18 private String searchBase; 19 private String userObjectClasses; 20 private String groupObjectClasses; 21 private String relationObjectClasses; private String groupUniqueAttributeName; 23 private String groupDescriptionAttributeName; 24 private String userUniqueAttributeName; 25 private String relationUniqueAttributeName; private String relationMemberAttributeName; private String userPasswordAttributeName; 28 private String userRealNameAttributeName; 29 private String userFirstNameAttributeName; 30 private String userLastNameAttributeName; 31 private String userEmailAttributeName; 32 private String ldapUser; 33 private String ldapPassword; 34 private String groupGroupsName; 35 private String groupUsersName; 36 private String groupGroupRelationsName; 37 private String groupUserRelationsName; 38 39 private CallbackUtilities cus; 40 public LDAPOptions (CallbackUtilities cus) { 41 this.cus=cus; 42 java.util.Properties properties=cus.getProperties(); 43 try { 44 ldapPort=Integer.valueOf(properties.getProperty("LDAPPort")).intValue(); 45 } catch (Exception ex) { 46 cus.error("LDAPOptions -> Port invalid, using default port 389"); 47 ldapPort=389 ; 48 } 49 50 try { 51 structureType=Integer.valueOf(properties.getProperty("LDAPStructureType")).intValue(); 52 } catch (Exception ex) { 53 cus.error("LDAPOptions -> Structure type invalid, using default - complex"); 54 structureType=1; 55 } 56 if (structureType<0 || structureType>1) { 57 cus.error("LDAPOptions -> Structure type invalid, using default - complex"); 58 structureType=1; 59 } 60 61 63 try { 64 ldapHost=properties.getProperty("LDAPHost"); 65 } catch (Exception ex) { 66 cus.error("LDAPOptions -> Host invalid, using default localhost"); 67 ldapHost="localhost"; 68 } 69 if (ldapHost==null) { 70 cus.error("LDAPOptions -> Host invalid, using default localhost"); 71 ldapHost="localhost"; 72 } 73 74 try { 75 searchBase=properties.getProperty("LDAPSearchBase"); 76 } catch (Exception ex) { 77 cus.error("LDAPOptions -> Search base invalid, not using search base"); 78 searchBase=""; 79 } 80 if (searchBase==null) { 81 cus.error("LDAPOptions -> Search base invalid, not using search base"); 82 searchBase=""; 83 } 84 85 try { 86 groupObjectClasses=properties.getProperty("LDAPGroupObjectClasses"); 87 } catch (Exception ex) { 88 cus.error("LDAPOptions -> Group object classes filter invalid, using organizationalUnit"); 89 groupObjectClasses="organizationalUnit"; 90 } 91 if (groupObjectClasses==null) { 92 cus.error("LDAPOptions -> Group object classes filter invalid, using organizationalUnit"); 93 groupObjectClasses="organizationalUnit"; 94 } 95 96 if (structureType == 1){ 97 try { 98 relationObjectClasses=properties.getProperty("LDAPRelationObjectClasses"); 99 } catch (Exception ex) { 100 cus.error("LDAPOptions -> Relation object classes filter invalid, using groupOfNames"); 101 relationObjectClasses="groupOfNames"; 102 } 103 if (relationObjectClasses==null) { 104 cus.error("LDAPOptions -> Relation object classes filter invalid, using groupOfNames"); 105 relationObjectClasses="groupOfNames"; 106 } 107 } 108 109 try { 110 userObjectClasses=properties.getProperty("LDAPUserObjectClasses"); 111 } catch (Exception ex) { 112 cus.error("LDAPOptions -> User object classes filter invalid, using inetOrgPerson"); 113 userObjectClasses="inetOrgPerson"; 114 } 115 if (userObjectClasses==null) { 116 cus.error("LDAPOptions -> User object classes filter invalid, using inetOrgPerson"); 117 userObjectClasses="inetOrgPerson"; 118 } 119 120 try { 121 groupUniqueAttributeName=properties.getProperty("LDAPGroupUniqueAttributeName"); 122 } catch (Exception ex) { 123 cus.error("LDAPOptions -> Group unique attribute name invalid, using ou"); 124 groupUniqueAttributeName="ou"; 125 } 126 if (groupUniqueAttributeName==null) { 127 cus.error("LDAPOptions -> Group unique attribute name invalid, using ou"); 128 groupUniqueAttributeName="ou"; 129 } 130 131 try { 132 groupDescriptionAttributeName=properties.getProperty("LDAPGroupDescriptionAttributeName"); 133 } catch (Exception ex) { 134 cus.error("LDAPOptions -> Group description attribute name invalid, using description"); 135 groupDescriptionAttributeName="description"; 136 } 137 if (groupDescriptionAttributeName==null) { 138 cus.error("LDAPOptions -> Group description attribute name invalid, using description"); 139 groupDescriptionAttributeName="description"; 140 } 141 142 try { 143 userUniqueAttributeName=properties.getProperty("LDAPUserUniqueAttributeName"); 144 } catch (Exception ex) { 145 cus.error("LDAPOptions -> User unique attribute name invalid, using uid"); 146 userUniqueAttributeName="uid"; 147 } 148 if (userUniqueAttributeName==null) { 149 cus.error("LDAPOptions -> User unique attribute name invalid, using uid"); 150 userUniqueAttributeName="uid"; 151 } 152 153 if (structureType == 1) { 154 try { 155 relationUniqueAttributeName=properties.getProperty("LDAPRelationUniqueAttributeName"); 156 } catch (Exception ex) { 157 cus.error("LDAPOptions -> relation unique attribute name invalid, using cn"); 158 relationUniqueAttributeName="cn"; 159 } 160 if (relationUniqueAttributeName==null) { 161 cus.error("LDAPOptions -> relation unique attribute name invalid, using cn"); 162 relationUniqueAttributeName="cn"; 163 } 164 } 165 166 if (structureType == 1) { 167 try { 168 relationMemberAttributeName=properties.getProperty("LDAPRelationMemberAttributeName"); 169 } catch (Exception ex) { 170 cus.error("LDAPOptions -> relation member attribute name invalid, using member"); 171 relationMemberAttributeName="member"; 172 } 173 if (relationMemberAttributeName==null) { 174 cus.error("LDAPOptions -> relation member attribute name invalid, using member"); 175 relationMemberAttributeName="member"; 176 } 177 } 178 179 try { 180 userPasswordAttributeName=properties.getProperty("LDAPUserPasswordAttributeName"); 181 } catch (Exception ex) { 182 cus.error("LDAPOptions -> User password attribute name invalid, using password"); 183 userPasswordAttributeName="password"; 184 } 185 if (userPasswordAttributeName==null) { 186 cus.error("LDAPOptions -> User password attribute name invalid, using password"); 187 userPasswordAttributeName="password"; 188 } 189 190 try { 191 userRealNameAttributeName=properties.getProperty("LDAPUserRealNameAttributeName"); 192 } catch (Exception ex) { 193 cus.error("LDAPOptions -> User real name attribute name invalid, using cn"); 194 userRealNameAttributeName="cn"; 195 } 196 if (userRealNameAttributeName==null) { 197 cus.error("LDAPOptions -> User real name attribute name invalid, using cn"); 198 userRealNameAttributeName="cn"; 199 } 200 201 try { 202 userFirstNameAttributeName=properties.getProperty("LDAPUserFirstNameAttributeName"); 203 } catch (Exception ex) { 204 cus.error("LDAPOptions -> User first name attribute name invalid, using givenName"); 205 userFirstNameAttributeName="givenName"; 206 } 207 if (userFirstNameAttributeName==null) { 208 cus.error("LDAPOptions -> User first name attribute name invalid, using givenName"); 209 userFirstNameAttributeName="givenName"; 210 } 211 212 try { 213 userLastNameAttributeName=properties.getProperty("LDAPUserLastNameAttributeName"); 214 } catch (Exception ex) { 215 cus.error("LDAPOptions -> User last name attribute name invalid, using sn"); 216 userLastNameAttributeName="sn"; 217 } 218 if (userLastNameAttributeName==null) { 219 cus.error("LDAPOptions -> User last name attribute name invalid, using sn"); 220 userLastNameAttributeName="sn"; 221 } 222 223 try { 224 userEmailAttributeName=properties.getProperty("LDAPUserEmailAttributeName"); 225 } catch (Exception ex) { 226 cus.error("LDAPOptions -> User email attribute name invalid, using mail"); 227 userEmailAttributeName="mail"; 228 } 229 if (userEmailAttributeName==null) { 230 cus.error("LDAPOptions -> User email attribute name invalid, using mail"); 231 userEmailAttributeName="mail"; 232 } 233 234 try { 235 ldapUser=properties.getProperty("LDAPUser"); 236 } catch (Exception ex) { 237 cus.error("LDAPOptions -> User invalid, leaving empty"); 238 ldapUser=""; 239 } 240 if (ldapUser==null) { 241 cus.error("LDAPOptions -> User invalid, leaving empty"); 242 ldapUser=""; 243 } 244 245 try { 246 ldapPassword=properties.getProperty("LDAPPassword"); 247 } catch (Exception ex) { 248 cus.error("LDAPOptions -> Password invalid, leaving empty"); 249 ldapPassword=""; 250 } 251 if (ldapPassword==null) { 252 cus.error("LDAPOptions -> Password invalid, leaving empty"); 253 ldapPassword=""; 254 } 255 256 if (structureType == 1){ 257 try { 258 groupGroupsName=properties.getProperty("LDAPGroupGroupsName"); 259 } catch (Exception ex) { 260 cus.error("LDAPOptions -> Name of group groups invalid, using Groups"); 261 groupGroupsName="Groups"; 262 } 263 if (groupGroupsName==null) { 264 cus.error("LDAPOptions -> Name of group groups invalid, using Groups"); 265 groupGroupsName="Groups"; 266 } 267 268 try { 269 groupUsersName=properties.getProperty("LDAPGroupUsersName"); 270 } catch (Exception ex) { 271 cus.error("LDAPOptions -> Name of group users invalid, using Users"); 272 groupUsersName="Users"; 273 } 274 if (groupUsersName==null) { 275 cus.error("LDAPOptions -> Name of group users invalid, using Users"); 276 groupUsersName="Users"; 277 } 278 279 try { 280 groupGroupRelationsName=properties.getProperty("LDAPGroupGroupRelationsName"); 281 } catch (Exception ex) { 282 cus.error("LDAPOptions -> Name of group group relations invalid, using GroupRelations"); 283 groupGroupRelationsName="GroupRelations"; 284 } 285 if (groupGroupRelationsName==null) { 286 cus.error("LDAPOptions -> Name of group group relations invalid, using GroupRelations"); 287 groupGroupRelationsName="GroupRelations"; 288 } 289 290 try { 291 groupUserRelationsName=properties.getProperty("LDAPGroupUserRelationsName"); 292 } catch (Exception ex) { 293 cus.error("LDAPOptions -> Name of group user relations invalid, using UserRelations"); 294 groupUserRelationsName="UserRelations"; 295 } 296 if (groupUserRelationsName==null) { 297 cus.error("LDAPOptions -> Name of group user relations invalid, using UserRelations"); 298 groupUserRelationsName="UserRelations"; 299 } 300 301 } 303 } 304 305 public int getPort () { 306 return ldapPort; 307 } 308 309 public void setPort (int port) { 310 this.ldapPort=port; 311 } 312 313 public int getStructureType () { 314 return structureType; 315 } 316 317 public void setStructureType (int structureType) { 318 this.structureType=structureType; 319 } 320 321 public int getSearchScope () { 322 return searchScope; 323 } 324 325 public boolean getAttributeOnly () { 326 return attributeOnly; 327 } 328 329 public void setAttributeOnly (boolean attrOnly) { 330 this.attributeOnly=attrOnly; 331 } 332 333 public String getHost () { 334 return ldapHost; 335 } 336 337 public void setHost (String host) { 338 this.ldapHost=host; 339 } 340 341 public String getSearchBase () { 342 return searchBase; 343 } 344 345 public void setSearchBase (String searchBase) { 346 this.searchBase=searchBase; 347 } 348 349 public String getGroupObjectClasses () { 350 return groupObjectClasses; 351 } 352 353 public void setGroupObjectClasses (String groupObjectClasses) { 354 this.groupObjectClasses=groupObjectClasses; 355 } 356 357 public String getRelationObjectClasses () { 358 return relationObjectClasses; 359 } 360 361 public void setRelationObjectClasses (String relationObjectClasses) { 362 this.relationObjectClasses=relationObjectClasses; 363 } 364 365 public String getUserObjectClasses () { 366 return userObjectClasses; 367 } 368 369 public void setUserObjectClasses (String userObjectClasses) { 370 this.userObjectClasses=userObjectClasses; 371 } 372 373 public String getGroupUniqueAttributeName () { 374 return groupUniqueAttributeName; 375 } 376 377 public void setGroupUniqueAttributeName (String groupUniqueAttributeName) { 378 this.groupUniqueAttributeName=groupUniqueAttributeName; 379 } 380 381 public String getGroupDescriptionAttributeName () { 382 return groupDescriptionAttributeName; 383 } 384 385 public void setGroupDescriptionAttributeName (String groupDescriptionAttributeName) { 386 this.groupDescriptionAttributeName=groupDescriptionAttributeName; 387 } 388 389 public String getUserUniqueAttributeName () { 390 return userUniqueAttributeName; 391 } 392 393 public void setUserUniqueAttributeName (String userUniqueAttributeName) { 394 this.userUniqueAttributeName=userUniqueAttributeName; 395 } 396 397 public String getRelationUniqueAttributeName () { 398 return relationUniqueAttributeName; 399 } 400 401 public void setRelationUniqueAttributeName (String relationUniqueAttributeName) { 402 this.relationUniqueAttributeName=relationUniqueAttributeName; 403 } 404 405 public String getRelationMemberAttributeName () { 406 return relationMemberAttributeName; 407 } 408 409 public void setRelationMemberAttributeName (String relationMemberAttributeName) { 410 this.relationMemberAttributeName=relationMemberAttributeName; 411 } 412 413 public String getUserPasswordAttributeName () { 414 return userPasswordAttributeName; 415 } 416 417 public void setUserPasswordAttributeName (String userPasswordAttributeName) { 418 this.userPasswordAttributeName=userPasswordAttributeName; 419 } 420 421 public String getUserRealNameAttributeName () { 422 return userRealNameAttributeName; 423 } 424 425 public void setUserRealNameAttributeName(String userRealNameAttributeName) { 426 this.userRealNameAttributeName=userRealNameAttributeName; 427 } 428 429 public String getUserFirstNameAttributeName () { 430 return userFirstNameAttributeName; 431 } 432 433 public void setUserFirstNameAttributeName(String userFirstNameAttributeName) { 434 this.userFirstNameAttributeName=userFirstNameAttributeName; 435 } 436 437 public String getUserLastNameAttributeName () { 438 return userLastNameAttributeName; 439 } 440 441 public void setUserLastNameAttributeName(String userLastNameAttributeName) { 442 this.userLastNameAttributeName=userLastNameAttributeName; 443 } 444 445 public String getUserEmailAttributeName () { 446 return userEmailAttributeName; 447 } 448 449 public void setUserEmailAttributeName(String userEmailAttributeName) { 450 this.userEmailAttributeName=userEmailAttributeName; 451 } 452 453 public String getUser () { 454 return ldapUser; 455 } 456 457 public void setUser (String user) { 458 this.ldapUser=user; 459 } 460 461 public String getPassword () { 462 return ldapPassword; 463 } 464 465 public void setPassword (String password) { 466 this.ldapPassword=password; 467 } 468 469 public String getGroupGroupsName () { 470 return groupGroupsName; 471 } 472 473 public void setGroupGroupsName (String groupGroupsName) { 474 this.groupGroupsName=groupGroupsName; 475 } 476 477 public String getGroupUsersName () { 478 return groupUsersName; 479 } 480 481 public void setGroupUsersName (String groupUsersName) { 482 this.groupUsersName=groupUsersName; 483 } 484 485 public String getGroupGroupRelationsName () { 486 return groupGroupRelationsName; 487 } 488 489 public void setGroupGroupRelationsName (String groupGroupRelationsName) { 490 this.groupGroupRelationsName=groupGroupRelationsName; 491 } 492 493 public String getGroupUserRelationsName () { 494 return groupUserRelationsName; 495 } 496 497 public void setGroupUserRelationsName (String groupUserRelationsName) { 498 this.groupUserRelationsName=groupUserRelationsName; 499 } 500 501 } 502 503 | Popular Tags |