Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/was/Request.java @ 2950:192eddbbd4cf
Implement a login page to be able to authenticate a user
The username and password requested by the login.jsp are send to
the LoginServlet. The credentials are afterwards used to authenticate
the user against GGinA.
flys-client/trunk@4928 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 11 Jul 2012 10:37:10 +0000 |
parents | 7683d4e43afa |
children |
rev | line source |
---|---|
2943
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server.was; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
2 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
3 import java.io.UnsupportedEncodingException; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
4 import java.net.URI; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
5 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
6 import org.apache.commons.codec.binary.Base64; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
7 import org.apache.http.client.methods.HttpGet; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
8 import org.apache.log4j.Logger; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
9 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
10 public class Request extends HttpGet { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
11 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
12 private final static String VERSION = "1.1"; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
13 private final static String REQUEST_SAML_RESPONSE = "GetSAMLResponse"; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
14 private final static String METHOD_AUTH_PASSWORD = |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
15 "urn:opengeospatial:authNMethod:OWS:1.0:password"; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
16 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
17 private static Logger logger = Logger.getLogger(Request.class); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
18 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
19 public Request(String uri) { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
20 String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
21 REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
22 "&ANONYMOUS=TRUE&CREDENTIALS="; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
23 this.setURI(URI.create(request)); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
24 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
25 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
26 public Request(String uri, String user, String pass, String encoding) { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
27 try { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
28 String base64user = this.toBase64(user, encoding); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
29 String base64pass = this.toBase64(pass, encoding); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
30 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
31 String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
32 REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
33 "&CREDENTIALS=" + base64user + "," + base64pass; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
34 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
35 System.out.println(request); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
36 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
37 this.setURI(URI.create(request)); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
38 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
39 catch(UnsupportedEncodingException e) { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
40 logger.error(e); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
41 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
42 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
43 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
44 private String toBase64(String value, String encoding) throws |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
45 UnsupportedEncodingException { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
46 if (encoding == null) { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
47 encoding = "utf-8"; |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
48 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
49 try { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
50 return new String(Base64.encodeBase64(value.getBytes(encoding))); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
51 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
52 catch(UnsupportedEncodingException e) { |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
53 logger.warn("Can't encode string with encoding " + encoding + |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
54 ". Falling back to utf-8. " + e); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
55 return this.toBase64(value, "utf-8"); |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
56 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
57 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
58 |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
59 } |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
60 // vim: set et si fileencoding=utf-8 ts=4 sw=4 tw=80: |
7683d4e43afa
Implement class representation of a Web Authentication Service (WAS)
Bjoern Ricks <bjoern.ricks@intevation.de>
parents:
diff
changeset
|
61 |