Skip to content
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

java.lang.NullPointerException when using ResourceProcessor<RepositoryLinksResource> and SpringSecurity [DATAREST-702] #1073

Open
spring-projects-issues opened this issue Nov 11, 2015 · 0 comments
Assignees
Labels
type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Nov 11, 2015

Manuel Sousa opened DATAREST-702 and commented

I have a custom controller which implements ResourceProcessor<RepositoryLinksResource> in order to populate the root response as in: http://stackoverflow.com/questions/25783487/custom-response-for-root-request-int-the-spring-rest-hateoas-with-both-repositor/26118405#26118405

If one of the controller methods is annotated with springsecurity Pre/PostAuthorize I get a null pointer exception when booting the application:
...
Caused by: java.lang.NullPointerException
at org.springframework.data.rest.webmvc.ResourceProcessorHandlerMethodReturnValueHandler.<init>(ResourceProcessorHandlerMethodReturnValueHandler.java:89)
at org.springframework.data.rest.webmvc.ResourceProcessorInvokingHandlerAdapter.afterPropertiesSet(ResourceProcessorInvokingHandlerAdapter.java:75)
at org.springframework.data.rest.webmvc.RepositoryRestHandlerAdapter.afterPropertiesSet(RepositoryRestHandlerAdapter.java:60)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
...

I think the issue lies in the processor being Proxy$... instead of the ControllerClass.
Moving the method to another class, for instance the DAO fixes the issue as an workaround.

Not sure if this is a bug, a design choice or if i'm missing something.

@RestController
@ExposesResourceFor(Device.class)
@RequestMapping(value = "/devices", produces = "application/hal+json")
public class DeviceController implements ResourceProcessor<RepositoryLinksResource> {
...
    @RequestMapping(path = "/{id}")
    @PreAuthorize("isAuthenticated()")
    public Resource<Device> getDevice(@PathVariable("id") String id){
    ...
    }

    public RepositoryLinksResource process(RepositoryLinksResource resource) {
        resource.add(ControllerLinkBuilder.linkTo(DeviceController.class).withRel("devices"));
        return resource;
    }
}

Removing the @PreAuthorize or moving it to the dao is enough for it to work as expected


Affects: 2.4 GA (Gosling)

Referenced from: commits e08dff8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants