alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Play Framework/Scala example source code file (OpenID.java)

This example Play Framework source code file (OpenID.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Play Framework (and Scala) source code examples by using tags.

All credit for the original source code belongs to Play Framework; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Play Framework tags/keywords

concurrent, core, hashmap, lib, library, map, openid, override, play, play framework, request, string, userinfo

The OpenID.java Play Framework example source code

/*
 * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
 */
package play.libs.openid;

import java.util.Map;
import java.util.HashMap;

import play.libs.Scala;
import scala.runtime.AbstractFunction1;
import scala.collection.JavaConversions;

import play.api.libs.concurrent.Promise;

import play.libs.F;
import play.mvc.Http;
import play.mvc.Http.Request;

import play.core.Invoker;

/**
 * provides support for OpenID
 */
public class OpenID {

    /**
     * Retrieve the URL where the user should be redirected to start the OpenID authentication process
     */
    public static F.Promise<String> redirectURL(String openID, String callbackURL) {
        return redirectURL(openID, callbackURL, null, null, null);
    }

    /**
     * Retrieve the URL where the user should be redirected to start the OpenID authentication process
     */
    public static F.Promise<String> redirectURL(String openID, String callbackURL, Map<String, String> axRequired) {
        return redirectURL(openID, callbackURL, axRequired, null, null);
    }

    /**
     * Retrieve the URL where the user should be redirected to start the OpenID authentication process
     */
    public static F.Promise<String> redirectURL(String openID,
            String callbackURL,
            Map<String, String> axRequired,
            Map<String, String> axOptional) {
        return redirectURL(openID, callbackURL, axRequired, axOptional, null);
    }

    /**
     * Retrieve the URL where the user should be redirected to start the OpenID authentication process
     */
    public static F.Promise<String> redirectURL(String openID,
            String callbackURL,
            Map<String, String> axRequired,
            Map<String, String> axOptional,
            String realm) {
        if (axRequired == null) axRequired = new HashMap<String, String>();
        if (axOptional == null) axOptional = new HashMap<String, String>();
        return F.Promise.wrap(play.api.libs.openid.OpenID.redirectURL(openID,
                                                                      callbackURL,
                                                                      JavaConversions.mapAsScalaMap(axRequired).toSeq(),
                                                                      JavaConversions.mapAsScalaMap(axOptional).toSeq(),
                                                                      Scala.Option(realm)));
    }

    /**
     * Check the identity of the user from the current request, that should be the callback from the OpenID server
     */
    public static F.Promise<UserInfo> verifiedId() {
        Request request = Http.Context.current().request();
        scala.concurrent.Future<UserInfo> scalaPromise = play.api.libs.openid.OpenID.verifiedId(request.queryString()).map(
                new AbstractFunction1<play.api.libs.openid.UserInfo, UserInfo>() {
                    @Override
                    public UserInfo apply(play.api.libs.openid.UserInfo scalaUserInfo) {
                        return new UserInfo(scalaUserInfo.id(), JavaConversions.mapAsJavaMap(scalaUserInfo.attributes()));
                    }
                },Invoker.executionContext());
        return F.Promise.wrap(scalaPromise);
    }

    public static class UserInfo {
        public String id;
        public Map<String, String> attributes;
        public UserInfo(String id) {
            this.id = id;
            this.attributes = new HashMap<String, String>();
        }
        public UserInfo(String id, Map<String, String> attributes) {
            this.id = id;
            this.attributes = attributes;
        }
    }

}

Other Play Framework source code examples

Here is a short list of links related to this Play Framework OpenID.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.