use of org.springframework.security.context.SecurityContext in project gocd by gocd.
the class ConfigModifyingUserTest method shouldIdentifyLoggedInUserAsModifyingUser_WhenNoModifyingUserIsGiven.
@Test
public void shouldIdentifyLoggedInUserAsModifyingUser_WhenNoModifyingUserIsGiven() {
SecurityContext context = SecurityContextHolder.getContext();
context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
ConfigModifyingUser user = new ConfigModifyingUser();
assertThat(user.getUserName(), is("loser_boozer"));
}
use of org.springframework.security.context.SecurityContext 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, mock(GoConfigService.class));
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));
}
use of org.springframework.security.context.SecurityContext 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));
}
use of org.springframework.security.context.SecurityContext in project gocd by gocd.
the class UserHelperTest method stubSecurityContextForGrantedAuthorities.
private static void stubSecurityContextForGrantedAuthorities(GrantedAuthority[] grantedAuthorities) {
SecurityContext context = mock(SecurityContext.class);
Authentication authentication = mock(Authentication.class);
when(context.getAuthentication()).thenReturn(authentication);
when(authentication.getAuthorities()).thenReturn(grantedAuthorities);
SecurityContextHolder.setContext(context);
}
Aggregations