APISonar


com.thoughtworks.go.server.service.GoConfigService.security

> com > thoughtworks > go > server > service > GoConfigService > security
com APIs thoughtworks APIs go APIs server APIs service APIs GoConfigService APIs security APIs

Example 1
private GoConfigService goConfigService;

    public Permissions permissionsForEmptyGroup(PipelineConfigs group) {
        PipelineGroupsSecurityHelper security = new PipelineGroupsSecurityHelper(goConfigService.security());
        return groupPermissionsOnPipeline(security, group, null);
    }
Example 2
private GoConfigService configService;

    private Map<CaseInsensitiveString, Permissions> getPipelinesAndTheirPermissions() {
        when(configService.security()).thenReturn(config.server().security());
        when(configService.groups()).thenReturn(config.getGroups());

        return service.pipelinesAndTheirPermissions();
    }
Example 3
private GoConfigService goConfigService;

    private Map<CaseInsensitiveString, Permissions> pipelinesInGroupsAndTheirPermissions(PipelineGroups groups) {
        final Map<CaseInsensitiveString, Permissions> pipelinesAndTheirPermissions = new HashMap<>();

        PipelineGroupsSecurityHelper security = new PipelineGroupsSecurityHelper(goConfigService.security());

        groups.accept(group -> {
            for (PipelineConfig pipeline : group) {
                pipelinesAndTheirPermissions.put(pipeline.name(), groupPermissionsOnPipeline(security, group, pipeline));
            }
        });

        return pipelinesAndTheirPermissions;
    }
Example 4
private final GoConfigService goConfigService;

    private Properties loadPasswordFile() throws IOException {
        final String passwordFilePath = goConfigService.security().passwordFileConfig().path();
        final Properties properties = new Properties();
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(passwordFilePath);
            properties.load(inputStream);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
        return properties;
    }
Example 5
private final GoConfigService goConfigService;

    public List<User> search(String username) {
        SecurityConfig securityConfig = goConfigService.security();
        return search(username, securityConfig.ldapConfig());
    }
Example 6
private final GoConfigService goConfigService;

    public boolean supports(Class authentication) {
        SecurityConfig securityConfig = goConfigService.security();
        if (!securityConfig.isSecurityEnabled() || !securityConfig.ldapConfig().isEnabled()) {
            return false;
        }
        return super.supports(authentication);
    }
Example 7
private GoConfigService goConfigService;

    private AllowedUsers pipelineOperators(PipelineConfig pipeline, Set<String> admins, AllowedUsers groupLevelOperators, Map<String, Collection<String>> rolesToUsers) {
        if (!pipeline.first().hasOperatePermissionDefined()) {
            return groupLevelOperators;
        }

        Set<String> stageLevelApproversOfFirstStage = namesOf(pipeline.first().getApproval().getAuthConfig(), rolesToUsers);
        Set<PluginRoleConfig> stageLevelPluginRoleApproversOfFirstStage = pluginRolesFor(goConfigService.security(), pipeline.first().getApproval().getAuthConfig().getRoles());

        Set<String> pipelineOperators = new HashSet<>();
        pipelineOperators.addAll(admins);
        pipelineOperators.addAll(stageLevelApproversOfFirstStage);

        return new AllowedUsers(pipelineOperators, stageLevelPluginRoleApproversOfFirstStage);
    }
Example 8
private GoConfigService goConfigService;

    public void shouldNotInitializeDelegatorWhenAnLDAPConfigurationIsRemovedFromOurConfig() {
        LdapContextFactory factory = new LdapContextFactory(goConfigService);
        when(goConfigService.security()).thenReturn(new SecurityConfig(new LdapConfig(goCipher), new PasswordFileConfig(), true));
        try {
            factory.initializeDelegator();
        } catch (Exception e) {
            e.printStackTrace();
            fail("should not have thrown an execption");
        }
        verify(goConfigService).security();
    }
Example 9
private final GoConfigService goConfigService;

    private GoApiResponse processRoleConfigRequest(GoPluginDescriptor pluginDescriptor, GoApiRequest request) {
        AuthorizationMessageConverter messageConverter = extension.getMessageConverter(request.apiVersion());
        String authConfigId = messageConverter.processGetRoleConfigsRequest(request.requestBody());

        SecurityAuthConfig securityAuthConfig = goConfigService.security().securityAuthConfigs().findByPluginIdAndProfileId(pluginDescriptor.id(), authConfigId);

        List<PluginRoleConfig> roles = new ArrayList<>();
        if (securityAuthConfig != null) {
            roles = goConfigService.security().getRoles().getPluginRolesConfig(authConfigId);
        }

        return DefaultGoApiResponse.success(messageConverter.getProcessRoleConfigsResponseBody(roles));
    }
