use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.
the class SecurityMockWithAuthoritiesMvcResultMatchersTests method withAuthoritiesFailsIfNotAllRoles.
@Test(expected = AssertionError.class)
public void withAuthoritiesFailsIfNotAllRoles() throws Exception {
List<SimpleGrantedAuthority> grantedAuthorities = new ArrayList<SimpleGrantedAuthority>();
grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
mockMvc.perform(formLogin()).andExpect(authenticated().withAuthorities(grantedAuthorities));
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security-oauth by spring-projects.
the class TokenEndpointTests method testGetAccessTokenWithNoClientId.
@Test
public void testGetAccessTokenWithNoClientId() throws HttpRequestMethodNotSupportedException {
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put(OAuth2Utils.GRANT_TYPE, "authorization_code");
OAuth2AccessToken expectedToken = new DefaultOAuth2AccessToken("FOO");
when(tokenGranter.grant(Mockito.eq("authorization_code"), Mockito.any(TokenRequest.class))).thenReturn(expectedToken);
@SuppressWarnings("unchecked") Map<String, String> anyMap = Mockito.any(Map.class);
when(authorizationRequestFactory.createTokenRequest(anyMap, Mockito.any(ClientDetails.class))).thenReturn(createFromParameters(parameters));
clientAuthentication = new UsernamePasswordAuthenticationToken(null, null, Collections.singleton(new SimpleGrantedAuthority("ROLE_CLIENT")));
ResponseEntity<OAuth2AccessToken> response = endpoint.postAccessToken(clientAuthentication, parameters);
assertNotNull(response);
assertEquals(HttpStatus.OK, response.getStatusCode());
OAuth2AccessToken body = response.getBody();
assertEquals(body, expectedToken);
assertTrue("Wrong body: " + body, body.getTokenType() != null);
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security-oauth by spring-projects.
the class Role method translate.
private Collection<? extends GrantedAuthority> translate(List<Role> roles) {
List<GrantedAuthority> authorities = new ArrayList<>();
for (Role role : roles) {
String name = role.getName().toUpperCase();
if (!name.startsWith("ROLE_")) {
name = "ROLE_" + name;
}
authorities.add(new SimpleGrantedAuthority(name));
}
return authorities;
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.
the class AclAuthorizationStrategyImplTests method setup.
@Before
public void setup() {
authority = new SimpleGrantedAuthority("ROLE_AUTH");
TestingAuthenticationToken authentication = new TestingAuthenticationToken("foo", "bar", Arrays.asList(authority));
authentication.setAuthenticated(true);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
use of org.springframework.security.core.authority.SimpleGrantedAuthority in project spring-security by spring-projects.
the class AclImplTests method deleteAceFailsForNonExistentElement.
@Test
public void deleteAceFailsForNonExistentElement() throws Exception {
AclAuthorizationStrategyImpl strategy = new AclAuthorizationStrategyImpl(new SimpleGrantedAuthority("ROLE_OWNERSHIP"), new SimpleGrantedAuthority("ROLE_AUDITING"), new SimpleGrantedAuthority("ROLE_GENERAL"));
MutableAcl acl = new AclImpl(objectIdentity, (1), strategy, pgs, null, null, true, new PrincipalSid("joe"));
try {
acl.deleteAce(99);
fail("It should have thrown NotFoundException");
} catch (NotFoundException expected) {
}
}
Aggregations