Search in sources :

Example 1 with User

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

the class GoFileConfigDataSourceTest method shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven.

@Test
public void shouldUse_UserFromSession_asConfigModifyingUserWhenNoneGiven() throws GitAPIException, IOException {
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(new UsernamePasswordAuthenticationToken(new User("loser_boozer", "pass", true, true, true, true, new GrantedAuthority[] {}), null));
    goConfigDao.updateMailHost(getMailHost("mailhost.local"));
    CruiseConfig cruiseConfig = goConfigDao.load();
    GoConfigRevision revision = configRepository.getRevision(cruiseConfig.getMd5());
    assertThat(revision.getUsername(), is("loser_boozer"));
}
Also used : User(org.springframework.security.userdetails.User) SecurityContext(org.springframework.security.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 2 with User

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

the class UserHelperTest method shouldGetNameFromUserDetails.

@Test
public void shouldGetNameFromUserDetails() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new User("user", "pass", true, false, true, true, new GrantedAuthority[0]), null, null);
    assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("user"));
}
Also used : User(org.springframework.security.userdetails.User) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 3 with User

use of org.springframework.security.userdetails.User 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 4 with User

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

the class X509AuthoritiesPopulator method getUserDetails.

public UserDetails getUserDetails(X509Certificate clientCert) throws AuthenticationException {
    X500Principal principal = clientCert.getSubjectX500Principal();
    Matcher cnMatcher = CN_PATTERN.matcher(principal.getName());
    Matcher ouMatcher = OU_PATTERN.matcher(principal.getName());
    if (cnMatcher.find() && ouMatcher.find()) {
        GrantedAuthorityImpl agentAuthority = new GrantedAuthorityImpl(role);
        return new User(cnMatcher.group(1), "", true, true, true, true, new GrantedAuthority[] { agentAuthority });
    }
    throw new BadCredentialsException("Couldn't find CN and/or OU for the certificate");
}
Also used : User(org.springframework.security.userdetails.User) GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) Matcher(java.util.regex.Matcher) X500Principal(javax.security.auth.x500.X500Principal) BadCredentialsException(org.springframework.security.BadCredentialsException)

Example 5 with User

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

the class OauthAuthenticationProvider method authenticate.

public OauthAuthenticationToken authenticate(Authentication authentication) throws AuthenticationException {
    OauthAuthenticationToken authenticationToken = (OauthAuthenticationToken) authentication;
    String token = authenticationToken.getCredentials();
    OauthDataSource.OauthTokenDTO oauthToken = oauthDataSource.findOauthTokenByAccessToken(token);
    if (oauthToken == null) {
        throw new BadCredentialsException("No match for OAuth token: " + token);
    }
    String username = oauthToken.getUserId();
    UserDetails user = new User(username, token, true, true, true, true, oauthAuthority());
    return new OauthAuthenticationToken(user);
}
Also used : UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) BadCredentialsException(org.springframework.security.BadCredentialsException) OauthDataSource(com.thoughtworks.go.server.oauth.OauthDataSource) OauthAuthenticationToken(com.thoughtworks.go.server.security.OauthAuthenticationToken)

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