Search in sources :

Example 11 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class RemoveAdminPermissionFilterIntegrationTest method setupAuthentication.

private Authentication setupAuthentication() {
    GrantedAuthority[] authorities = {};
    Authentication authentication = new TestingAuthenticationToken(new User("loser", "secret", true, true, true, true, authorities), null, authorities);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    authentication.setAuthenticated(true);
    return authentication;
}
Also used : User(org.springframework.security.userdetails.User) Authentication(org.springframework.security.Authentication) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken)

Example 12 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class ReAuthenticationFilterTest method setupAuthentication.

private Authentication setupAuthentication() {
    GrantedAuthority[] authorities = {};
    Authentication authentication = new TestingAuthenticationToken(new User("user", "password", true, true, true, true, authorities), null, authorities);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    authentication.setAuthenticated(true);
    return authentication;
}
Also used : User(org.springframework.security.userdetails.User) Authentication(org.springframework.security.Authentication) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken)

Example 13 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class ScheduleStageTest method shouldRerunJobsWithUserAsApprover.

@Test
public void shouldRerunJobsWithUserAsApprover() throws Exception {
    Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
    Stage oldStage = pipeline.getStages().byName(fixture.devStage);
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
    HttpOperationResult result = new HttpOperationResult();
    Stage newStage = scheduleService.rerunJobs(oldStage, a("foo", "foo3"), result);
    Stage loadedLatestStage = dbHelper.getStageDao().findStageWithIdentifier(newStage.getIdentifier());
    assertThat(loadedLatestStage.getApprovedBy(), is("loser"));
    assertThat(oldStage.getApprovedBy(), is(not("loser")));
    assertThat(result.canContinue(), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) User(org.springframework.security.userdetails.User) SecurityContext(org.springframework.security.context.SecurityContext) Stage(com.thoughtworks.go.domain.Stage) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 14 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class OauthAuthenticationFilterTest method shouldAuthenticateToken.

@Test
public void shouldAuthenticateToken() throws IOException, ServletException {
    when(req.getHeader(OauthAuthenticationFilter.AUTHORIZATION)).thenReturn("Token token=\"valid-token\"");
    OauthAuthenticationToken authenticatedToken = new OauthAuthenticationToken(new User("user-name", "valid-token", true, true, true, true, new GrantedAuthority[] { GoAuthority.ROLE_SUPERVISOR.asAuthority() }));
    when(authenticationManager.authenticate(new OauthAuthenticationToken("valid-token"))).thenReturn(authenticatedToken);
    filter.doFilterHttp(req, res, chain);
    verify(securityContext).setAuthentication(authenticatedToken);
    verify(chain).doFilter(req, res);
//assertThat(logFixture.contains(Level.DEBUG, "Oauth authorization header: Token token=\"valid-token\""), is(true));//uncomment this to run it locally (this fails on build, we need to find out why). -Rajesh & JJ
}
Also used : User(org.springframework.security.userdetails.User) GrantedAuthority(org.springframework.security.GrantedAuthority) Test(org.junit.Test)

Example 15 with User

use of org.springframework.security.userdetails.User in project gocd by gocd.

the class GoFileConfigDataSourceTest method setup.

@Before
public void setup() throws Exception {
    systemEnvironment = new SystemEnvironment();
    systemEnvironment.setProperty(SystemEnvironment.OPTIMIZE_FULL_CONFIG_SAVE.propertyName(), "false");
    configHelper = new GoConfigFileHelper();
    configHelper.onSetUp();
    configRepository = new ConfigRepository(systemEnvironment);
    configRepository.initialize();
    timeProvider = mock(TimeProvider.class);
    fullConfigSaveMergeFlow = mock(FullConfigSaveMergeFlow.class);
    fullConfigSaveNormalFlow = mock(FullConfigSaveNormalFlow.class);
    when(timeProvider.currentTime()).thenReturn(new Date());
    ServerVersion serverVersion = new ServerVersion();
    ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    ServerHealthService serverHealthService = new ServerHealthService();
    cachedGoPartials = new CachedGoPartials(serverHealthService);
    dataSource = new GoFileConfigDataSource(new GoConfigMigration(new GoConfigMigration.UpgradeFailedHandler() {

        public void handle(Exception e) {
            throw new RuntimeException(e);
        }
    }, configRepository, new TimeProvider(), configCache, registry), configRepository, systemEnvironment, timeProvider, configCache, serverVersion, registry, mock(ServerHealthService.class), cachedGoPartials, fullConfigSaveMergeFlow, fullConfigSaveNormalFlow);
    dataSource.upgradeIfNecessary();
    CachedGoConfig cachedGoConfig = new CachedGoConfig(serverHealthService, dataSource, mock(CachedGoPartials.class), null, null);
    cachedGoConfig.loadConfigIfNull();
    goConfigDao = new GoConfigDao(cachedGoConfig);
    configHelper.load();
    configHelper.usingCruiseConfigDao(goConfigDao);
    GoConfigWatchList configWatchList = new GoConfigWatchList(cachedGoConfig);
    ConfigElementImplementationRegistry configElementImplementationRegistry = new ConfigElementImplementationRegistry(new NoPluginsInstalled());
    GoConfigPluginService configPluginService = new GoConfigPluginService(mock(ConfigRepoExtension.class), new ConfigCache(), configElementImplementationRegistry, cachedGoConfig);
    repoConfig = new ConfigRepoConfig(new GitMaterialConfig("url"), "plugin");
    configHelper.addConfigRepo(repoConfig);
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
}
Also used : ServerVersion(com.thoughtworks.go.server.util.ServerVersion) User(org.springframework.security.userdetails.User) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) ServerHealthService(com.thoughtworks.go.serverhealth.ServerHealthService) NoPluginsInstalled(com.thoughtworks.go.config.registry.NoPluginsInstalled) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ExpectedException(org.junit.rules.ExpectedException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) IOException(java.io.IOException) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) SecurityContext(org.springframework.security.context.SecurityContext) ConfigRepoExtension(com.thoughtworks.go.plugin.access.configrepo.ConfigRepoExtension) Before(org.junit.Before)

Aggregations

User (org.springframework.security.userdetails.User)17 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)10 Test (org.junit.Test)8 GrantedAuthority (org.springframework.security.GrantedAuthority)4 SecurityContext (org.springframework.security.context.SecurityContext)4 TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)4 UserDetails (org.springframework.security.userdetails.UserDetails)4 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)2 Before (org.junit.Before)2 Authentication (org.springframework.security.Authentication)2 BadCredentialsException (org.springframework.security.BadCredentialsException)2 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)2 SecurityContextImpl (org.springframework.security.context.SecurityContextImpl)2 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)1 NoPluginsInstalled (com.thoughtworks.go.config.registry.NoPluginsInstalled)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1