]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3153 Add missing deprecated tag and move property from SecurityRealmFactory...
authorJulien Lancelot <julien.lancelot@gmail.com>
Mon, 25 Mar 2013 14:52:48 +0000 (15:52 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Mon, 25 Mar 2013 14:53:05 +0000 (15:53 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-server/src/main/java/org/sonar/server/ui/SecurityRealmFactory.java
sonar-server/src/test/java/org/sonar/server/ui/SecurityRealmFactoryTest.java

index 13f32b04e95f7dad69e634707c2277ec781cedc4..32f3875774b2ed8aeb79e39f64ccb017cdb227a2 100644 (file)
@@ -351,7 +351,7 @@ import java.util.List;
   // SERVER-SIDE TECHNICAL PROPERTIES
 
   @Property(
-    key = "sonar.security.realm",
+    key = CoreProperties.CORE_AUTHENTICATOR_REALM,
     name = "Security Realm",
     project = false,
     global = false
index 910e7b4460f91abff8c0b6628b8e7bf6e8f572e4..6cdd0293530ced13d5f3f401b105b1ccdccd57f5 100644 (file)
@@ -153,7 +153,18 @@ public interface CoreProperties {
   String CORE_DEFAULT_GROUP = "sonar.defaultGroup";
   String CORE_DEFAULT_GROUP_DEFAULT_VALUE = "sonar-users";
   boolean CORE_ALLOW_USERS_TO_SIGNUP_DEAULT_VALUE = false;
+
+  /**
+   * @deprecated since 2.14. See http://jira.codehaus.org/browse/SONAR-3153
+   */
+  @Deprecated
   String CORE_AUTHENTICATOR_CLASS = "sonar.authenticator.class";
+
+  /**
+   * @since 2.14
+   */
+  String CORE_AUTHENTICATOR_REALM = "sonar.security.realm";
+
   String CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE = "sonar.authenticator.ignoreStartupFailure";
   String CORE_AUTHENTICATOR_CREATE_USERS = "sonar.authenticator.createUsers";
   String SERVER_VERSION = "sonar.core.version";
index 23c1f653d0f1c209e36a44054118eb71fa3e2a5a..6bff033f901e1b6abdca86a8b9f6c760212c0f58 100644 (file)
@@ -39,17 +39,15 @@ public class SecurityRealmFactory implements ServerComponent {
   private final boolean ignoreStartupFailure;
   private final SecurityRealm realm;
 
-  static final String REALM_PROPERTY = "sonar.security.realm";
-
   public SecurityRealmFactory(Settings settings, SecurityRealm[] realms, LoginPasswordAuthenticator[] authenticators) {
     ignoreStartupFailure = settings.getBoolean(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE);
-    String realmName = settings.getString(REALM_PROPERTY);
+    String realmName = settings.getString(CoreProperties.CORE_AUTHENTICATOR_REALM);
     String className = settings.getString(CoreProperties.CORE_AUTHENTICATOR_CLASS);
     SecurityRealm selectedRealm = null;
     if (!StringUtils.isEmpty(realmName)) {
       selectedRealm = selectRealm(realms, realmName);
       if (selectedRealm == null) {
-        throw new SonarException("Realm '" + realmName + "' not found. Please check the property '" + REALM_PROPERTY + "' in conf/sonar.properties");
+        throw new SonarException("Realm '" + realmName + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_REALM + "' in conf/sonar.properties");
       }
     }
     if (selectedRealm == null && !StringUtils.isEmpty(className)) {
index 2e5904a9661c534cacd9b3b30138c9f049e7d06f..74c3708ba99101bb964a30324ebc1090ac75d00c 100644 (file)
@@ -27,7 +27,10 @@ import org.sonar.api.security.LoginPasswordAuthenticator;
 import org.sonar.api.security.SecurityRealm;
 import org.sonar.api.utils.SonarException;
 
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.spy;
@@ -46,26 +49,26 @@ public class SecurityRealmFactoryTest {
    * Typical usage.
    */
   @Test
-  public void shouldSelectRealmAndStart() {
+  public void should_select_realm_and_start() {
     SecurityRealm realm = spy(new FakeRealm());
-    settings.setProperty(SecurityRealmFactory.REALM_PROPERTY, realm.getName());
+    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
 
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[] {realm});
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm});
     factory.start();
     assertThat(factory.getRealm(), is(realm));
     verify(realm).init();
   }
 
   @Test
-  public void doNotFailIfNoRealms() {
+  public void do_not_fail_if_no_realms() {
     SecurityRealmFactory factory = new SecurityRealmFactory(settings);
     factory.start();
     assertThat(factory.getRealm(), nullValue());
   }
 
   @Test
-  public void realmNotFound() {
-    settings.setProperty(SecurityRealmFactory.REALM_PROPERTY, "Fake");
+  public void realm_not_found() {
+    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, "Fake");
 
     try {
       new SecurityRealmFactory(settings);
@@ -76,29 +79,29 @@ public class SecurityRealmFactoryTest {
   }
 
   @Test
-  public void shouldProvideCompatibilityForAuthenticator() {
+  public void should_provide_compatibility_for_authenticator() {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
     LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
 
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[] {authenticator});
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[]{authenticator});
     SecurityRealm realm = factory.getRealm();
     assertThat(realm, instanceOf(CompatibilityRealm.class));
   }
 
   @Test
-  public void shouldTakePrecedenceOverAuthenticator() {
+  public void should_take_precedence_over_authenticator() {
     SecurityRealm realm = new FakeRealm();
-    settings.setProperty(SecurityRealmFactory.REALM_PROPERTY, realm.getName());
+    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
     LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
 
-    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[] {realm},
-        new LoginPasswordAuthenticator[] {authenticator});
+    SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm},
+        new LoginPasswordAuthenticator[]{authenticator});
     assertThat(factory.getRealm(), is(realm));
   }
 
   @Test
-  public void authenticatorNotFound() {
+  public void authenticator_not_found() {
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, "Fake");
 
     try {
@@ -110,22 +113,22 @@ public class SecurityRealmFactoryTest {
   }
 
   @Test
-  public void ignoreStartupFailure() {
+  public void ignore_startup_failure() {
     SecurityRealm realm = spy(new AlwaysFailsRealm());
-    settings.setProperty(SecurityRealmFactory.REALM_PROPERTY, realm.getName());
+    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
     settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, true);
 
-    new SecurityRealmFactory(settings, new SecurityRealm[] {realm}).start();
+    new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
     verify(realm).init();
   }
 
   @Test
-  public void shouldFail() {
+  public void should_fail() {
     SecurityRealm realm = spy(new AlwaysFailsRealm());
-    settings.setProperty(SecurityRealmFactory.REALM_PROPERTY, realm.getName());
+    settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
 
     try {
-      new SecurityRealmFactory(settings, new SecurityRealm[] {realm}).start();
+      new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
       fail();
     } catch (SonarException e) {
       assertThat(e.getCause(), instanceOf(IllegalStateException.class));