Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/auth/was/Request.java @ 2956:d7f76f197d89
Refactor GGInA authentication
Move authentication related classes to de.intevation.fly.client.server.auth
package. Abstract the authentication classes to allow other authentications
beside WAS/GGInA.
flys-client/trunk@4936 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Wed, 11 Jul 2012 13:31:56 +0000 |
parents | |
children | e0c6de3a9803 |
comparison
equal
deleted
inserted
replaced
2955:f1030909eeb6 | 2956:d7f76f197d89 |
---|---|
1 package de.intevation.flys.client.server.auth.was; | |
2 | |
3 import java.io.UnsupportedEncodingException; | |
4 import java.net.URI; | |
5 | |
6 import org.apache.commons.codec.binary.Base64; | |
7 import org.apache.http.client.methods.HttpGet; | |
8 import org.apache.log4j.Logger; | |
9 | |
10 public class Request extends HttpGet { | |
11 | |
12 private final static String VERSION = "1.1"; | |
13 private final static String REQUEST_SAML_RESPONSE = "GetSAMLResponse"; | |
14 private final static String METHOD_AUTH_PASSWORD = | |
15 "urn:opengeospatial:authNMethod:OWS:1.0:password"; | |
16 | |
17 private static Logger logger = Logger.getLogger(Request.class); | |
18 | |
19 public Request(String uri) { | |
20 String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + | |
21 REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + | |
22 "&ANONYMOUS=TRUE&CREDENTIALS="; | |
23 this.setURI(URI.create(request)); | |
24 } | |
25 | |
26 public Request(String uri, String user, String pass, String encoding) { | |
27 try { | |
28 String base64user = this.toBase64(user, encoding); | |
29 String base64pass = this.toBase64(pass, encoding); | |
30 | |
31 String request = uri + "?VERSION=" + VERSION + "&REQUEST=" + | |
32 REQUEST_SAML_RESPONSE + "&METHOD=" + METHOD_AUTH_PASSWORD + | |
33 "&CREDENTIALS=" + base64user + "," + base64pass; | |
34 | |
35 System.out.println(request); | |
36 | |
37 this.setURI(URI.create(request)); | |
38 } | |
39 catch(UnsupportedEncodingException e) { | |
40 logger.error(e); | |
41 } | |
42 } | |
43 | |
44 private String toBase64(String value, String encoding) throws | |
45 UnsupportedEncodingException { | |
46 if (encoding == null) { | |
47 encoding = "utf-8"; | |
48 } | |
49 try { | |
50 return new String(Base64.encodeBase64(value.getBytes(encoding))); | |
51 } | |
52 catch(UnsupportedEncodingException e) { | |
53 logger.warn("Can't encode string with encoding " + encoding + | |
54 ". Falling back to utf-8. " + e); | |
55 return this.toBase64(value, "utf-8"); | |
56 } | |
57 } | |
58 | |
59 } | |
60 // vim: set et si fileencoding=utf-8 ts=4 sw=4 tw=80: | |
61 |