use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.
the class SonarQubeMonitorTest method get_realm.
@Test
public void get_realm() throws Exception {
SecurityRealm realm = mock(SecurityRealm.class);
when(realm.getName()).thenReturn("LDAP");
when(securityRealmFactory.getRealm()).thenReturn(realm);
Map<String, Object> attributes = underTest.attributes();
assertThat(attributes).containsEntry("External User Authentication", "LDAP");
}
use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.
the class SecurityRealmFactoryTest method ignore_startup_failure.
@Test
public void ignore_startup_failure() {
SecurityRealm realm = spy(new AlwaysFailsRealm());
settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, true);
new SecurityRealmFactory(settings, new SecurityRealm[] { realm }).start();
verify(realm).init();
}
use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.
the class SecurityRealmFactoryTest method should_fail.
@Test
public void should_fail() {
SecurityRealm realm = spy(new AlwaysFailsRealm());
settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
try {
new SecurityRealmFactory(settings, new SecurityRealm[] { realm }).start();
fail();
} catch (SonarException e) {
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("Security realm fails to start");
}
}
use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.
the class SecurityRealmFactoryTest method should_select_realm_and_start.
/**
* Typical usage.
*/
@Test
public void should_select_realm_and_start() {
SecurityRealm realm = spy(new FakeRealm());
settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[] { realm });
factory.start();
assertThat(factory.getRealm()).isSameAs(realm);
assertThat(factory.hasExternalAuthentication()).isTrue();
verify(realm).init();
factory.stop();
}
use of org.sonar.api.security.SecurityRealm in project sonarqube by SonarSource.
the class SecurityRealmFactoryTest method should_provide_compatibility_for_authenticator.
@Test
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 });
SecurityRealm realm = factory.getRealm();
assertThat(realm).isInstanceOf(CompatibilityRealm.class);
}
Aggregations