use of org.springframework.security.providers.TestingAuthenticationToken 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.providers.TestingAuthenticationToken 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.providers.TestingAuthenticationToken in project gocd by gocd.
the class UserHelperTest method shouldGetFullNameFromLdapUserDetails.
@Test
public void shouldGetFullNameFromLdapUserDetails() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(new LdapUserDetailsImpl() {
public String getUsername() {
return "test1";
}
public String getDn() {
return "cn=Test User, ou=Beijing, ou=Employees, ou=Enterprise, ou=Principal";
}
}, null, null);
assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("Test User"));
}
use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.
the class GoVelocityViewTest method shouldRetriveLdapCompleteNameFromSessionWhenAuthenticated.
@Test
public void shouldRetriveLdapCompleteNameFromSessionWhenAuthenticated() throws Exception {
securityContext.setAuthentication(new TestingAuthenticationToken(new LdapUserDetailsImpl() {
public String getUsername() {
return "test1";
}
public String getDn() {
return "cn=Test User, ou=Beijing, ou=Employees, ou=Enterprise, ou=Principal";
}
}, null, null));
request.getSession().setAttribute(SPRING_SECURITY_CONTEXT_KEY, securityContext);
view.exposeHelpers(velocityContext, request);
assertThat(velocityContext.get(GoVelocityView.PRINCIPAL), is("Test User"));
}
use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.
the class ReAuthenticationFilterTest method setupAuthentication.
private Authentication setupAuthentication() {
GrantedAuthority[] authorities = {};
Authentication authentication = new TestingAuthenticationToken(new User("user", "password", true, true, true, true, authorities), null, authorities);
SecurityContextHolder.getContext().setAuthentication(authentication);
authentication.setAuthenticated(true);
return authentication;
}
Aggregations