diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-11-18 03:51:43 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-11-18 03:51:43 +1300 |
commit | 2bd0cdf04b2849a510f178cafea17fffa5d34961 (patch) | |
tree | 3ea0601bef67f6e04924221d8b20aaba0d0e71bf /src/org/traccar | |
parent | 468e3b0aa03fbe69b4c590743cf9f6886ef99751 (diff) | |
download | traccar-server-2bd0cdf04b2849a510f178cafea17fffa5d34961.tar.gz traccar-server-2bd0cdf04b2849a510f178cafea17fffa5d34961.tar.bz2 traccar-server-2bd0cdf04b2849a510f178cafea17fffa5d34961.zip |
Fix the problem with session
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/api/SecurityRequestFilter.java | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/org/traccar/api/SecurityRequestFilter.java b/src/org/traccar/api/SecurityRequestFilter.java index be74a3607..3f2390754 100644 --- a/src/org/traccar/api/SecurityRequestFilter.java +++ b/src/org/traccar/api/SecurityRequestFilter.java @@ -17,6 +17,7 @@ package org.traccar.api; import org.traccar.Context; import org.traccar.api.resource.SessionResource; +import org.traccar.helper.Log; import org.traccar.model.User; import javax.annotation.security.PermitAll; @@ -62,29 +63,35 @@ public class SecurityRequestFilter implements ContainerRequestFilter { SecurityContext securityContext = null; - String authHeader = requestContext.getHeaderString(AUTHORIZATION_HEADER); - if (authHeader != null) { + try { - try { - String[] auth = decodeBasicAuth(authHeader); - User user = Context.getPermissionsManager().login(auth[0], auth[1]); - if (user != null) { - Context.getStatisticsManager().registerRequest(user.getId()); - securityContext = new UserSecurityContext(new UserPrincipal(user.getId())); + String authHeader = requestContext.getHeaderString(AUTHORIZATION_HEADER); + if (authHeader != null) { + + try { + String[] auth = decodeBasicAuth(authHeader); + User user = Context.getPermissionsManager().login(auth[0], auth[1]); + if (user != null) { + Context.getStatisticsManager().registerRequest(user.getId()); + securityContext = new UserSecurityContext(new UserPrincipal(user.getId())); + } + } catch (SQLException e) { + throw new WebApplicationException(e); } - } catch (SQLException e) { - throw new WebApplicationException(e); - } - } else if (request.getSession() != null) { + } else if (request.getSession() != null) { + + Long userId = (Long) request.getSession().getAttribute(SessionResource.USER_ID_KEY); + if (userId != null) { + Context.getPermissionsManager().checkUser(userId); + Context.getStatisticsManager().registerRequest(userId); + securityContext = new UserSecurityContext(new UserPrincipal(userId)); + } - Long userId = (Long) request.getSession().getAttribute(SessionResource.USER_ID_KEY); - if (userId != null) { - Context.getPermissionsManager().checkUser(userId); - Context.getStatisticsManager().registerRequest(userId); - securityContext = new UserSecurityContext(new UserPrincipal(userId)); } + } catch (SecurityException e) { + Log.warning(e); } if (securityContext != null) { |