Misch Misch - 1 year ago 163
Java Question

How to integrate Spring OAuth2 Server into Liferay

I'm trying to integrate a Spring OAuth2 Server into Liferay. Despite some problems, the basic way to do this seems to be clear:

  1. Use a
    to map a URL to a servlet

  2. Configure this servlet with a
    tag to find and initialize the Spring OAuth2 Server

  3. Implement the
    and add the

However, this doesn't seem to be enough, the OAuth server is never initialized and calls to the URL where the server should be listening are simply answered with an error 404.

To locate the Problem, I (almost) successfully added a little REST Service. Here is the code I used:

Step 1: web.xml



Step 2: springwebservice-servlet.xml

<context:component-scan base-package="mypackage" />

Step 3: MyRestController.java

public class MyRestController {

public String testRest() {
return "Hello World!";

Strangely, this doesn't work. It seems to be ignoring the
tag and just handling it as if it were a normal
, thus searching a view called "Hello World!" instead of just returing that text:

[PageNotFound:1114] No mapping found for HTTP request with URI
[/TestLiferaySpring-1.0-SNAPSHOT/rest/Hello World!]
in DispatcherServlet with name 'springwebservice'

But independent of that, it does show that steps 1 and 2 shouldn't be the problem. However, my OAuth2 server configuration is never called at all! Why could this be the case, what am I missing?

Here is the code of the OAuth2 server configuration:

public class OAuth2Config implements AuthorizationServerConfigurer {

public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {

public void configure(ClientDetailsServiceConfigurer clients) throws Exception {

public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {


Answer Source

What a stupid mistake (and a stupid question) I merely forgot the @Configuration annotation above the @EnableAuthorizationServer annotation.

Now at least the Authorization server is recognized:

Mapped "{[/oauth/authorize],methods=[POST], ... onto ...

I could delete this question, but maybe it will help somebody else who wants to achieve something similar (I at least wasn't able to find much documentation for either Liferay or Spring Security). Just be aware that I still get an exception about Autowiring, so this isn't the final solution to get everything to work.