Search in sources :

Example 21 with AuthorizationPluginInfo

use of com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo in project gocd by gocd.

the class SecurityAuthConfigServiceTest method shouldGetAListOfAllConfiguredWebBasedAuthorizationPlugins.

@Test
public void shouldGetAListOfAllConfiguredWebBasedAuthorizationPlugins() {
    Set<AuthorizationPluginInfo> installedWebBasedPlugins = new HashSet<>();
    String githubPluginId = "cd.go.github";
    AuthorizationPluginInfo githubPluginInfo = pluginInfo(githubPluginId, "GitHub Auth Plugin", SupportedAuthType.Web);
    installedWebBasedPlugins.add(githubPluginInfo);
    installedWebBasedPlugins.add(pluginInfo(githubPluginId, "Google Auth Plugin", SupportedAuthType.Web));
    when(authorizationMetadataStore.getPluginsThatSupportsWebBasedAuthentication()).thenReturn(installedWebBasedPlugins);
    when(authorizationMetadataStore.getPluginInfo(githubPluginId)).thenReturn(githubPluginInfo);
    SecurityConfig securityConfig = new SecurityConfig();
    SecurityAuthConfig github = new SecurityAuthConfig("github", githubPluginId);
    SecurityAuthConfig ldap = new SecurityAuthConfig("ldap", "cd.go.ldap");
    securityConfig.securityAuthConfigs().add(github);
    securityConfig.securityAuthConfigs().add(ldap);
    when(goConfigService.security()).thenReturn(securityConfig);
    List<AuthPluginInfoViewModel> allWebBasedAuthorizationConfigs = securityAuthConfigService.getAllConfiguredWebBasedAuthorizationPlugins();
    assertThat(allWebBasedAuthorizationConfigs.size(), is(1));
    AuthPluginInfoViewModel pluginInfoViewModel = allWebBasedAuthorizationConfigs.get(0);
    assertThat(pluginInfoViewModel.pluginId(), is(githubPluginId));
    assertThat(pluginInfoViewModel.name(), is("GitHub Auth Plugin"));
    assertThat(pluginInfoViewModel.imageUrl(), is("/go/api/plugin_images/cd.go.github/hash"));
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) AuthPluginInfoViewModel(com.thoughtworks.go.server.ui.AuthPluginInfoViewModel) Test(org.junit.Test)

Example 22 with AuthorizationPluginInfo

use of com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo in project gocd by gocd.

the class ConfigInfoProviderTest method shouldProvideSecurityInformationWhenNoAuthorizationPluginIsConfigured.

@Test
public void shouldProvideSecurityInformationWhenNoAuthorizationPluginIsConfigured() throws Exception {
    final GoConfigService goConfigService = goConfigService();
    final AuthorizationPluginInfo passwordFile = pluginInfo("cd.go.authentication.passwordfile", "Password File Authentication Plugin for GoCD");
    final AuthorizationPluginInfo ldap = pluginInfo("cd.go.authentication.ldap", "LDAP Authentication Plugin for GoCD");
    authorizationMetadataStore.setPluginInfo(passwordFile);
    authorizationMetadataStore.setPluginInfo(ldap);
    final Map<String, Object> map = new ConfigInfoProvider(goConfigService, authorizationMetadataStore).asJson();
    final Map<String, Object> security = (Map<String, Object>) map.get("Security");
    assertNotNull(security);
    assertThat(security, hasEntry("Enabled", false));
    assertThat(security, hasEntry("Plugins", new ArrayList<>()));
}
Also used : AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) ArrayList(java.util.ArrayList) Map(java.util.Map) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 23 with AuthorizationPluginInfo

use of com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo in project gocd by gocd.

the class ConfigInfoProviderTest method shouldProvideSecurityInformationWhenAuthorizationPluginsConfigured.

@Test
public void shouldProvideSecurityInformationWhenAuthorizationPluginsConfigured() throws Exception {
    final GoConfigService goConfigService = goConfigService();
    final AuthorizationPluginInfo passwordFile = pluginInfo("cd.go.authentication.passwordfile", "Password File Authentication Plugin for GoCD");
    final AuthorizationPluginInfo ldap = pluginInfo("cd.go.authentication.ldap", "LDAP Authentication Plugin for GoCD");
    authorizationMetadataStore.setPluginInfo(passwordFile);
    authorizationMetadataStore.setPluginInfo(ldap);
    goConfigService.security().securityAuthConfigs().add(new SecurityAuthConfig("file", "cd.go.authentication.passwordfile"));
    final Map<String, Object> map = new ConfigInfoProvider(goConfigService, authorizationMetadataStore).asJson();
    final Map<String, Object> security = (Map<String, Object>) map.get("Security");
    assertNotNull(security);
    assertThat(security, hasEntry("Enabled", true));
    final List<Map<String, Boolean>> plugins = (List<Map<String, Boolean>>) security.get("Plugins");
    assertThat(plugins, containsInAnyOrder(singletonMap("Password File Authentication Plugin for GoCD", true), singletonMap("LDAP Authentication Plugin for GoCD", false)));
}
Also used : AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 24 with AuthorizationPluginInfo

use of com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo in project gocd by gocd.

the class AuthPluginInfoViewModelTest method shouldGetDetailsAboutThePlugin.

@Test
public void shouldGetDetailsAboutThePlugin() {
    GoPluginDescriptor.About about = new GoPluginDescriptor.About("GitHub Auth Plugin", "1.0", null, null, null, null);
    String pluginId = "github";
    GoPluginDescriptor descriptor = new GoPluginDescriptor(pluginId, "1.0", about, null, null, false);
    AuthorizationPluginInfo pluginInfo = new AuthorizationPluginInfo(descriptor, null, null, new Image("svg", "data", "hash"), new Capabilities(SupportedAuthType.Web, true, true));
    AuthPluginInfoViewModel model = new AuthPluginInfoViewModel(pluginInfo);
    assertThat(model.imageUrl(), is("/go/api/plugin_images/github/hash"));
    assertThat(model.pluginId(), is("github"));
    assertThat(model.name(), is("GitHub Auth Plugin"));
}
Also used : Capabilities(com.thoughtworks.go.plugin.domain.authorization.Capabilities) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Image(com.thoughtworks.go.plugin.domain.common.Image) Test(org.junit.Test)

Aggregations

AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)24 Test (org.junit.Test)16 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)12 Capabilities (com.thoughtworks.go.plugin.domain.authorization.Capabilities)9 ArrayList (java.util.ArrayList)5 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)4 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)3 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)3 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)3 Image (com.thoughtworks.go.plugin.domain.common.Image)3 Map (java.util.Map)3 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 PluginDescriptor (com.thoughtworks.go.plugin.api.info.PluginDescriptor)2 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)2 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)2 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)2 AuthPluginInfoViewModel (com.thoughtworks.go.server.ui.AuthPluginInfoViewModel)2 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)1 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1