use of org.springframework.security.providers.TestingAuthenticationToken in project gocd by gocd.
the class UserHelperTest method shouldGetNameFromLdapUserDetailsIfCannotGetFullName.
@Test
public void shouldGetNameFromLdapUserDetailsIfCannotGetFullName() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(new LdapUserDetailsImpl() {
public String getUsername() {
return "test1";
}
public String getDn() {
return "n=Test User, ou=Beijing, ou=Employees, ou=Enterprise, ou=Principal";
}
}, null, null);
assertThat(UserHelper.getUserName(authentication).getDisplayName(), is("test1"));
}
use of org.springframework.security.providers.TestingAuthenticationToken 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.providers.TestingAuthenticationToken in project gocd by gocd.
the class UserHelperTest method shouldReturnTrueWhenCheckIsAgentIfGrantedAuthorityContainsAgentRole.
@Test
public void shouldReturnTrueWhenCheckIsAgentIfGrantedAuthorityContainsAgentRole() {
TestingAuthenticationToken authentication = new TestingAuthenticationToken(null, null, new GrantedAuthorityImpl[] { new GrantedAuthorityImpl("ROLE_AGENT") });
assertThat(UserHelper.matchesRole(authentication, X509AuthoritiesPopulator.ROLE_AGENT), is(true));
}
use of org.springframework.security.providers.TestingAuthenticationToken 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"));
}
use of org.springframework.security.providers.TestingAuthenticationToken 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));
}
Aggregations