2 * Copyright (C) 2015 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.service
;
11 import java
.io
.IOException
;
13 import org
.apache
.commons
.codec
.binary
.Base64
;
14 import org
.apache
.http
.client
.methods
.HttpPost
;
15 import org
.springframework
.remoting
.httpinvoker
.HttpComponentsHttpInvokerRequestExecutor
;
16 import org
.springframework
.remoting
.httpinvoker
.HttpInvokerClientConfiguration
;
17 import org
.springframework
.security
.core
.Authentication
;
18 import org
.springframework
.security
.core
.context
.SecurityContext
;
20 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
27 public class CdmAuthenticatedHttpInvokerRequestExecutor
extends HttpComponentsHttpInvokerRequestExecutor
{
30 protected HttpPost
createHttpPost(HttpInvokerClientConfiguration config
) throws IOException
{
31 HttpPost postMethod
= super.createHttpPost(config
);
33 SecurityContext securityContext
= CdmApplicationState
.getCurrentSecurityContext();
34 if(securityContext
!= null) {
35 Authentication auth
= securityContext
.getAuthentication();
36 if ((auth
!= null) && (auth
.getName() != null) &&
37 (auth
.getCredentials() != null)) {
38 String base64
= auth
.getName() + ":" + auth
.getCredentials().toString();
39 postMethod
.setHeader("Authorization", "Basic " +
40 new String(Base64
.encodeBase64(base64
.getBytes())));