Skip to content

ClassNotFoundException when management role is set without Spring Security #3888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
snicoll opened this issue Sep 3, 2015 · 10 comments
Closed
Assignees
Labels
type: blocker An issue that is blocking us from releasing type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Sep 3, 2015

To reproduce, create a vanilla app with the actuator (no Spring Security). It works fine but if you specify management.security.role you get this

Caused by: java.lang.NoClassDefFoundError: org/springframework/security/config/http/SessionCreationPolicy
    at org.springframework.boot.actuate.autoconfigure.ManagementServerProperties$Security.<init>(ManagementServerProperties.java:158)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at java.lang.Class.newInstance(Class.java:433)
    at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:78)
    at org.springframework.beans.AbstractNestablePropertyAccessor.newValue(AbstractNestablePropertyAccessor.java:914)
    at org.springframework.beans.AbstractNestablePropertyAccessor.createDefaultPropertyValue(AbstractNestablePropertyAccessor.java:887)
@snicoll
Copy link
Member Author

snicoll commented Sep 3, 2015

okay so the trick is that management.security is null unless binding forces it to be created. If we set management.security.role then the security instance is created by the binder (and that obviously lead to the exception).

I can see the security object being top-level + a condition to enable it which means we'll have to move all the security aspect of the actuator to a separate auto-config element.

@dsyer
Copy link
Member

dsyer commented Oct 1, 2015

A new bean ManagementSecurityProperties is probably the best solution, but ManagementServerProperties has ignoreUnknownFields = true so we would have to break that to fix this problem, unless we find a way to declare exclusions for ignoreUnknownFields.

@snicoll
Copy link
Member Author

snicoll commented Oct 1, 2015

That's #3445

@dsyer
Copy link
Member

dsyer commented Oct 1, 2015

Indeed. But that one is not marked for 1.3, and this one is (and is marked as a bug). I would argue we need to postpone this and downgrade it to an enhancement.l donut can be done properly in 1.4/2.0.

@snicoll
Copy link
Member Author

snicoll commented Oct 1, 2015

Agreed

@snicoll snicoll modified the milestones: 1.4.0, 1.3.0.RC1 Oct 2, 2015
mikegehard added a commit to mikegehard/user-management-evolution-kotlin that referenced this issue Nov 21, 2015
Leaving this is will cause issues by trying to require spring security.
See: spring-projects/spring-boot#3888
@philwebb philwebb modified the milestones: 1.4.0.M2, 1.4.0 Jan 7, 2016
@snicoll snicoll modified the milestones: 1.3.2, 1.4.0.M2 Jan 11, 2016
@snicoll snicoll added type: enhancement A general enhancement and removed type: bug A general bug labels Jan 12, 2016
@philwebb philwebb modified the milestones: 1.4.0.M3, 1.4.0.M2 Apr 12, 2016
@philwebb philwebb modified the milestones: 1.4.0.RC1, 1.4.0.M3 May 17, 2016
@snicoll snicoll removed this from the 1.4.0.RC1 milestone Jun 16, 2016
@philwebb philwebb added type: bug A general bug type: blocker An issue that is blocking us from releasing labels Nov 2, 2016
@philwebb philwebb removed the type: enhancement A general enhancement label Nov 2, 2016
@philwebb philwebb added this to the 1.4.2 milestone Nov 2, 2016
@snicoll snicoll self-assigned this Nov 3, 2016
@snicoll
Copy link
Member Author

snicoll commented Nov 3, 2016

Unfortunately, the issue is outside of our control at this stage. The guard makes sure that the Security inner class isn't created but when the binder processes management.security, it first makes sure it has a default value for it before checking it can actually set the value. If that works fine, we end up in NotWritablePropertyException that's going to be ignored by the binder.

Essentially, our guard only works if we don't attempt to bind any element of the management.security namespace. I guess it would be nice to only compute the default value once we have determined that we can actually set it. Maybe @jhoeller has some insight about that?

@philwebb we can workaround the issue by having our own enum for SessionCreationPolicy and something that would translate it back to the actual enum Spring Security is expecting. Or we could have a raw String with value hints metadata. I don't see any other way at this point.

snicoll added a commit to snicoll/spring-boot that referenced this issue Nov 3, 2016
@philwebb philwebb self-assigned this Nov 3, 2016
@philwebb
Copy link
Member

philwebb commented Nov 3, 2016

@snicoll I've gone with the enum option. Ideally we wouldn't change this in 1.4 but a custom was hit by the issue.

@snicoll
Copy link
Member Author

snicoll commented Nov 4, 2016

Rather than a sample that acts as an integration test can we please use the test that I've started to craft? It reproduces the exact same thing. If you agree I can replace that.

@wilkinsona
Copy link
Member

Yes please, @snicoll

@snicoll
Copy link
Member Author

snicoll commented Nov 4, 2016

Reopen to remove the sample and merge the integration test instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: blocker An issue that is blocking us from releasing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants