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 | */ |
---|
18 | package eu.dasish.annotation.backend.rest; |
---|
19 | |
---|
20 | import eu.dasish.annotation.backend.dao.DBIntegrityService; |
---|
21 | import java.io.IOException; |
---|
22 | import javax.servlet.ServletContext; |
---|
23 | import javax.servlet.http.HttpServletRequest; |
---|
24 | import javax.servlet.http.HttpServletResponse; |
---|
25 | import javax.ws.rs.core.Context; |
---|
26 | import javax.ws.rs.core.UriInfo; |
---|
27 | import javax.ws.rs.ext.Providers; |
---|
28 | import org.slf4j.Logger; |
---|
29 | import org.slf4j.LoggerFactory; |
---|
30 | import org.springframework.beans.factory.annotation.Autowired; |
---|
31 | |
---|
32 | /** |
---|
33 | * |
---|
34 | * @author olhsha |
---|
35 | */ |
---|
36 | public class ResourceResource { |
---|
37 | |
---|
38 | @Autowired |
---|
39 | protected DBIntegrityService dbIntegrityService; |
---|
40 | @Context |
---|
41 | protected HttpServletRequest httpServletRequest; |
---|
42 | @Context |
---|
43 | protected HttpServletResponse httpServletResponse; |
---|
44 | @Context |
---|
45 | protected UriInfo uriInfo; |
---|
46 | @Context |
---|
47 | protected Providers providers; |
---|
48 | @Context |
---|
49 | protected ServletContext context; |
---|
50 | protected Logger loggerServer = LoggerFactory.getLogger(HttpServletResponse.class); |
---|
51 | protected VerboseOutput verboseOutput; |
---|
52 | protected String admin = "admin"; |
---|
53 | protected String anonym = "anonymous"; |
---|
54 | |
---|
55 | public Number getUserID() throws IOException { |
---|
56 | dbIntegrityService.setServiceURI(uriInfo.getBaseUri().toString()); |
---|
57 | verboseOutput = new VerboseOutput(httpServletResponse, loggerServer); |
---|
58 | String remoteUser = httpServletRequest.getRemoteUser(); |
---|
59 | if (remoteUser != null) { |
---|
60 | if (!remoteUser.equals(anonym)) { |
---|
61 | final Number userID = dbIntegrityService.getUserInternalIDFromRemoteID(remoteUser); |
---|
62 | if (userID != null) { |
---|
63 | return userID; |
---|
64 | } |
---|
65 | verboseOutput.REMOTE_PRINCIPAL_NOT_FOUND(remoteUser, dbIntegrityService.getDataBaseAdmin().getDisplayName(), dbIntegrityService.getDataBaseAdmin().getEMail()); |
---|
66 | return null; |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | verboseOutput.NOT_LOGGED_IN(dbIntegrityService.getDataBaseAdmin().getDisplayName(), dbIntegrityService.getDataBaseAdmin().getEMail()); |
---|
71 | return null; |
---|
72 | |
---|
73 | } |
---|
74 | } |
---|