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 DispatcherServlet to map a URL to a servlet
  2. Configure this servlet with a <context:component-scan> tag to find and initialize the Spring OAuth2 Server
  3. Implement the AuthorizationServerConfigurer and add the @EnableAuthorizationServer tag.

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
<servlet>
    <servlet-name>springwebservice</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>springwebservice</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Step 2: springwebservice-servlet.xml
<context:component-scan base-package="mypackage" />
Step 3: MyRestController.java
@RestController
public class MyRestController {

    @RequestMapping("/test")
    public String testRest() {
        return "Hello World!";
    }
}

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

WARN [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:

@EnableAuthorizationServer
public class OAuth2Config implements AuthorizationServerConfigurer {

    @Override
    public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
        System.out.println("configure1");
    }

    @Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        System.out.println("configure2");
    }

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        System.out.println("configure3");
    }

}

Answers


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.


Need Your Help

How to successfully set a value to a field in JS? tried on.focus but no luck

javascript jquery css field frontend

Hi I'm trying to get my input field to say 'Enter your e-mail address' and when you click on it, it goes away to let the user type it. I tried playing around with on:focus and other various tips on...

Make XmlPullParser ignore whitespace?

java android xml xml-parsing xmlpullparser

I am parsing Xml with an XmlPullParser. I just want to deal with the Xml tags and the text contained within them however, the XmlPullParser reads in the whitespace text (spaces and carriage returns)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.