Spring Security has an OAuth sub-project with support for OAuth 1.0a and OAuth2 (both client and server). They have sample code on their GitHub repo:
- Main repo: https://github.com/spring-projects/spring-security-oauth
- Sample OAuth2 provider (called sparklr): https://github.com/spring-projects/spring-security-oauth/tree/master/samples/oauth2/sparklr
Apache Amber (http://oltu.apache.org/) is another project (now deprecated) that makes it fairly straightforward to build an OAuth2 provider. See:
- https://cwiki.apache.org/confluence/display/OLTU/OAuth+2.0+Authorization+Server for the Authorization server
- https://cwiki.apache.org/confluence/display/OLTU/OAuth+2.0+Resource+Server for the Resource server