1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.service;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
|
13
|
import org.apache.commons.codec.binary.Base64;
|
14
|
import org.apache.http.client.methods.HttpPost;
|
15
|
import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
|
16
|
import org.springframework.security.core.Authentication;
|
17
|
import org.springframework.security.core.context.SecurityContext;
|
18
|
import org.springframework.security.core.context.SecurityContextHolder;
|
19
|
|
20
|
/**
|
21
|
* @author cmathew
|
22
|
* @date 27 Jan 2015
|
23
|
*/
|
24
|
public class AuthenticatingHttpInvokerRequestExecutor extends TimestampingHttpInvokerRequestExecutor {
|
25
|
|
26
|
@Override
|
27
|
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
|
28
|
HttpPost postMethod = super.createHttpPost(config);
|
29
|
|
30
|
SecurityContext securityContext = SecurityContextHolder.getContext();
|
31
|
if(securityContext != null) {
|
32
|
Authentication auth = securityContext.getAuthentication();
|
33
|
if ((auth != null) && (auth.getName() != null) &&
|
34
|
(auth.getCredentials() != null)) {
|
35
|
String base64 = auth.getName() + ":" + auth.getCredentials().toString();
|
36
|
postMethod.setHeader("Authorization", "Basic " +
|
37
|
new String(Base64.encodeBase64(base64.getBytes())));
|
38
|
}
|
39
|
}
|
40
|
return postMethod;
|
41
|
}
|
42
|
}
|