Rev 2069 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2069 | Rev 2072 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.es.exemplos.hibernate.web.login; |
1 | package pt.estgp.es.exemplos.hibernate.web.login; |
2 | 2 | ||
3 | import org.json.JSONException; |
3 | import org.json.JSONException; |
4 | import org.json.JSONObject; |
4 | import org.json.JSONObject; |
5 | import pt.estgp.es.exemplos.hibernate.HibernateUtils; |
5 | import pt.estgp.es.exemplos.hibernate.HibernateUtils; |
- | 6 | import pt.estgp.es.exemplos.hibernate.User; |
|
6 | import pt.estgp.es.exemplos.hibernate.UserSession; |
7 | import pt.estgp.es.exemplos.hibernate.UserSession; |
- | 8 | import pt.estgp.es.exemplos.hibernate.security.SecurityContextProvider; |
|
- | 9 | import pt.estgp.es.exemplos.hibernate.security.logic.NotAuthenticatedException; |
|
- | 10 | import pt.estgp.es.exemplos.hibernate.services.ServicoSessoes; |
|
7 | import pt.estgp.es.exemplos.hibernate.web.SecurityFilter; |
11 | import pt.estgp.es.exemplos.hibernate.web.SecurityFilter; |
8 | import pt.estgp.es.exemplos.hibernate.web.UserFilter; |
12 | import pt.estgp.es.exemplos.hibernate.web.UserFilter; |
9 | import pt.estgp.es.exemplos.hibernate.web.rest.AbstractRestServlet; |
13 | import pt.estgp.es.exemplos.hibernate.web.rest.AbstractRestServlet; |
10 | 14 | ||
11 | import javax.servlet.ServletException; |
15 | import javax.servlet.ServletException; |
12 | import javax.servlet.http.HttpServletRequest; |
16 | import javax.servlet.http.HttpServletRequest; |
13 | import javax.servlet.http.HttpServletResponse; |
17 | import javax.servlet.http.HttpServletResponse; |
14 | import java.io.IOException; |
18 | import java.io.IOException; |
- | 19 | import java.util.List; |
|
- | 20 | ||
- | 21 | import static org.hibernate.criterion.Restrictions.eq; |
|
15 | 22 | ||
16 | public class LoginRest extends AbstractRestServlet |
23 | public class LoginRest extends AbstractRestServlet |
17 | { |
24 | { |
18 | public JSONObject login(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
25 | public JSONObject login(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException, NotAuthenticatedException, 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException { |
19 | { |
- | |
20 | 1.5.0/docs/api/java/lang/String.html">String username = data.getString("username"); |
26 | 1.5.0/docs/api/java/lang/String.html">String username = data.getString("username"); |
21 | 1.5.0/docs/api/java/lang/String.html">String password = data.getString("password"); |
27 | 1.5.0/docs/api/java/lang/String.html">String password = data.getString("password"); |
22 | 28 | ||
23 | HibernateUtils.getCurrentSession().beginTransaction(); |
- | |
24 | - | ||
25 | //TODO COMPLETAR |
- | |
26 | UserSession session = null; |
- | |
27 | try { |
- | |
28 | session = SecurityFilter.loadSessionProxy(req); |
- | |
29 | UserSession persistente = (UserSession) HibernateUtils.getCurrentSession().get(UserSession.class,session.getCookie()); |
- | |
30 | //persistente.setUser(u); |
- | |
31 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
- | |
32 | e.printStackTrace(); |
- | |
33 | } catch (ServletException e) { |
- | |
34 | e.printStackTrace(); |
- | |
35 | } |
- | |
36 | - | ||
37 | - | ||
38 | - | ||
39 | 1.5.0/docs/api/java/lang/System.html">System.out.println(username); |
- | |
40 | 1.5.0/docs/api/java/lang/System.html">System.out.println(password); |
29 | new ServicoSessoes().login(username,password); |
41 | - | ||
42 | - | ||
43 | 30 | ||
44 | JSONObject js = new JSONObject(); |
31 | JSONObject js = new JSONObject(); |
45 | js.put("result","ok"); |
32 | js.put("result","ok"); |
46 | 33 | ||
47 | addMessage("User autenticado com sucesso",req); |
34 | addMessage("User autenticado com sucesso",req); |
48 | 35 | ||
49 | return js; |
36 | return js; |
50 | } |
37 | } |
51 | 38 | ||
- | 39 | ||
- | 40 | ||
52 | public JSONObject logout(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException |
41 | public JSONObject logout(JSONObject data, HttpServletRequest req, HttpServletResponse resp) throws JSONException { |
- | 42 | ||
- | 43 | new ServicoSessoes().logout(); |
|
53 | { |
44 | |
- | 45 | addMessage("Volte sempre",req); |
|
54 | JSONObject js = new JSONObject(); |
46 | JSONObject js = new JSONObject(); |
55 | js.put("result","ok"); |
47 | js.put("result","ok"); |
56 | 48 | ||
57 | return js; |
49 | return js; |
58 | } |
50 | } |