Search in sources :

Example 1 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldNotUserWithoutValidPassword.

@Test(expected = BadCredentialsException.class)
public void shouldNotUserWithoutValidPassword() throws Exception {
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    UserDetails user = new User("jez", "something", true, true, true, true, new GrantedAuthority[0]);
    provider.additionalAuthenticationChecks(user, new UsernamePasswordAuthenticationToken("jez", "nothing"));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 2 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldThrowExceptionIfUsernameIsNotSpecifiedInFile.

@Test(expected = UsernameNotFoundException.class)
public void shouldThrowExceptionIfUsernameIsNotSpecifiedInFile() throws Exception {
    setupFile("jez=" + SHA1_BADGER);
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    provider.retrieveUser("blah", null);
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) Test(org.junit.Test)

Example 3 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldReturnUserPrincipleWithTheRightDisplayName.

@Test
public void shouldReturnUserPrincipleWithTheRightDisplayName() throws Exception {
    setupFile(String.format("jez=%s\ncharan=%s\nbabe=%s", SHA1_BADGER, SHA1_BADGER, SHA1_BADGER));
    when(userService.findUserByName("jez")).thenReturn(new com.thoughtworks.go.domain.User("jez", "Jezz Humbles", "jez@humble.com"));
    when(userService.findUserByName("charan")).thenReturn(new com.thoughtworks.go.domain.User("charan", "", "ch@ar.an"));
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, new AuthorityGranter(securityService), userService, securityService);
    GoUserPrinciple details = (GoUserPrinciple) provider.retrieveUser("jez", null);
    assertThat(details.getUsername(), is("jez"));
    assertThat(details.getDisplayName(), is("Jezz Humbles"));
    details = (GoUserPrinciple) provider.retrieveUser("charan", null);
    assertThat(details.getUsername(), is("charan"));
    assertThat(details.getDisplayName(), is("charan"));
    details = (GoUserPrinciple) provider.retrieveUser("babe", null);
    assertThat(details.getUsername(), is("babe"));
    assertThat(details.getDisplayName(), is("babe"));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) Test(org.junit.Test)

Example 4 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldAuthenticateUserWithValidPassword.

@Test
public void shouldAuthenticateUserWithValidPassword() throws Exception {
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    UserDetails user = new User("jez", SHA1_BADGER, true, true, true, true, new GrantedAuthority[0]);
    provider.additionalAuthenticationChecks(user, new UsernamePasswordAuthenticationToken("jez", "badger"));
}
Also used : AuthorityGranter(com.thoughtworks.go.server.security.AuthorityGranter) UserDetails(org.springframework.security.userdetails.UserDetails) User(org.springframework.security.userdetails.User) UsernamePasswordAuthenticationToken(org.springframework.security.providers.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 5 with AuthorityGranter

use of com.thoughtworks.go.server.security.AuthorityGranter in project gocd by gocd.

the class FileAuthenticationProviderTest method shouldRetrieveDetailsIfUsernameSpecifiedInFile.

@Test
public void shouldRetrieveDetailsIfUsernameSpecifiedInFile() throws Exception {
    setupFile("jez=" + SHA1_BADGER);
    AuthorityGranter authorityGranter = new AuthorityGranter(securityService);
    when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("jez")))).thenReturn(true);
    when(userService.findUserByName("jez")).thenReturn(new com.thoughtworks.go.domain.User("jez", "Jezz Humbles", "jez@humble.com"));
    FileAuthenticationProvider provider = new FileAuthenticationProvider(goConfigService, authorityGranter, userService, securityService);
    final UserDetails details = provider.retrieveUser("jez", 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("jez"));
    assertThat(details.getPassword(), is(SHA1_BADGER));
}
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)

Aggregations

AuthorityGranter (com.thoughtworks.go.server.security.AuthorityGranter)14 Test (org.junit.Test)8 TestingClock (com.thoughtworks.go.util.TestingClock)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 SecurityService (com.thoughtworks.go.server.service.SecurityService)4 UserDetails (org.springframework.security.userdetails.UserDetails)4 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)3 AuthorizationExtension (com.thoughtworks.go.plugin.access.authorization.AuthorizationExtension)3 Username (com.thoughtworks.go.server.domain.Username)3 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)3 PluginRoleService (com.thoughtworks.go.server.service.PluginRoleService)3 UserService (com.thoughtworks.go.server.service.UserService)3 MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)2 AnonymousAuthenticationProvider (com.thoughtworks.go.server.newsecurity.providers.AnonymousAuthenticationProvider)2 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)2 FilterChain (javax.servlet.FilterChain)2 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)2 User (org.springframework.security.userdetails.User)2 LdapConfig (com.thoughtworks.go.config.LdapConfig)1