Search in sources :

Example 11 with UserDetails

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

the class FileAuthenticationProviderTest method shouldHandleApacheFormatFile.

@Test
public void shouldHandleApacheFormatFile() throws IOException {
    setupFile("cread:{SHA}OPhRtj5TCERacn3mvwItERz8uCk=");
    when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("cread")))).thenReturn(true);
    when(userService.findUserByName("cread")).thenReturn(new com.thoughtworks.go.domain.User("cread", "Chriss Readds", "cread@humble.com"));
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    final UserDetails details = provider.retrieveUser("cread", null);
    assertThat(details.getAuthorities()[0].getAuthority(), is("ROLE_SUPERVISOR"));
    assertThat(details.isAccountNonExpired(), is(true));
    assertThat(details.isAccountNonLocked(), is(true));
    assertThat(details.isCredentialsNonExpired(), is(true));
    assertThat(details.isEnabled(), is(true));
    assertThat(details.getUsername(), is("cread"));
    assertThat(details.getPassword(), is("OPhRtj5TCERacn3mvwItERz8uCk="));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) Username(com.thoughtworks.go.server.domain.Username) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 12 with UserDetails

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

the class IntegrationTestsFixture method login.

public static void login(String username, String password) {
    UserDetails principal = new User(username, password, true, true, true, true, new GrantedAuthority[0]);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(principal, password));
}
Also used : UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken)

Aggregations

UserDetails (org.springframework.security.userdetails.UserDetails)12 Test (org.junit.Test)9 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)4 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)4 User (org.springframework.security.userdetails.User)4 User (com.thoughtworks.go.plugin.access.authentication.models.User)3 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 AuthenticationResponse (com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse)2 Username (com.thoughtworks.go.server.domain.Username)2 OauthAuthenticationToken (com.thoughtworks.go.server.security.OauthAuthenticationToken)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 GrantedAuthority (org.springframework.security.GrantedAuthority)2 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)1 X509CertificateGenerator (com.thoughtworks.go.security.X509CertificateGenerator)1 OauthDataSource (com.thoughtworks.go.server.oauth.OauthDataSource)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 BadCredentialsException (org.springframework.security.BadCredentialsException)1 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)1