use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class GoAuthenticationProviderFactoryTest method shouldCreateLicenseEnforcementProviderWithUserServicePassedIn.
@Test
public void shouldCreateLicenseEnforcementProviderWithUserServicePassedIn() throws Exception {
GoAuthenticationProvider licenseEnforcementProvider = (GoAuthenticationProvider) factory.getObject();
AuthenticationProvider underlyingProvider = mock(AuthenticationProvider.class);
licenseEnforcementProvider.setProvider(underlyingProvider);
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("foo", "bar");
UsernamePasswordAuthenticationToken resultantAuthorization = new UsernamePasswordAuthenticationToken(new org.springframework.security.userdetails.User("foo-user", "pass", true, true, true, true, new GrantedAuthority[] { GoAuthority.ROLE_USER.asAuthority() }), "bar");
when(underlyingProvider.authenticate(auth)).thenReturn(resultantAuthorization);
licenseEnforcementProvider.authenticate(auth);
verify(userService).addUserIfDoesNotExist(UserHelper.getUser(resultantAuthorization));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class OauthAuthenticationProviderTest method shouldReturnOAUTH_USERAsTheGrantedAuthority.
@Test
public void shouldReturnOAUTH_USERAsTheGrantedAuthority() {
when(dataSource.findOauthTokenByAccessToken("token-string")).thenReturn(oauthTokenDto("user-id"));
GrantedAuthority[] grantedAuthorities = { GoAuthority.ROLE_OAUTH_USER.asAuthority() };
OauthAuthenticationToken authentication = provider.authenticate(new OauthAuthenticationToken("token-string"));
assertThat(authentication.isAuthenticated(), is(true));
UserDetails userDetails = authentication.getPrincipal();
assertThat(userDetails.getUsername(), is("user-id"));
assertThat(userDetails.getAuthorities(), is(grantedAuthorities));
assertThat(authentication.getAuthorities(), is(grantedAuthorities));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class AuthorityGranterTest method shouldGrantTemplateViewUserRoleToTemplateViewUsers.
@Test
public void shouldGrantTemplateViewUserRoleToTemplateViewUsers() {
String templateViewUser = "templateViewUser";
when(securityService.isAuthorizedToViewAndEditTemplates(new Username(new CaseInsensitiveString(templateViewUser)))).thenReturn(false);
when(securityService.isAuthorizedToViewTemplates(new Username(templateViewUser))).thenReturn(true);
GrantedAuthority[] authorities = authorityGranter.authorities(templateViewUser);
assertThat(authorities, hasItemInArray(GoAuthority.ROLE_TEMPLATE_VIEW_USER.asAuthority()));
assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_TEMPLATE_SUPERVISOR.asAuthority())));
assertThat(authorities, not(hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority())));
assertThat(authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class AuthorityGranterTest method shouldGrantRoleUserToUsersWhoAreNotSpecial.
@Test
public void shouldGrantRoleUserToUsersWhoAreNotSpecial() {
when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(false);
when(securityService.isUserGroupAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(false);
GrantedAuthority[] authorities = authorityGranter.authorities("admin");
assertThat("Should not have " + GoAuthority.ROLE_SUPERVISOR + " authority", authorities, not(hasItemInArray(GoAuthority.ROLE_SUPERVISOR.asAuthority())));
assertThat("Should not have " + GoAuthority.ROLE_GROUP_SUPERVISOR + " authority", authorities, not(hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority())));
assertThat("Should have " + GoAuthority.ROLE_USER + " authority", authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
use of org.springframework.security.GrantedAuthority in project gocd by gocd.
the class AuthorityGranterTest method shouldGrantSupervisorRoleToUsersWhoAreAdminsAndGroupAdmins.
@Test
public void shouldGrantSupervisorRoleToUsersWhoAreAdminsAndGroupAdmins() {
when(securityService.isUserAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(true);
when(securityService.isUserGroupAdmin(new Username(new CaseInsensitiveString("admin")))).thenReturn(true);
GrantedAuthority[] authorities = authorityGranter.authorities("admin");
assertThat("Should have " + GoAuthority.ROLE_SUPERVISOR + " authority", authorities, hasItemInArray(GoAuthority.ROLE_SUPERVISOR.asAuthority()));
assertThat("Should have " + GoAuthority.ROLE_GROUP_SUPERVISOR + " authority", authorities, hasItemInArray(GoAuthority.ROLE_GROUP_SUPERVISOR.asAuthority()));
assertThat("Should have " + GoAuthority.ROLE_USER + " authority", authorities, hasItemInArray(GoAuthority.ROLE_USER.asAuthority()));
}
Aggregations