我最近在Google App Engine上部署了一个Roo / Gwt项目。
我花了几个小时但找不到一个教程,一步一步地说明,我们如何添加n身份验证系统(使用联合登录Api)。
我发现this very good article提供了一些有用的代码:
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
@SuppressWarnings("serial")
public class OpenIdDemoServlet 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>] ");
}
}
}
}
如何设置此验证模块?我应该把这段代码放在哪里,因为没有“main.java”文件?
非常感谢,
此致
答案 0 :(得分:1)
这正在为GWT 2.1 / Roo 1.1.0实施。有关详细信息https://jira.springsource.org/browse/ROO-1003
,请参阅此处如果您迫不及待,请查看Google App Engine中的Spring Security文章http://blog.springsource.com/2010/08/02/spring-security-in-google-app-engine/ Roo不支持这种方法(所以一旦你改变生成的代码,继续使用Roo会更难,但仍然可能)