Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/spring-security-data.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
}

apply plugin: 'io.spring.convention.spring-module'
apply plugin: 'compile-warnings-error'

dependencies {
management platform(project(":spring-security-dependencies"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ public SecurityExpressionRoot<Object> getRootObject() {
};
root.setAuthorizationManagerFactory(this.authorizationManagerFactory);
root.setPermissionEvaluator(this.permissionEvaluator);
if (!DEFAULT_ROLE_PREFIX.equals(this.defaultRolePrefix)) {
// Ensure SecurityExpressionRoot can strip the custom role prefix
root.setDefaultRolePrefix(this.defaultRolePrefix);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. We must preserve this functionality until the deprecation has been removed. Can you please restore that?

}
return root;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
import org.springframework.security.authentication.AuthenticationTrustResolver;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.authorization.DefaultAuthorizationManagerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
import org.springframework.security.core.context.SecurityContextImpl;
Expand Down Expand Up @@ -90,6 +91,7 @@ public void getRootObjectExplicitAuthentication() {
}

@Test
@SuppressWarnings("deprecation")
public void setTrustResolverWhenNullThenIllegalArgumentException() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_EXPLICIT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
Expand All @@ -98,6 +100,7 @@ public void setTrustResolverWhenNullThenIllegalArgumentException() {
}

@Test
@SuppressWarnings("deprecation")
public void setTrustResolverWhenNotNullThenVerifyRootObject() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_EXPLICIT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
Expand All @@ -109,6 +112,7 @@ public void setTrustResolverWhenNotNullThenVerifyRootObject() {
}

@Test
@SuppressWarnings("deprecation")
public void setRoleHierarchyWhenNullThenIllegalArgumentException() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_EXPLICIT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
Expand All @@ -117,6 +121,7 @@ public void setRoleHierarchyWhenNullThenIllegalArgumentException() {
}

@Test
@SuppressWarnings("deprecation")
public void setRoleHierarchyWhenNotNullThenVerifyRootObject() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_PARENT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
Expand All @@ -143,6 +148,7 @@ public void setPermissionEvaluatorWhenNotNullThenVerifyRootObject() {
}

@Test
@SuppressWarnings("deprecation")
public void setDefaultRolePrefixWhenCustomThenVerifyRootObject() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "CUSTOM_EXPLICIT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
Expand All @@ -151,6 +157,41 @@ public void setDefaultRolePrefixWhenCustomThenVerifyRootObject() {
assertThat(getRoot().hasRole("EXPLICIT")).isTrue();
}

@Test
public void setAuthorizationManagerFactoryWithTrustResolverThenVerifyRootObject() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_EXPLICIT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
AuthenticationTrustResolver trustResolver = mock(AuthenticationTrustResolver.class);
given(trustResolver.isAuthenticated(explicit)).willReturn(true);
DefaultAuthorizationManagerFactory<Object> factory = new DefaultAuthorizationManagerFactory<>();
factory.setTrustResolver(trustResolver);
this.securityExtension.setAuthorizationManagerFactory(factory);
assertThat(getRoot().isAuthenticated()).isTrue();
verify(trustResolver).isAuthenticated(explicit);
}

@Test
public void setAuthorizationManagerFactoryWithRoleHierarchyThenVerifyRootObject() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_PARENT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
RoleHierarchy roleHierarchy = RoleHierarchyImpl.fromHierarchy("ROLE_PARENT > ROLE_EXPLICIT");
DefaultAuthorizationManagerFactory<Object> factory = new DefaultAuthorizationManagerFactory<>();
factory.setRoleHierarchy(roleHierarchy);
this.securityExtension.setAuthorizationManagerFactory(factory);
assertThat(getRoot().hasRole("EXPLICIT")).isTrue();
}

@Test
public void setAuthorizationManagerFactoryWithRolePrefixThenVerifyRootObject() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "CUSTOM_EXPLICIT");
this.securityExtension = new SecurityEvaluationContextExtension(explicit);
String customRolePrefix = "CUSTOM_";
DefaultAuthorizationManagerFactory<Object> factory = new DefaultAuthorizationManagerFactory<>();
factory.setRolePrefix(customRolePrefix);
this.securityExtension.setAuthorizationManagerFactory(factory);
assertThat(getRoot().hasRole("EXPLICIT")).isTrue();
}

@Test
public void getRootObjectWhenAdditionalFieldsNotSetThenVerifyDefaults() {
TestingAuthenticationToken explicit = new TestingAuthenticationToken("explicit", "password", "ROLE_EXPLICIT");
Expand Down