use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class X509AuthoritiesPopulatorTest method shouldReturnUserDetailsWithCorrectAuthorityIfAgentCertificateHasOu.
@Test
public void shouldReturnUserDetailsWithCorrectAuthorityIfAgentCertificateHasOu() {
X509Certificate agentCertificate = new X509CertificateGenerator().createCertificateWithDn("CN=hostname, OU=agent").getFirstCertificate();
UserDetails userDetails = populator.getUserDetails(agentCertificate);
GrantedAuthority[] actual = userDetails.getAuthorities();
GrantedAuthority expected = new GrantedAuthorityImpl(ROLE_AGENT);
assertThat(actual.length, is(1));
assertThat(actual[0], is(expected));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class AuthorityGranterTest method shouldGrantTemplateSupervisorRoleToTemplateAdmins.
@Test
public void shouldGrantTemplateSupervisorRoleToTemplateAdmins() throws Exception {
String templateAdmin = "template-admin";
when(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString(templateAdmin)))).thenReturn(true);
GrantedAuthority[] authorities = authorityGranter.authorities(templateAdmin);
assertThat(authorities, hasItemInArray(GoAuthority.ROLE_TEMPLATE_SUPERVISOR.asAuthority()));
assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority())));
assertThat(authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class GoVelocityViewTest method shouldSetGroupAdministratorIfUserIsAPipelineGroupAdministrator.
@Test
public void shouldSetGroupAdministratorIfUserIsAPipelineGroupAdministrator() throws Exception {
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_GROUP_SUPERVISOR.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.ADMINISTRATOR), is(nullValue()));
assertThat(velocityContext.get(GoVelocityView.GROUP_ADMINISTRATOR), is(true));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class GoVelocityViewTest method shouldSetAdministratorIfUserIsAdministrator.
@Test
public void shouldSetAdministratorIfUserIsAdministrator() throws Exception {
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_SUPERVISOR.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.ADMINISTRATOR), is(true));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class UserHelperTest method stubSecurityContextForRole.
public static void stubSecurityContextForRole(String roleName) {
GrantedAuthority agentAuth = mock(GrantedAuthority.class);
when(agentAuth.getAuthority()).thenReturn(roleName);
GrantedAuthority[] grantedAuthorities = roleName == null ? new GrantedAuthority[] {} : new GrantedAuthority[] { agentAuth };
stubSecurityContextForGrantedAuthorities(grantedAuthorities);
}
Aggregations