Mercurial > lada > lada-server
view src/main/java/de/intevation/lada/rest/UserService.java @ 1290:14876c62f692
Push down refreshing of persisted objects deeper into the stack.
There are more places besides creation of Probe objects where it is
useful to return within the response what has been really written to
the database (including modifications by the database itself) instead
of merely the request data, e.g. creation of Ort objects, which
includes database generated ort_ids.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 08 Feb 2017 18:02:05 +0100 |
parents | f5b4784d9173 |
children |
line wrap: on
line source
/* Copyright (C) 2015 by Bundesamt fuer Strahlenschutz * Software engineering by Intevation GmbH * * This file is Free Software under the GNU GPL (v>=3) * and comes with ABSOLUTELY NO WARRANTY! Check out * the documentation coming with IMIS-Labordaten-Application for details. */ package de.intevation.lada.rest; import java.util.Date; import java.util.HashMap; import java.util.Map; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.UriInfo; import de.intevation.lada.util.annotation.AuthorizationConfig; import de.intevation.lada.util.auth.Authorization; import de.intevation.lada.util.auth.AuthorizationType; import de.intevation.lada.util.auth.UserInfo; import de.intevation.lada.util.rest.Response; /** * REST service to get login data for the Lada application. * <p> * This service produces data in the application/json media type. * A typical response holds information about the action performed and the data. * <pre> * <code> * { * "success": [boolean], * "message": [string], * "data":{ * "username": [string], * "servertime": [timestamp], * "roles": [string] * }, * "errors": [object], * "warnings": [object], * "readonly": [boolean], * "totalCount": [number] * } * </code> * </pre> * * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> */ @Path("rest/user") @RequestScoped public class UserService{ @Inject @AuthorizationConfig(type=AuthorizationType.HEADER) private Authorization authorization; /** * Get login data. * <pre> * <code> * { * "success": [boolean], * "message": [string], * "data": { * "username": [string], * "servertime": [timestamp], * "roles": [string] * }, * "errors": [object], * "warnings": [object], * "readonly": [boolean], * "totalCount": [number] * } * </code> * </pre> * * @return Response object containing login data. */ @GET @Path("/") @Produces("application/json") public Response get( @Context HttpHeaders headers, @Context UriInfo info, @Context HttpServletRequest request ) { Map<String, Object> response = new HashMap<String, Object>(); response.put("username", request.getAttribute("lada.user.name")); response.put("roles", request.getAttribute("lada.user.roles")); response.put("servertime", new Date().getTime()); UserInfo userInfo = authorization.getInfo(request); response.put("messstelleLabor", userInfo.getMessLaborId()); response.put("netzbetreiber", userInfo.getNetzbetreiber()); response.put("funktionen", userInfo.getFunktionen()); return new Response(true, 200, response); } }