Search in sources :

Example 11 with SecurityConfig

use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.

the class SecurityAuthConfigServiceTest method shouldGetNullIfSecurityAuthConfigByGivenIdIsNotPresent.

@Test
public void shouldGetNullIfSecurityAuthConfigByGivenIdIsNotPresent() {
    when(goConfigService.security()).thenReturn(new SecurityConfig());
    assertNull(securityAuthConfigService.findProfile("ldap"));
}
Also used : SecurityConfig(com.thoughtworks.go.config.SecurityConfig) Test(org.junit.jupiter.api.Test)

Example 12 with SecurityConfig

use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.

the class PasswordBasedPluginAuthenticationProviderTest method setUp.

@BeforeEach
void setUp() {
    SecurityService securityService = mock(SecurityService.class);
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    GoConfigService goConfigService = mock(GoConfigService.class);
    userService = mock(UserService.class);
    authorizationExtension = mock(AuthorizationExtension.class);
    pluginRoleService = mock(PluginRoleService.class);
    clock = new TestingClock();
    securityConfig = new SecurityConfig();
    when(goConfigService.security()).thenReturn(securityConfig);
    provider = new PasswordBasedPluginAuthenticationProvider(authorizationExtension, authorityGranter, goConfigService, pluginRoleService, userService, clock);
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserService(com.thoughtworks.go.server.service.UserService) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) SecurityService(com.thoughtworks.go.server.service.SecurityService) AuthorizationExtension(com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension) PluginRoleService(com.thoughtworks.go.server.service.PluginRoleService) TestingClock(com.thoughtworks.go.util.TestingClock) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with SecurityConfig

use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.

the class FileAuthenticationProviderTest method setupFile.

private void setupFile(String userAndPasswordAndRoles) throws IOException {
    final File passwordFile = TestFileUtil.createTempFile("password.properties");
    passwordFile.deleteOnExit();
    FileUtils.writeStringToFile(passwordFile, userAndPasswordAndRoles);
    final SecurityConfig securityConfig = new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig(passwordFile.getAbsolutePath()), true, null);
    when(goConfigService.security()).thenReturn(securityConfig);
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) GoCipher(com.thoughtworks.go.security.GoCipher) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) File(java.io.File) PasswordFileConfig(com.thoughtworks.go.config.PasswordFileConfig)

Example 14 with SecurityConfig

use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.

the class UserSearchServiceTest method shouldAddPluginSearchResults.

@Test
public void shouldAddPluginSearchResults() throws Exception {
    String searchTerm = "foo";
    User foo = new User("foo", new ArrayList<>(), "foo@cruise.com", false);
    User bar = new User("bar-foo", new ArrayList<>(), "bar@go.com", true);
    when(ldapUserSearch.search(searchTerm)).thenReturn(Arrays.asList(foo, bar));
    List<String> pluginIds = Arrays.asList("plugin-id-1", "plugin-id-2", "plugin-id-3", "plugin-id-4");
    when(metadataStore.getPluginsThatSupportsUserSearch()).thenReturn(new HashSet<>(pluginIds));
    when(authorizationExtension.canHandlePlugin(anyString())).thenReturn(true);
    when(goConfigService.security()).thenReturn(new SecurityConfig());
    when(authorizationExtension.searchUsers("plugin-id-1", searchTerm, Collections.emptyList())).thenReturn(Arrays.asList(getPluginUser(1)));
    when(authorizationExtension.searchUsers("plugin-id-2", searchTerm, Collections.emptyList())).thenReturn(Arrays.asList(getPluginUser(2), getPluginUser(3)));
    when(authorizationExtension.searchUsers("plugin-id-3", searchTerm, Collections.emptyList())).thenReturn(new ArrayList<>());
    when(authorizationExtension.searchUsers("plugin-id-4", searchTerm, Collections.emptyList())).thenReturn(Arrays.asList(new com.thoughtworks.go.plugin.access.authentication.models.User("username-" + 4, null, null)));
    List<UserSearchModel> models = userSearchService.search(searchTerm, new HttpLocalizedOperationResult());
    assertThat(models, is(Arrays.asList(new UserSearchModel(foo, UserSourceType.LDAP), new UserSearchModel(bar, UserSourceType.LDAP), new UserSearchModel(getUser(1), UserSourceType.PLUGIN), new UserSearchModel(getUser(2), UserSourceType.PLUGIN), new UserSearchModel(getUser(3), UserSourceType.PLUGIN), new UserSearchModel(new User("username-" + 4, "", ""), UserSourceType.PLUGIN))));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) User(com.thoughtworks.go.domain.User) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) UserSearchModel(com.thoughtworks.go.presentation.UserSearchModel) Test(org.junit.Test)

Example 15 with SecurityConfig

use of com.thoughtworks.go.config.SecurityConfig in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldThrowExceptionIfFileDoesNotExist.

@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionIfFileDoesNotExist() throws Exception {
    when(goConfigService.security()).thenReturn(new SecurityConfig(new LdapConfig(new GoCipher()), new PasswordFileConfig("ueyrweiyri"), true, null));
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    provider.retrieveUser("blah", null);
}
Also used : LdapConfig(com.thoughtworks.go.config.LdapConfig) AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) GoCipher(com.thoughtworks.go.security.GoCipher) SecurityConfig(com.thoughtworks.go.config.SecurityConfig) PasswordFileConfig(com.thoughtworks.go.config.PasswordFileConfig) Test(org.junit.Test)

Aggregations

SecurityConfig (com.thoughtworks.go.config.SecurityConfig)28 Test (org.junit.jupiter.api.Test)9 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)6 LdapConfig (com.thoughtworks.go.config.LdapConfig)5 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)5 Before (org.junit.Before)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)4 PasswordFileConfig (com.thoughtworks.go.config.PasswordFileConfig)4 ServerConfig (com.thoughtworks.go.config.ServerConfig)4 AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)4 Test (org.junit.Test)4 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)2 GoCipher (com.thoughtworks.go.security.GoCipher)2 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)2 UserService (com.thoughtworks.go.server.service.UserService)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 FilterChain (javax.servlet.FilterChain)2