I have an app running on Google app engine. I want to change the sign-in from using google, to using open id, in Java.
So, I tried following this guide:
http://code.google.com/appengine/articles/openid.html
I changed the authentication to federated login on the application settings dashboard.
I put this in the web.xml:
<servlet> <servlet-name>LoginRequiredServlet</servlet-name> <servlet-class>XXXXXX.server.LoginRequiredServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginRequiredServlet</servlet-name> <url-pattern>/_ah/login_required</url-pattern> </servlet-mapping>
I created a class called LoginRequiredServlet, with the code that is on the above link. I renamed their class OpenIdDemoServlet to LoginRequiredServlet.
开发者_StackOverflow社区
I redeployed. Upon going to my landing page, it only takes me a google login page. What exactly do I have to do to so it can show a few links to other OpenID providers?
What am I missing?
Thanks.
Try this, I'm quoting http://code.google.com/appengine/articles/openid.html except that I have changed the class name from OpenIdDemoServlet to LoginRequiredServlet.
@SuppressWarnings("serial") public class LoginRequiredServlet extends HttpServlet {
private static final Map<String, String> openIdProviders;
static {
openIdProviders = new HashMap<String, String>();
openIdProviders.put("Google", "google.com/accounts/o8/id");
openIdProviders.put("Yahoo", "yahoo.com");
openIdProviders.put("MySpace", "myspace.com");
openIdProviders.put("AOL", "aol.com");
openIdProviders.put("MyOpenId.com", "myopenid.com");
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); // or req.getUserPrincipal()
Set<String> attributes = new HashSet();
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
if (user != null) {
out.println("Hello <i>" + user.getNickname() + "</i>!");
out.println("[<a href=\""
+ userService.createLogoutURL(req.getRequestURI())
+ "\">sign out</a>]");
} else {
out.println("Hello world! Sign in at: ");
for (String providerName : openIdProviders.keySet()) {
String providerUrl = openIdProviders.get(providerName);
String loginUrl = userService.createLoginURL(req
.getRequestURI(), null, providerUrl, attributes);
out.println("[<a href=\"" + loginUrl + "\">" + providerName + "</a>] ");
}
}
}
}
Also update your web.xml so as to force logging in. the code below will force logging for all urls on the website.
精彩评论