2010-08-04 60 views
1

我最近在Google App Engine上部署了Roo/Gwt項目。在已部署的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」文件?

非常感謝你,

問候

回答

1

這是進步,爲GWT 2.1/1.1.0袋鼠來實現。看到這個更多細節https://jira.springsource.org/browse/ROO-1003

如果您不能等待,檢查彈簧安全在谷歌App Engine的文章,在http://blog.springsource.com/2010/08/02/spring-security-in-google-app-engine/ 這種做法不被袋鼠支持,但(所以一旦你改變生成的代碼,這將是更難但仍有可能繼續使用Roo)

+0

那麼,沒有辦法來保護部署的Roo/Gwt應用程序? – Zakaria 2010-08-05 19:57:15