Commit 78cd1e2247f109dc7498a5a52baa7ae9718f90c3
1 parent
cd3051f8
refactor: Session in SessionContext umbenannt
Showing
3 changed files
with
12 additions
and
11 deletions
src/main/java/net/ziemers/swxercise/lg/model/user/Session.java renamed to src/main/java/net/ziemers/swxercise/lg/model/user/SessionContext.java
@@ -3,10 +3,10 @@ package net.ziemers.swxercise.lg.model.user; | @@ -3,10 +3,10 @@ package net.ziemers.swxercise.lg.model.user; | ||
3 | import javax.enterprise.context.SessionScoped; | 3 | import javax.enterprise.context.SessionScoped; |
4 | 4 | ||
5 | /** | 5 | /** |
6 | - * Verwaltet die Session des zurzeit angemeldeten Benutzers. | 6 | + * Verwaltet den SessionContext des zurzeit angemeldeten Benutzers. |
7 | */ | 7 | */ |
8 | @SessionScoped | 8 | @SessionScoped |
9 | -public class Session implements java.io.Serializable { | 9 | +public class SessionContext implements java.io.Serializable { |
10 | 10 | ||
11 | private User user = null; | 11 | private User user = null; |
12 | 12 |
src/main/java/net/ziemers/swxercise/lg/user/service/UserService.java
@@ -7,7 +7,7 @@ import javax.inject.Inject; | @@ -7,7 +7,7 @@ import javax.inject.Inject; | ||
7 | 7 | ||
8 | import net.ziemers.swxercise.db.dao.user.UserDao; | 8 | import net.ziemers.swxercise.db.dao.user.UserDao; |
9 | import net.ziemers.swxercise.lg.model.user.Profile; | 9 | import net.ziemers.swxercise.lg.model.user.Profile; |
10 | -import net.ziemers.swxercise.lg.model.user.Session; | 10 | +import net.ziemers.swxercise.lg.model.user.SessionContext; |
11 | import net.ziemers.swxercise.lg.model.user.User; | 11 | import net.ziemers.swxercise.lg.model.user.User; |
12 | import net.ziemers.swxercise.lg.user.dto.UserDto; | 12 | import net.ziemers.swxercise.lg.user.dto.UserDto; |
13 | 13 | ||
@@ -21,21 +21,21 @@ public class UserService { | @@ -21,21 +21,21 @@ public class UserService { | ||
21 | private UserDao dao; | 21 | private UserDao dao; |
22 | 22 | ||
23 | @Inject | 23 | @Inject |
24 | - private Session session; | 24 | + private SessionContext sessionContext; |
25 | 25 | ||
26 | public boolean loginUser(UserDto dto) { | 26 | public boolean loginUser(UserDto dto) { |
27 | final User user = dao.findByUsername(dto.getUsername()); | 27 | final User user = dao.findByUsername(dto.getUsername()); |
28 | 28 | ||
29 | if (user != null && user.getProfile().isValidPassword(dto.getPassword())) { | 29 | if (user != null && user.getProfile().isValidPassword(dto.getPassword())) { |
30 | - session.setUser(user); | 30 | + sessionContext.setUser(user); |
31 | return true; | 31 | return true; |
32 | } | 32 | } |
33 | return false; | 33 | return false; |
34 | } | 34 | } |
35 | 35 | ||
36 | public boolean logoutUser() { | 36 | public boolean logoutUser() { |
37 | - session.setUser(null); | ||
38 | - return session.getUser() == null; | 37 | + sessionContext.setUser(null); |
38 | + return sessionContext.getUser() == null; | ||
39 | } | 39 | } |
40 | 40 | ||
41 | public User findUser(final Long id) { | 41 | public User findUser(final Long id) { |
@@ -61,7 +61,7 @@ public class UserService { | @@ -61,7 +61,7 @@ public class UserService { | ||
61 | } | 61 | } |
62 | 62 | ||
63 | public boolean deleteUser() { | 63 | public boolean deleteUser() { |
64 | - final User user = session.getUser(); | 64 | + final User user = sessionContext.getUser(); |
65 | 65 | ||
66 | if (user != null) { | 66 | if (user != null) { |
67 | dao.remove(User.class, user.getId()); | 67 | dao.remove(User.class, user.getId()); |
@@ -71,7 +71,7 @@ public class UserService { | @@ -71,7 +71,7 @@ public class UserService { | ||
71 | } | 71 | } |
72 | 72 | ||
73 | public User getSessionUser() { | 73 | public User getSessionUser() { |
74 | - return session.getUser(); | 74 | + return sessionContext.getUser(); |
75 | } | 75 | } |
76 | 76 | ||
77 | } | 77 | } |
src/main/java/net/ziemers/swxercise/ui/UserViewController.java
@@ -7,6 +7,7 @@ import javax.inject.Inject; | @@ -7,6 +7,7 @@ import javax.inject.Inject; | ||
7 | import javax.ws.rs.*; | 7 | import javax.ws.rs.*; |
8 | import javax.ws.rs.core.MediaType; | 8 | import javax.ws.rs.core.MediaType; |
9 | 9 | ||
10 | +import net.ziemers.swxercise.lg.model.user.SessionContext; | ||
10 | import net.ziemers.swxercise.lg.model.user.User; | 11 | import net.ziemers.swxercise.lg.model.user.User; |
11 | import net.ziemers.swxercise.lg.user.dto.UserDto; | 12 | import net.ziemers.swxercise.lg.user.dto.UserDto; |
12 | import net.ziemers.swxercise.lg.user.service.UserService; | 13 | import net.ziemers.swxercise.lg.user.service.UserService; |
@@ -126,7 +127,7 @@ public class UserViewController { | @@ -126,7 +127,7 @@ public class UserViewController { | ||
126 | } | 127 | } |
127 | 128 | ||
128 | /** | 129 | /** |
129 | - * Meldet einen Benutzer durch übergebenen username und password mit einer neuen User-{@link net.ziemers.swxercise.lg.model.user.Session} an. | 130 | + * Meldet einen Benutzer durch übergebenen username und password mit einem neuen User-{@link SessionContext} an. |
130 | * | 131 | * |
131 | * Aufruf: | 132 | * Aufruf: |
132 | * POST http://localhost:8080/swxercise/rest/users/login | 133 | * POST http://localhost:8080/swxercise/rest/users/login |
@@ -146,7 +147,7 @@ public class UserViewController { | @@ -146,7 +147,7 @@ public class UserViewController { | ||
146 | } | 147 | } |
147 | 148 | ||
148 | /** | 149 | /** |
149 | - * Meldet den angemeldeten Benutzer von seiner User-{@link net.ziemers.swxercise.lg.model.user.Session} ab. | 150 | + * Meldet den angemeldeten Benutzer von seinem User-{@link SessionContext} ab. |
150 | * | 151 | * |
151 | * Aufruf: | 152 | * Aufruf: |
152 | * POST http://localhost:8080/swxercise/rest/users/logout | 153 | * POST http://localhost:8080/swxercise/rest/users/logout |