From 3995cfc37b2485e555043c9d15f23c8013752829 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 2 Mar 2017 17:58:23 +0500 Subject: Decode user and password cookies --- src/org/traccar/api/resource/SessionResource.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/api') diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java index 5f1c597d1..acdbb7c87 100644 --- a/src/org/traccar/api/resource/SessionResource.java +++ b/src/org/traccar/api/resource/SessionResource.java @@ -33,6 +33,11 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.xml.bind.DatatypeConverter; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.sql.SQLException; @Path("session") @@ -49,7 +54,7 @@ public class SessionResource extends BaseResource { @PermitAll @GET - public User get(@QueryParam("token") String token) throws SQLException { + public User get(@QueryParam("token") String token) throws SQLException, UnsupportedEncodingException { Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY); if (userId == null) { Cookie[] cookies = request.getCookies(); @@ -57,10 +62,14 @@ public class SessionResource extends BaseResource { if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies[i].getName().equals(USER_COOKIE_KEY)) { - email = cookies[i].getValue(); + byte[] emailBytes = DatatypeConverter.parseBase64Binary( + URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name())); + email = new String(emailBytes, StandardCharsets.UTF_8); } if (cookies[i].getName().equals(PASS_COOKIE_KEY)) { - password = cookies[i].getValue(); + byte[] passwordBytes = DatatypeConverter.parseBase64Binary( + URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name())); + password = new String(passwordBytes, StandardCharsets.UTF_8); } } } -- cgit v1.2.3