use of org.springframework.security.GrantedAuthorityImpl in project gocd by gocd.
the class GoVelocityViewTest method shouldSetTemplateAdministratorIfUserIsTemplateAdministrator.
@Test
public void shouldSetTemplateAdministratorIfUserIsTemplateAdministrator() throws Exception {
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_TEMPLATE_SUPERVISOR.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.TEMPLATE_ADMINISTRATOR), is(true));
}
use of org.springframework.security.GrantedAuthorityImpl in project gocd by gocd.
the class GoVelocityViewTest method shouldSetViewAdministratorRightsIfUserHasAnyLevelOfAdministratorRights.
@Test
public void shouldSetViewAdministratorRightsIfUserHasAnyLevelOfAdministratorRights() throws Exception {
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_TEMPLATE_SUPERVISOR.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.VIEW_ADMINISTRATOR_RIGHTS), is(true));
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.VIEW_ADMINISTRATOR_RIGHTS), is(true));
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.VIEW_ADMINISTRATOR_RIGHTS), is(true));
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_TEMPLATE_VIEW_USER.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.VIEW_ADMINISTRATOR_RIGHTS), is(true));
securityContext.setAuthentication(new TestingAuthenticationToken("jez", "badger", new GrantedAuthority[] { new GrantedAuthorityImpl(GoAuthority.ROLE_USER.toString()) }));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.VIEW_ADMINISTRATOR_RIGHTS), is(nullValue()));
}
use of org.springframework.security.GrantedAuthorityImpl 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));
assertThat(userDetails.getUsername(), is("_go_agent_hostname"));
}
use of org.springframework.security.GrantedAuthorityImpl in project gocd by gocd.
the class UserHelperTest method shouldReturnFalseWhenCheckIsAgentIfGrantedAuthorityNotContainsAgentRole.
@Test
public void shouldReturnFalseWhenCheckIsAgentIfGrantedAuthorityNotContainsAgentRole() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(null, null, new GrantedAuthorityImpl[] { new GrantedAuthorityImpl("anything") });
assertThat(UserHelper.matchesRole(authentication, X509AuthoritiesPopulator.ROLE_AGENT), is(false));
}
use of org.springframework.security.GrantedAuthorityImpl 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));
}
Aggregations