session bug fix
~30 min of work
This commit is contained in:
parent
74a2da5f6f
commit
db2ade5881
@ -29,11 +29,11 @@ read -p "Press any key to resume ..." null
|
|||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
echo "2) Login Users"
|
echo "2) Login Users"
|
||||||
token1=$(curl -i -X POST http://localhost:10001/sessions --header "Content-Type: application/json" -d "{\"Username\":\"kienboec\", \"Password\":\"daniel\"}")
|
token1=$(curl --silent -X POST http://localhost:10001/sessions --header "Content-Type: application/json" -d "{\"Username\":\"kienboec\", \"Password\":\"daniel\"}")
|
||||||
echo .
|
echo .
|
||||||
token2=$(curl -i -X POST http://localhost:10001/sessions --header "Content-Type: application/json" -d "{\"Username\":\"altenhof\", \"Password\":\"markus\"}")
|
token2=$(curl --silent -X POST http://localhost:10001/sessions --header "Content-Type: application/json" -d "{\"Username\":\"altenhof\", \"Password\":\"markus\"}")
|
||||||
echo .
|
echo .
|
||||||
token3=$(curl -i -X POST http://localhost:10001/sessions --header "Content-Type: application/json" -d "{\"Username\":\"admin\", \"Password\":\"istrator\"}")
|
token3=$(curl --silent -X POST http://localhost:10001/sessions --header "Content-Type: application/json" -d "{\"Username\":\"admin\", \"Password\":\"istrator\"}")
|
||||||
echo .
|
echo .
|
||||||
|
|
||||||
read -p "Press any key to resume ..." null
|
read -p "Press any key to resume ..." null
|
||||||
|
|||||||
@ -28,11 +28,6 @@ public final class SessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized UUID login(UserCredentials userCredentials) throws SQLException { // avoid multiple logins of same user
|
public synchronized UUID login(UserCredentials userCredentials) throws SQLException { // avoid multiple logins of same user
|
||||||
for (val session : this.sessions.entrySet()) {
|
|
||||||
if (userCredentials.username().equals(session.getValue().username())) {
|
|
||||||
this.sessions.remove(session.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val result = DbQuery.builder()
|
val result = DbQuery.builder()
|
||||||
.command(SqlCommand.SELECT)
|
.command(SqlCommand.SELECT)
|
||||||
@ -53,14 +48,25 @@ public final class SessionHandler {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (val session : this.sessions.entrySet()) {
|
||||||
|
if (userCredentials.username().equals(session.getValue().username())) {
|
||||||
|
this.sessions.remove(session.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
this.sessions.put(uuid, new UserInfo((UUID) row1.get("uuid"), userCredentials.username(), (boolean) row1.get("admin")));
|
this.sessions.put(uuid, new UserInfo((UUID) row1.get("uuid"), userCredentials.username(), (boolean) row1.get("admin")));
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID tokenFromHttpHeader(String headerValue) {
|
public static UUID tokenFromHttpHeader(String headerValue) {
|
||||||
|
try {
|
||||||
return headerValue == null ? null : UUID.fromString(headerValue.replaceFirst("^Bearer ", ""));
|
return headerValue == null ? null : UUID.fromString(headerValue.replaceFirst("^Bearer ", ""));
|
||||||
}
|
}
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TokenValidity verifyUUID(UUID uuid) {
|
public TokenValidity verifyUUID(UUID uuid) {
|
||||||
return verifyUUID(uuid, false);
|
return verifyUUID(uuid, false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user