You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LdapSettingsFactory.java 4.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.auth.ldap;
  21. import javax.annotation.Nullable;
  22. import org.sonar.api.config.internal.MapSettings;
  23. import org.sonar.auth.ldap.server.LdapServer;
  24. /**
  25. * Create Settings for most used test cases.
  26. */
  27. public class LdapSettingsFactory {
  28. /**
  29. * Generate simple settings for 2 ldap servers that allows anonymous access.
  30. *
  31. * @return The specific settings.
  32. */
  33. public static MapSettings generateSimpleAnonymousAccessSettings(LdapServer exampleServer, @Nullable LdapServer infosupportServer) {
  34. MapSettings settings = new MapSettings();
  35. if (infosupportServer != null) {
  36. settings.setProperty("ldap.servers", "example,infosupport");
  37. settings.setProperty("ldap.example.url", exampleServer.getUrl())
  38. .setProperty("ldap.example.user.baseDn", "ou=users,dc=example,dc=org")
  39. .setProperty("ldap.example.group.baseDn", "ou=groups,dc=example,dc=org");
  40. settings.setProperty("ldap.infosupport.url", infosupportServer.getUrl())
  41. .setProperty("ldap.infosupport.user.baseDn", "ou=users,dc=infosupport,dc=com")
  42. .setProperty("ldap.infosupport.group.baseDn", "ou=groups,dc=infosupport,dc=com");
  43. } else {
  44. settings.setProperty("ldap.url", exampleServer.getUrl())
  45. .setProperty("ldap.user.baseDn", "ou=users,dc=example,dc=org")
  46. .setProperty("ldap.group.baseDn", "ou=groups,dc=example,dc=org");
  47. }
  48. return settings;
  49. }
  50. /**
  51. * Generate settings for 2 ldap servers.
  52. *
  53. * @param exampleServer The first ldap server.
  54. * @param infosupportServer The second ldap server.
  55. * @return The specific settings.
  56. */
  57. public static MapSettings generateAuthenticationSettings(LdapServer exampleServer, @Nullable LdapServer infosupportServer, String authMethod) {
  58. MapSettings settings = new MapSettings();
  59. if (infosupportServer != null) {
  60. settings.setProperty("ldap.servers", "example,infosupport");
  61. settings.setProperty("ldap.example.url", exampleServer.getUrl())
  62. .setProperty("ldap.example.bindDn", LdapContextFactory.AUTH_METHOD_SIMPLE.equals(authMethod) ? "cn=bind,ou=users,dc=example,dc=org" : "bind")
  63. .setProperty("ldap.example.bindPassword", "bindpassword")
  64. .setProperty("ldap.example.authentication", authMethod)
  65. .setProperty("ldap.example.realm", "example.org")
  66. .setProperty("ldap.example.user.baseDn", "ou=users,dc=example,dc=org")
  67. .setProperty("ldap.example.group.baseDn", "ou=groups,dc=example,dc=org");
  68. settings.setProperty("ldap.infosupport.url", infosupportServer.getUrl())
  69. .setProperty("ldap.infosupport.bindDn", LdapContextFactory.AUTH_METHOD_SIMPLE.equals(authMethod) ? "cn=bind,ou=users,dc=infosupport,dc=com" : "bind")
  70. .setProperty("ldap.infosupport.bindPassword", "bindpassword")
  71. .setProperty("ldap.infosupport.authentication", authMethod)
  72. .setProperty("ldap.infosupport.realm", "infosupport.com")
  73. .setProperty("ldap.infosupport.user.baseDn", "ou=users,dc=infosupport,dc=com")
  74. .setProperty("ldap.infosupport.group.baseDn", "ou=groups,dc=infosupport,dc=com");
  75. } else {
  76. settings.setProperty("ldap.url", exampleServer.getUrl())
  77. .setProperty("ldap.bindDn", LdapContextFactory.AUTH_METHOD_SIMPLE.equals(authMethod) ? "cn=bind,ou=users,dc=example,dc=org" : "bind")
  78. .setProperty("ldap.bindPassword", "bindpassword")
  79. .setProperty("ldap.authentication", authMethod)
  80. .setProperty("ldap.realm", "example.org")
  81. .setProperty("ldap.user.baseDn", "ou=users,dc=example,dc=org")
  82. .setProperty("ldap.group.baseDn", "ou=groups,dc=example,dc=org");
  83. }
  84. return settings;
  85. }
  86. }