3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.service
;
12 import java
.io
.IOException
;
14 import org
.apache
.commons
.codec
.binary
.Base64
;
15 import org
.apache
.commons
.httpclient
.methods
.PostMethod
;
16 import org
.springframework
.remoting
.httpinvoker
.CommonsHttpInvokerRequestExecutor
;
17 import org
.springframework
.remoting
.httpinvoker
.HttpInvokerClientConfiguration
;
18 import org
.springframework
.security
.core
.Authentication
;
19 import org
.springframework
.security
.core
.context
.SecurityContextHolder
;
26 public class CdmAuthenticatedHttpInvokerRequestExecutor
extends CommonsHttpInvokerRequestExecutor
{
29 protected PostMethod
createPostMethod(HttpInvokerClientConfiguration config
) throws IOException
{
30 PostMethod postMethod
= super.createPostMethod(config
);
33 SecurityContextHolder
.getContext().getAuthentication();
35 if ((auth
!= null) && (auth
.getName() != null) &&
36 (auth
.getCredentials() != null)) {
37 String base64
= auth
.getName() + ":" + auth
.getCredentials().toString();
38 postMethod
.setRequestHeader("Authorization", "Basic " +
39 new String(Base64
.encodeBase64(base64
.getBytes())));