Search in sources :

Example 1 with GrantedAuthority

use of org.springframework.security.GrantedAuthority 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 2 with GrantedAuthority

use of org.springframework.security.GrantedAuthority in project gocd by gocd.

the class GoVelocityViewTest method shouldSetTemplateViewUserRightsForTemplateViewUser.

@Test
public void shouldSetTemplateViewUserRightsForTemplateViewUser() throws Exception {
    securityContext.setAuthentication(new TestingAuthenticationToken("templateView", "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.TEMPLATE_VIEW_USER), 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 3 with GrantedAuthority

use of org.springframework.security.GrantedAuthority 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 4 with GrantedAuthority

use of org.springframework.security.GrantedAuthority in project gocd by gocd.

the class UserHelperTest method shouldGetDisplayNameForAPasswordFileUser.

@Test
public void shouldGetDisplayNameForAPasswordFileUser() {
    GrantedAuthority[] authorities = { new GrantedAuthorityImpl("anything") };
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new GoUserPrinciple("user", "Full Name", "password", true, true, true, true, authorities), null, authorities);
    assertThat(UserHelper.getUserName(authentication), is(new Username(new CaseInsensitiveString("user"), "Full Name")));
}
Also used : GrantedAuthorityImpl(org.springframework.security.GrantedAuthorityImpl) Username(com.thoughtworks.go.server.domain.Username) GrantedAuthority(org.springframework.security.GrantedAuthority) GoUserPrinciple(com.thoughtworks.go.server.security.userdetail.GoUserPrinciple) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 5 with GrantedAuthority

use of org.springframework.security.GrantedAuthority in project gocd by gocd.

the class UserHelperTest method shouldGetNameFromUserDetails.

@Test
public void shouldGetNameFromUserDetails() {
    TestingAuthenticationToken authentication = new TestingAuthenticationToken(new User("user", "pass", true, false, true, true, new GrantedAuthority[0]), null, null);
    assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("user"));
}
Also used : User(org.springframework.security.userdetails.User) GrantedAuthority(org.springframework.security.GrantedAuthority) TestingAuthenticationToken(org.springframework.security.providers.TestingAuthenticationToken) Test(org.junit.Test)

Aggregations

GrantedAuthority (org.springframework.security.GrantedAuthority)20 Test (org.junit.Test)17 TestingAuthenticationToken (org.springframework.security.providers.TestingAuthenticationToken)9 GrantedAuthorityImpl (org.springframework.security.GrantedAuthorityImpl)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 Username (com.thoughtworks.go.server.domain.Username)6 User (org.springframework.security.userdetails.User)4 Authentication (org.springframework.security.Authentication)3 UsernamePasswordAuthenticationToken (org.springframework.security.providers.UsernamePasswordAuthenticationToken)2 UserDetails (org.springframework.security.userdetails.UserDetails)2 X509CertificateGenerator (com.thoughtworks.go.security.X509CertificateGenerator)1 OauthAuthenticationToken (com.thoughtworks.go.server.security.OauthAuthenticationToken)1 GoUserPrinciple (com.thoughtworks.go.server.security.userdetail.GoUserPrinciple)1 X509Certificate (java.security.cert.X509Certificate)1 AuthenticationProvider (org.springframework.security.providers.AuthenticationProvider)1