diff --git a/inf.sh b/inf.sh index f49dd8b..f2adc96 100755 --- a/inf.sh +++ b/inf.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker run --name glicko-mongo --network=glickorater -p 27017:27017 -d mongo +docker run --name glicko-postgres --network=glickorater -p 5432:5432 -d postgres diff --git a/runimage.sh b/runimage.sh index f53323c..8f30bbf 100755 --- a/runimage.sh +++ b/runimage.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -docker run --name glicko-rater --network=glickorater -p 3000:3000 -e MONGODB_ADDR="glicko-mongo" -d desp/glickorater:local +docker run --name glicko-rater --network=glickorater -p 3000:3000 -e DB_ADDR="glicko-postgres" -d desp/glickorater:local diff --git a/src/main/java/solutions/desperate/glicko/domain/service/AuthService.java b/src/main/java/solutions/desperate/glicko/domain/service/AuthService.java index 83ca7ea..ff2b289 100644 --- a/src/main/java/solutions/desperate/glicko/domain/service/AuthService.java +++ b/src/main/java/solutions/desperate/glicko/domain/service/AuthService.java @@ -51,6 +51,11 @@ public void doAuth(UUID token) { } } + public void logout(UUID authorization) { + Token token = getToken(authorization).orElseThrow(() -> new NotAuthorizedException("Not authorized")); + query.update("DELETE FROM token WHERE token = ?").params(token.token().toString()).run(); + } + private Optional getToken(UUID token) { return query.select("SELECT * FROM token WHERE token = ?").params(token.toString()).firstResult(tokenMapper()); } diff --git a/src/main/java/solutions/desperate/glicko/rest/TokenApi.java b/src/main/java/solutions/desperate/glicko/rest/TokenApi.java index a92eb94..0f59779 100644 --- a/src/main/java/solutions/desperate/glicko/rest/TokenApi.java +++ b/src/main/java/solutions/desperate/glicko/rest/TokenApi.java @@ -3,6 +3,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import solutions.desperate.glicko.rest.dto.AuthHeader; import solutions.desperate.glicko.rest.view.TokenView; import solutions.desperate.glicko.domain.service.AuthService; @@ -10,6 +11,7 @@ import javax.ws.rs.BadRequestException; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -38,4 +40,11 @@ public TokenView token(@ApiParam(allowableValues = "password") @FormParam("grant } return authService.doLogin(username, password); } + + @ApiOperation(value = "Log out user") + @POST + @Consumes(MediaType.TEXT_PLAIN) + public void logout(@ApiParam(hidden = true) @HeaderParam("authorization") String authorization) { + authService.logout(AuthHeader.getAuthString(authorization)); + } }