source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AutheticationResource.java @ 4670

Last change on this file since 4670 was 4670, checked in by olhsha, 10 years ago

removing remote user from dbIntegrityservice (not saved any more)

File size: 3.4 KB
Line 
1/*
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18package eu.dasish.annotation.backend.rest;
19
20import eu.dasish.annotation.schema.ObjectFactory;
21import eu.dasish.annotation.schema.User;
22import java.io.IOException;
23import java.sql.SQLException;
24import javax.servlet.ServletException;
25import javax.servlet.http.HttpServletRequestWrapper;
26import javax.ws.rs.GET;
27import javax.ws.rs.Path;
28import javax.ws.rs.Produces;
29import javax.ws.rs.core.MediaType;
30import javax.xml.bind.JAXBElement;
31import javax.xml.parsers.ParserConfigurationException;
32import org.springframework.stereotype.Component;
33import org.springframework.transaction.annotation.Transactional;
34
35/**
36 *
37 * @author olhsha
38 */
39@Component
40@Path("/authentication")
41@Transactional(rollbackFor = {Exception.class, SQLException.class, IOException.class, ParserConfigurationException.class})
42public class AutheticationResource extends ResourceResource {
43
44    @GET
45    @Produces(MediaType.TEXT_XML)
46    @Path("user")
47    @Transactional(readOnly = true)
48    public JAXBElement<User> getCurrentUser() throws IOException {
49        Number userID = this.getUserID();
50        if (userID != null) {
51            return new ObjectFactory().createUser(dbIntegrityService.getUser(userID));
52        }
53        return new ObjectFactory().createUser(new User());
54    }
55
56    /* the only request that redirects to the shibboleth login-page
57     *
58     */
59    @GET
60    @Produces(MediaType.TEXT_XML)
61    @Path("login")
62    @Transactional(readOnly = true)
63    public JAXBElement<User> loginAndGet() throws IOException {
64        String remoteUser = httpServletRequest.getRemoteUser();
65        verboseOutput = new VerboseOutput(httpServletResponse, loggerServer);
66        if (remoteUser != null) {
67            if (!remoteUser.equals("anonymous")) {
68                dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString());
69                final Number remoteUserID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser);
70                if (remoteUserID != null) {
71                    return new ObjectFactory().createUser(dbIntegrityService.getUser(remoteUserID));
72                } else {
73                    verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser, dbIntegrityService.getDataBaseAdmin().getDisplayName(), dbIntegrityService.getDataBaseAdmin().getEMail());
74                }
75            } else {
76                verboseOutput.ANONYMOUS_PRINCIPAL();
77            }
78        }
79        return new ObjectFactory().createUser(new User());
80    }
81
82    @GET
83    @Produces(MediaType.TEXT_XML)
84    @Path("logout")
85    @Transactional(readOnly = true)
86    public void logout() throws IOException, ServletException {
87        httpServletResponse.sendRedirect("eu.dasish.annotation.backend.logout");
88    }
89}
Note: See TracBrowser for help on using the repository browser.