use of org.springframework.security.Authentication in project gocd by gocd.
the class LdapAuthenticationTest method commonLdapUserShouldOnlyHaveAuthorityOfUserAndNotAdmin.
@Test
public void commonLdapUserShouldOnlyHaveAuthorityOfUserAndNotAdmin() throws Exception {
ldapServer.addUser(employeesOrgUnit, "foleys", "some-password", "Shilpa Foley", "foleys@somecompany.com");
configFileHelper.initializeConfigFile();
configFileHelper.addLdapSecurityWithAdmin(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, SEARCH_BASE, SEARCH_FILTER, "another_admin");
Authentication authentication = new UsernamePasswordAuthenticationToken("foleys", "some-password");
Authentication result = ldapAuthenticationProvider.authenticate(authentication);
assertThat(result.isAuthenticated(), is(true));
GrantedAuthority[] authorities = result.getAuthorities();
assertThat("foleys should have only user authority. Found: " + ArrayUtils.toString(authorities), authorities.length, is(1));
assertThat(authorities[0].getAuthority(), is("ROLE_USER"));
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class LdapAuthenticationTest method assertAuthenticationOfValidAdminUser.
private void assertAuthenticationOfValidAdminUser(String userName, String password) {
Authentication authentication = new UsernamePasswordAuthenticationToken(userName, password);
Authentication result = ldapAuthenticationProvider.authenticate(authentication);
assertThat(result.isAuthenticated(), is(true));
assertThat(userName + " should have " + ROLE_SUPERVISOR + " authority", result.getAuthorities(), // by default, every user is administrator
hasItemInArray(ROLE_SUPERVISOR.asAuthority()));
}
use of org.springframework.security.Authentication 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;
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class UserEnabledCheckFilterTest method shouldNotSetUserIdInSessionIfAlreadySet.
@Test
public void shouldNotSetUserIdInSessionIfAlreadySet() throws IOException, ServletException {
SecurityContextHelper.setCurrentUser("winner");
Long userId = 1L;
User user = getUser("winner", userId);
Authentication actual = SecurityContextHolder.getContext().getAuthentication();
when(session.getAttribute(USERID_ATTR)).thenReturn(userId);
when(userService.load(userId)).thenReturn(user);
filter.doFilterHttp(req, res, chain);
assertThat(SecurityContextHolder.getContext().getAuthentication(), is(actual));
verify(session, never()).setAttribute(USERID_ATTR, userId);
verify(chain).doFilter(req, res);
}
use of org.springframework.security.Authentication in project gocd by gocd.
the class GoAuthenticationProviderTest method shouldNotFailWhenUnderlyingProviderDoesNotAuthenticate.
@Test
public void shouldNotFailWhenUnderlyingProviderDoesNotAuthenticate() throws Exception {
when(underlyingProvider.authenticate(auth)).thenReturn(null);
Authentication authentication = enforcementProvider.authenticate(auth);
assertThat(authentication, is(nullValue()));
}
Aggregations