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));
}
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));
}
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()));
}
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")));
}
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"));
}
Aggregations