view src/main/java/de/intevation/lada/rest/InfoService.java @ 293:7c268f742553

Added config to pom to write metadata in the manifest file and send metadata via info service.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 14 Aug 2013 16:12:09 +0200
parents 0ddcc6240d47
children aee36709a8e8
line wrap: on
line source
package de.intevation.lada.rest;

import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
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.auth.Authentication;
import de.intevation.lada.auth.AuthenticationException;
import de.intevation.lada.auth.AuthenticationResponse;

class Info {
    String user;
    String groups;
    String version;
    public Info(String user, String groups, String version) {
        this.user = user;
        this.groups = groups;
        this.version = version;
    }
    public String getUser() {
        return user;
    }
    public void setUser(String user) {
        this.user = user;
    }
    public String getGroups() {
        return groups;
    }
    public void setGroups(String groups) {
        this.groups = groups;
    }
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
}

/**
 * This class produces a RESTful service to read, write and update
 * LOrt objects.
 *
 * @author <a href="mailto:torsten.irlaender@intevation.de">Torsten Irländer</a>
 */
@Path("/info")
@RequestScoped
public class InfoService
{
    /**
     * The authorization module.
     */
    @Inject
    @Named("ldapauth")
    private Authentication authentication;

    /**
     * Request SQL-Queries
     *
     * Query parameters are used for the filter in form of key-value pairs.
     *
     * @param info      The URL query parameters.
     * @param headers   The HTTP header containing authorization information.
     * @return Response object.
     */
    @GET
    @Produces("text/json")
    public Response filter(
        @Context UriInfo info,
        @Context HttpHeaders headers
    ) {
        try {
            if (!authentication.isAuthorizedUser(headers)) {
                return new Response(false, 699, null);
            }
            String user = authentication.getUserName(headers);
            AuthenticationResponse ar = authentication.authorizedGroups(headers);
            List<String> groups = ar.getNetzbetreiber();
            String gString = "";
            boolean first = true;
            for(String g : groups) {
                if (first) {
                    gString += g;
                }
                else {
                    gString += ", " + g;
                }
            }
            //TODO: This is the best way to get the version.
            //  Should read the version from MANIFEST.MF but does not work (returns null).
            //String version = getClass().getPackage().getImplementationVersion();
            String version = System.getProperty("de.intevation.lada.server.version");

            Response response = new Response(true, 200, new Info(user, gString, version));
            return response;
        }
        catch(AuthenticationException ae) {
            return new Response(false, 699, null);
        }
    }
}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)