Search in sources :

Example 1 with AuthPluginInfoViewModel

use of com.thoughtworks.go.server.ui.AuthPluginInfoViewModel in project gocd by gocd.

the class SecurityAuthConfigService method getAllConfiguredWebBasedAuthorizationPlugins.

public List<AuthPluginInfoViewModel> getAllConfiguredWebBasedAuthorizationPlugins() {
    ArrayList<AuthPluginInfoViewModel> result = new ArrayList();
    Set<AuthorizationPluginInfo> loadedWebBasedAuthPlugins = authorizationMetadataStore.getPluginsThatSupportsWebBasedAuthentication();
    SecurityAuthConfigs configuredAuthPluginProfiles = getPluginProfiles();
    for (SecurityAuthConfig authConfig : configuredAuthPluginProfiles) {
        AuthorizationPluginInfo authorizationPluginInfo = loadedWebBasedAuthPlugins.stream().filter(authorizationPluginInfo1 -> authorizationPluginInfo1.getDescriptor().id().equals(authConfig.getPluginId())).findFirst().orElse(null);
        if (authorizationPluginInfo != null) {
            result.add(new AuthPluginInfoViewModel(authorizationPluginInfo));
        }
    }
    return result;
}
Also used : SecurityAuthConfig(com.thoughtworks.go.config.SecurityAuthConfig) ArrayList(java.util.ArrayList) AuthorizationPluginInfo(com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo) SecurityAuthConfigs(com.thoughtworks.go.config.SecurityAuthConfigs) AuthPluginInfoViewModel(com.thoughtworks.go.server.ui.AuthPluginInfoViewModel)

Example 2 with AuthPluginInfoViewModel

use of com.thoughtworks.go.server.ui.AuthPluginInfoViewModel 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.jupiter.api.Test)

Aggregations

SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)2 AuthPluginInfoViewModel (com.thoughtworks.go.server.ui.AuthPluginInfoViewModel)2 SecurityAuthConfigs (com.thoughtworks.go.config.SecurityAuthConfigs)1 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1