Example 10
private GoConfigService goConfigService;

    public void setUp() throws Exception {
        initMocks(this);
        when(pluginDescriptor.id()).thenReturn("cd.go.authorization.github");
        stub(goConfigService.security()).toReturn(securityConfig);
        securityAuthConfigsSpy = spy(new SecurityAuthConfigs());
        stub(securityConfig.securityAuthConfigs()).toReturn(securityAuthConfigsSpy);
    }
Example 11
private GoConfigService goConfigService;

    private List<com.thoughtworks.go.plugin.domain.authorization.User> getUsersConfiguredViaPlugin(String pluginId, String searchTerm) {
        List<com.thoughtworks.go.plugin.domain.authorization.User> users = new ArrayList<>();
        if (authorizationExtension.canHandlePlugin(pluginId)) {
            List<SecurityAuthConfig> authConfigs = goConfigService.security().securityAuthConfigs().findByPluginId(pluginId);
            users.addAll(authorizationExtension.searchUsers(pluginId, searchTerm, authConfigs));
        }
        return users;
    }
Example 12
private final GoConfigService goConfigService;

    protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
        final String passwordFilePath = goConfigService.security().passwordFileConfig().path();
        try {
            UserMap userMap = UserMapEditor.addUsersFromProperties(new UserMap(),
                    addDummyRoleToPropertiesIfRequired(stripShaFromPasswordsIfRequired(loadPasswordFile(passwordFilePath))));
            final UserDetails details = userMap.getUser(username);
            return userStrippedOfAnyAuthoritiesSpecifiedInFile(username, details);
        } catch (IOException e) {
            throw new UsernameNotFoundException(
                    "Trying to authenticate user " + username + " but could not open file: " + passwordFilePath);
        }

    }
Example 13
private GoConfigService goConfigService;

    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);
    }
Example 14
private GoConfigService goConfigService;

    public void shouldNotEngageWhenPasswordFileIsNotConfigured() throws Exception {
        FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, null, userService, securityService);
        when(goConfigService.security()).thenReturn(new SecurityConfig(null, new PasswordFileConfig(), true));
        assertThat(provider.supports(UsernamePasswordAuthenticationToken.class), is(false));
    }
Example 15
private GoConfigService goConfigService;

    public void setUp() {
        goConfigService = mock(GoConfigService.class);
        contextFactory = mock(SpringSecurityContextSource.class);
        securityConfig = mock(SecurityConfig.class);
        ldapTemplate = mock(LdapTemplate.class);
        logger = mock(Logger.class);
        ldapUserSearch = new LdapUserSearch(goConfigService, contextFactory, ldapTemplate, logger);
        when(goConfigService.security()).thenReturn(securityConfig);
        spy = spy(ldapUserSearch);
    }
Example 16
private GoConfigService goConfigService;

    public void setUp() {
        initMocks(this);

        when(authenticationToken.getCredentials()).thenReturn("password");
        userAuthority = GoAuthority.ROLE_USER.asAuthority();
        when(authorityGranter.authorities("username")).thenReturn(new GrantedAuthority[]{userAuthority});

        provider = new PluginAuthenticationProvider(authenticationPluginRegistry, authenticationExtension, authorizationExtension, store, authorityGranter,
                goConfigService, pluginRoleService, userService);

        securityConfig = new SecurityConfig();
        when(goConfigService.security()).thenReturn(securityConfig);
    }
Example 17
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(true);
        when(goConfigService.security()).thenReturn(securityConfig);

        provider = new PasswordBasedPluginAuthenticationProvider(authorizationExtension, authorityGranter, goConfigService, pluginRoleService, userService, clock);
    }
Example 18
private GoConfigService goConfigService() {
        final GoConfigService goConfigService = mock(GoConfigService.class);
        final CruiseConfig cruiseConfig = mock(CruiseConfig.class);

        when(goConfigService.getCurrentConfig()).thenReturn(cruiseConfig);
        when(goConfigService.getAllPipelineConfigs()).thenReturn(emptyList());
        when(cruiseConfig.getEnvironments()).thenReturn(new EnvironmentsConfig());
        when(cruiseConfig.getAllUniqueMaterials()).thenReturn(emptySet());
        when(goConfigService.getSchedulableMaterials()).thenReturn(emptySet());
        when(goConfigService.security()).thenReturn(new SecurityConfig());
        return goConfigService;
    }