Template project demonstrating Dropwizard with OpenID authentication against a few providers (Google, Yahoo etc) and User/Authority annotation support.
Java
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/main
.gitignore
MIT-LICENSE
README.md
openid-demo.yml
pom.xml

README.md

OpenId Demo

This project demonstrates the following

  • Dropwizard - Serves HTML
  • OpenId - Provides integration with OpenId providers (Google, Facebook etc) see this blog post
  • Authorization - Security annotation supporting different levels of access
  • Session token cookie - Demonstrates stateless operation (but uses an in-memory cache so not horizontally scalable)
  • Markdown - see this blog post

Bug fixes

1.1.0

  • Fixed major bug with DiscoveryInformation getting lost between requests.
  • Added some Markdown demo code.
  • Designed for Dropwizard 0.6.2.

1.0.0

  • Initial release.
  • Designed for Dropwizard 0.6.1.

Getting started

From an IDE, just run the OpenIDDemoService.main() with a runtime configuration that passes application parameters of server openid-demo.yml.

From the console, just build with Maven and run it up:

mvn clean install
java -jar target/dropwizard-openid-1.1.0.jar server openid-demo.yml

Proxy settings

If you are behind a firewall you will need to set the proxy. This is configured in PublicOpenIDResource.

Authorization

Here is an example of the authorization annotation as used in PrivateInfoResource.

/**
 * @return The private home view if authenticated
 */
@GET
@Path("/home")
@Timed
@CacheControl(noCache = true)
public PublicFreemarkerView viewHome(
@RestrictedTo(Authority.ROLE_PUBLIC)
User publicUser) {

  BaseModel model = newBaseModel();
  return new PublicFreemarkerView<BaseModel>("private/home.ftl", model);

}

Adding yourself as an "admin"

The code supports different levels of authority (PUBLIC and ADMIN). To add yourself as an admin, simply edit the following code in PublicOpenIDResource to be the email address you use in your selected OpenID provider:

// Promote to admin if they have a specific email address
// (not a good way, but this is only a demo)
if ("nobody@example.org".equals(user.getEmailAddress())) {
  authorities.add(Authority.ROLE_ADMIN);
  log.info("Granted admin rights");
}

Where does the ASCII art come from?

The ASCII art for the startup banner was created using the online tool available at Webestools with a font of Tiza