use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class AuthorityGranterTest method shouldGrantGroupSupervisorRoleToPipelineGroupAdmins.
@Test
public void shouldGrantGroupSupervisorRoleToPipelineGroupAdmins() {
when(securityService.isUserGroupAdmin(new Username(new CaseInsensitiveString("group-admin")))).thenReturn(true);
GrantedAuthority[] authorities = authorityGranter.authorities("group-admin");
assertThat("Should not have " + GoAuthority.ROLE_SUPERVISOR + " authority", authorities, not(hasItemInArray(GoAuthority.ROLE_SUPERVISOR.asAuthority())));
assertThat("Should have " + GoAuthority.ROLE_GROUP_SUPERVISOR + " authority", authorities, hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority()));
assertThat("Should have " + GoAuthority.ROLE_USER + " authority", authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class RemoveAdminPermissionFilterIntegrationTest method setupAuthentication.
private Authentication setupAuthentication() {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new User("loser", "secret", true, true, true, true, authorities), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class LdapAuthenticationTest method commonLdapUserShouldOnlyHaveAuthorityOfUserAndNotAdmin.
@Test
public void commonLdapUserShouldOnlyHaveAuthorityOfUserAndNotAdmin() throws Exception {
ldapServer.addUser(employeesOrgUnit, "foleys", "some-password", "Shilpa Foley", "foleys@somecompany.com");
configFileHelper.initializeConfigFile();
configFileHelper.addLdapSecurityWithAdmin(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, SEARCH_BASE, SEARCH_FILTER, "another_admin");
Authentication authentication = new UsernamePasswordAuthenticationToken("foleys", "some-password");
Authentication result = ldapAuthenticationProvider.authenticate(authentication);
assertThat(result.isAuthenticated(), is(true));
GrantedAuthority[] authorities = result.getAuthorities();
assertThat("foleys should have only user authority. Found: " + ArrayUtils.toString(authorities), authorities.length, is(1));
assertThat(authorities[0].getAuthority(), is("ROLE_USER"));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class ReAuthenticationFilterTest method setupAuthentication.
private Authentication setupAuthentication() {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new User("user", "password", true, true, true, true, authorities), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class OauthAuthenticationFilterTest method shouldAuthenticateToken.
@Test
public void shouldAuthenticateToken() throws IOException, ServletException {
when(req.getHeader(OauthAuthenticationFilter.AUTHORIZATION)).thenReturn("Token token=\"valid-token\"");
OauthAuthenticationToken authenticatedToken = new OauthAuthenticationToken(new User("user-name", "valid-token", true, true, true, true, new GrantedAuthority[] { GoAuthority.ROLE_SUPERVISOR.asAuthority() }));
when(authenticationManager.authenticate(new OauthAuthenticationToken("valid-token"))).thenReturn(authenticatedToken);
filter.doFilterHttp(req, res, chain);
verify(securityContext).setAuthentication(authenticatedToken);
verify(chain).doFilter(req, res);
//assertThat(logFixture.contains(Level.DEBUG, "Oauth authorization header: Token token=\"valid-token\""), is(true));//uncomment this to run it locally (this fails on build, we need to find out why). -Rajesh & JJ
}
Aggregations