Search in sources :

Example 1 with SecurityContextImpl

use of org.springframework.security.context.SecurityContextImpl in project gocd by gocd.

the class GoConfigAdministrationControllerIntegrationTest method setCurrentUser.

private void setCurrentUser(String username) {
    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User(username, "", true, new GrantedAuthority[] {}), null));
    SecurityContextHolder.setContext(context);
}
Also used : SecurityContextImpl(org.springframework.security.context.SecurityContextImpl) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken)

Example 2 with SecurityContextImpl

use of org.springframework.security.context.SecurityContextImpl in project gocd by gocd.

the class SecurityContextHelper method setCurrentUserWithAuthorities.

public static void setCurrentUserWithAuthorities(String username, final GrantedAuthority[] authorities) {
    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User(username, "", true, authorities), null, authorities));
    SecurityContextHolder.setContext(context);
}
Also used : SecurityContextImpl(org.springframework.security.context.SecurityContextImpl) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken)

Example 3 with SecurityContextImpl

use of org.springframework.security.context.SecurityContextImpl in project gocd by gocd.

the class GoVelocityViewTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    when(featureToggleService.isToggleOn(anyString())).thenReturn(true);
    Toggles.initializeWith(featureToggleService);
    view = spy(new GoVelocityView());
    doReturn(railsAssetsService).when(view).getRailsAssetsService();
    doReturn(versionInfoService).when(view).getVersionInfoService();
    request = new MockHttpServletRequest();
    velocityContext = new VelocityContext();
    securityContext = new SecurityContextImpl();
}
Also used : SecurityContextImpl(org.springframework.security.context.SecurityContextImpl) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) VelocityContext(org.apache.velocity.VelocityContext) Before(org.junit.Before)

Aggregations

SecurityContextImpl (org.springframework.security.context.SecurityContextImpl)3 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)2 User (org.springframework.security.userdetails.User)2 VelocityContext (org.apache.velocity.VelocityContext)1 Before (org.junit.Before)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1