Browse Source

SONAR-3153 Add missing deprecated tag and move property from SecurityRealmFactory to CoreProperties

tags/3.6
Julien Lancelot 11 years ago
parent
commit
bc02f448a4

+ 1
- 1
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java View 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

+ 11
- 0
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java View 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";

+ 2
- 4
sonar-server/src/main/java/org/sonar/server/ui/SecurityRealmFactory.java View 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)) {

+ 23
- 20
sonar-server/src/test/java/org/sonar/server/ui/SecurityRealmFactoryTest.java View 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));

Loading…
Cancel
Save