use of org.springframework.security.access.SecurityConfig in project spring-boot by spring-projects.
the class AuthorizationAuditListenerTests method testAuthenticationCredentialsNotFound.
@Test
public void testAuthenticationCredentialsNotFound() {
AuditApplicationEvent event = handleAuthorizationEvent(new AuthenticationCredentialsNotFoundEvent(this, Collections.<ConfigAttribute>singletonList(new SecurityConfig("USER")), new AuthenticationCredentialsNotFoundException("Bad user")));
assertThat(event.getAuditEvent().getType()).isEqualTo(AuthenticationAuditListener.AUTHENTICATION_FAILURE);
}
use of org.springframework.security.access.SecurityConfig in project spring-boot by spring-projects.
the class AuthorizationAuditListenerTests method testAuthorizationFailure.
@Test
public void testAuthorizationFailure() {
AuditApplicationEvent event = handleAuthorizationEvent(new AuthorizationFailureEvent(this, Collections.<ConfigAttribute>singletonList(new SecurityConfig("USER")), new UsernamePasswordAuthenticationToken("user", "password"), new AccessDeniedException("Bad user")));
assertThat(event.getAuditEvent().getType()).isEqualTo(AuthorizationAuditListener.AUTHORIZATION_FAILURE);
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class SecuredAnnotationMetadataExtractor method extractAttributes.
public Collection<ConfigAttribute> extractAttributes(Secured secured) {
String[] attributeTokens = secured.value();
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(attributeTokens.length);
for (String token : attributeTokens) {
attributes.add(new SecurityConfig(token));
}
return attributes;
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class SecurityConfigTests method testToString.
@Test
public void testToString() {
SecurityConfig config = new SecurityConfig("TEST");
assertThat(config.toString()).isEqualTo("TEST");
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class SecuredAnnotationSecurityMetadataSourceTests method methodLevelAttributesAreFound.
@Test
public void methodLevelAttributesAreFound() {
Method method = null;
try {
method = BusinessService.class.getMethod("someUserAndAdminMethod", new Class[] {});
} catch (NoSuchMethodException unexpected) {
fail("Should be a method called 'someUserAndAdminMethod' on class!");
}
Collection<ConfigAttribute> attrs = this.mds.findAttributes(method, BusinessService.class);
assertThat(attrs).isNotNull();
// expect 2 attributes
assertThat(attrs).hasSize(2);
boolean user = false;
boolean admin = false;
// should have 2 SecurityConfigs
for (ConfigAttribute sc : attrs) {
assertThat(sc instanceof SecurityConfig).isTrue();
if (sc.getAttribute().equals("ROLE_USER")) {
user = true;
} else if (sc.getAttribute().equals("ROLE_ADMIN")) {
admin = true;
}
}
// expect to have ROLE_USER and ROLE_ADMIN
assertThat(user && admin).isTrue();
}
Aggregations