• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

moto web application


Commit MetaInfo

Revision987341e41304019cf42a43f7f385ec12d73e1d26 (tree)
Time2014-02-07 16:08:40
Authorastoria-d <astoria-d@mail...>
Commiterastoria-d

Log Message

openid login complete

Change Summary

Incremental Difference

--- a/WEB-INF/classes/motoSample/LoginFilter.java
+++ b/WEB-INF/classes/motoSample/LoginFilter.java
@@ -47,9 +47,8 @@ public class LoginFilter implements Filter {
4747 String contextPath = ((HttpServletRequest)request).getContextPath();
4848 ((HttpServletResponse)response).sendRedirect(contextPath + "/login.jsf");
4949 }
50-
50+
5151 chain.doFilter(request, response);
52-
5352 }
5453
5554 public void init(FilterConfig config) throws ServletException {
--- a/WEB-INF/classes/motoSample/OpenIdReturn.java
+++ b/WEB-INF/classes/motoSample/OpenIdReturn.java
@@ -16,10 +16,13 @@ import org.openid4java.discovery.Identifier;
1616 import org.openid4java.consumer.VerificationResult;
1717 import org.openid4java.message.ParameterList;
1818
19-
2019 public class OpenIdReturn extends HttpServlet {
2120 private static Logger log = Logger.getLogger(OpenIdReturn.class.getName());
2221
22+ public OpenIdReturn() {
23+ super();
24+ }
25+
2326 static Identifier returnCheck(DiscoveryInformation discoveryInformation, Map pageParameters, String returnToUrl) {
2427 ParameterList response = new ParameterList(pageParameters);
2528 try {
@@ -39,19 +42,36 @@ public class OpenIdReturn extends HttpServlet {
3942 HttpSession session = request.getSession();
4043 DiscoveryInformation di = (DiscoveryInformation) session.getAttribute("discoveryInformation");
4144 Identifier id = returnCheck(di, request.getParameterMap(), OpenIdBean.getReturnUrl());
45+ session.removeAttribute("discoveryInformation");
46+
4247 PrintWriter out = response.getWriter();
48+ UserBean ubean = (UserBean)session.getAttribute("userBean");
4349
4450 out.println("<HTML><HEAD><TITLE>open id login page</TITLE></HEAD>");
4551 out.println("<BODY>");
52+
4653 if (id == null) {
4754 out.println("<H3>open id verification failure...</H3>");
4855 }
4956 else {
50- out.println("Open ID successfull : <H3>" + id.getIdentifier() + "</H3>");
57+ String openid = id.getIdentifier();
58+ String nextUrl = ubean.doOpenIdLogin(openid, session);
59+ if (nextUrl == null) {
60+ out.println("Open ID : <H3>" + openid + "</H3> not found...");
61+ }
62+ else {
63+ out.println("open id login ok. log in user : <H3>" + ubean.getUname()+ "</H3>.");
64+ String contextPath = request.getContextPath();
65+ /*log.info("contextPath: " + contextPath);
66+ log.info("last char: " + contextPath.charAt(contextPath.length() - 1));
67+ if (contextPath.charAt(contextPath.length() - 1) != '/')
68+ contextPath += "/";
69+ */
70+ response.sendRedirect(contextPath + nextUrl);
71+ }
5172 }
5273 out.println("</BODY>");
53- out.println("</HTML>");
74+ out.println("</HTML>");
5475 }
5576
56-
5777 }
--- a/WEB-INF/classes/motoSample/UserBean.java
+++ b/WEB-INF/classes/motoSample/UserBean.java
@@ -92,6 +92,34 @@ public class UserBean implements Serializable {
9292 }
9393 }
9494
95+ private void initLogin(Connection conn, String user_name) {
96+ login = true;
97+ this.uname = user_name;
98+ initUserFlights(conn);
99+
100+ //add to the app login list.
101+ loginMemberBean.login(uid, true);
102+ //notify log in message
103+ for (SelectItem si : flights) {
104+ String chatRoom = si.getValue().toString();
105+
106+ PushMsg pm = PushMsg.newLoginPushMsg();
107+ PushMsg.LoginUser lu = pm.getLoginUser();
108+ lu.setUid(uid);
109+ lu.setLogin(true);
110+
111+ String br_url = "/comet/" + chatRoom;
112+ Broadcaster b = BroadcasterFactory.getDefault().lookup(br_url, true);
113+ ObjectMapper mapper = new ObjectMapper();
114+ try {
115+ String json = mapper.writeValueAsString(pm);
116+ b.broadcast(json);
117+ } catch (IOException e) {
118+ log.severe("json encode error.");
119+ }
120+ }
121+ }
122+
95123 public String doLogin() {
96124
97125 try {
@@ -111,36 +139,11 @@ public class UserBean implements Serializable {
111139 //log.info("name = " + rs.getString("user_name"));
112140
113141 if (pwd.equals(db_pwd)) {
114- login = true;
115- this.uname = rs.getString("user_name");
142+ initLogin(conn, rs.getString("user_name"));
143+
116144 statement.close();
117-
118- initUserFlights(conn);
119-
120145 conn.close();
121146
122- //add to the app login list.
123- loginMemberBean.login(uid, true);
124- //notify log in message
125- for (SelectItem si : flights) {
126- String chatRoom = si.getValue().toString();
127-
128- PushMsg pm = PushMsg.newLoginPushMsg();
129- PushMsg.LoginUser lu = pm.getLoginUser();
130- lu.setUid(uid);
131- lu.setLogin(true);
132-
133- String br_url = "/comet/" + chatRoom;
134- Broadcaster b = BroadcasterFactory.getDefault().lookup(br_url, true);
135- ObjectMapper mapper = new ObjectMapper();
136- try {
137- String json = mapper.writeValueAsString(pm);
138- b.broadcast(json);
139- } catch (IOException e) {
140- log.severe("json encode error.");
141- }
142- }
143-
144147 ///after login, redirect to the user specified url.
145148 HttpSession session = Resources.getSession();
146149 String request_url = (String) session.getAttribute("request_url");
@@ -166,6 +169,43 @@ public class UserBean implements Serializable {
166169 return "";
167170 }
168171
172+
173+ public String doOpenIdLogin (String openid, HttpSession session) {
174+
175+ try {
176+ Connection conn = Resources.getConnection();
177+
178+ String sqlString = "select user_id, user_name from tb_users where use_open_id=\'TRUE\' and user_open_id=\'" + openid +"\'";
179+
180+ Statement statement = conn.createStatement();
181+ statement.setQueryTimeout(30); // set timeout to 30 sec.
182+
183+ ResultSet rs = statement.executeQuery(sqlString);
184+ if(rs.next())
185+ {
186+ this.uid = rs.getString("user_id");
187+ initLogin(conn, rs.getString("user_name"));
188+ statement.close();
189+ conn.close();
190+
191+ ///after login, redirect to the user specified url.
192+ String request_url = (String) session.getAttribute("request_url");
193+ if (request_url == null)
194+ request_url = "/secured/chat.jsf";
195+ return request_url + "?faces-redirect=true";
196+ }
197+ else {
198+ log.info("openid " + openid + " not found...");
199+ }
200+ statement.close();
201+ conn.close();
202+ }
203+ catch (SQLException se) {
204+ log.severe("sql err!!!");
205+ }
206+ return null;
207+ }
208+
169209 public String doLogout() {
170210 //notify log in message
171211 for (SelectItem si : flights) {
--- a/login.xhtml
+++ b/login.xhtml
@@ -18,6 +18,15 @@ password : <h:inputSecret value="#{userBean.pwd}"/>
1818
1919 </h:form>
2020
21+<br />
22+<br />
23+<br />
24+<hr />
25+<br />
26+<br />
27+<br />
28+Open ID log in:
29+<br />
2130 <h:form>
2231 <h:commandLink action="#{openIdBean.yahooLogin}">
2332 <img src="http://i.yimg.jp/images/login/btn/btnXSYid.gif" width="241" height="28" alt="Yahoo! JAPAN IDでログイン" border="0" />