Search in sources :

Example 6 with GrantedAuthorityImpl

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));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 7 with GrantedAuthorityImpl

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()));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 8 with GrantedAuthorityImpl

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"));
}
Also used : UserDetails(org.springframework.security.userdetails.UserDetails) GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) X509Certificate(java.security.cert.X509Certificate) X509CertificateGenerator(com.thoughtworks.go.security.X509CertificateGenerator) Test(org.junit.Test)

Example 9 with GrantedAuthorityImpl

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));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Example 10 with GrantedAuthorityImpl

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));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)12 Test (org.junit.Test)10 TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)9 GrantedAuthority (org.springframework.security.GrantedAuthority)7 User (org.springframework.security.userdetails.User)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 X509CertificateGenerator (com.thoughtworks.go.security.X509CertificateGenerator)1 Username (com.thoughtworks.go.server.domain.Username)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 X500Principal (javax.security.auth.x500.X500Principal)1 BadCredentialsException (org.springframework.security.BadCredentialsException)1 UserDetails (org.springframework.security.userdetails.UserDetails)1 UserAttribute (org.springframework.security.userdetails.memory.UserAttribute)1