session bug fix

~30 min of work
This commit is contained in:
Benedikt Galbavy 2024-01-07 23:27:47 +01:00
parent 74a2da5f6f
commit db2ade5881
2 changed files with 15 additions and 9 deletions

View File

@ -29,11 +29,11 @@ read -p "Press any key to resume ..." null
# --------------------------------------------------
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 .
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 .
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 .
read -p "Press any key to resume ..." null

View File

@ -28,11 +28,6 @@ public final class SessionHandler {
}
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()
.command(SqlCommand.SELECT)
@ -53,13 +48,24 @@ public final class SessionHandler {
return null;
}
for (val session : this.sessions.entrySet()) {
if (userCredentials.username().equals(session.getValue().username())) {
this.sessions.remove(session.getKey());
}
}
UUID uuid = UUID.randomUUID();
this.sessions.put(uuid, new UserInfo((UUID) row1.get("uuid"), userCredentials.username(), (boolean) row1.get("admin")));
return uuid;
}
public static UUID tokenFromHttpHeader(String headerValue) {
return headerValue == null ? null : UUID.fromString(headerValue.replaceFirst("^Bearer ", ""));
try {
return headerValue == null ? null : UUID.fromString(headerValue.replaceFirst("^Bearer ", ""));
}
catch (IllegalArgumentException e) {
return null;
}
}
public TokenValidity verifyUUID(UUID uuid) {