Project

General

Profile

Download (1.6 KB) Statistics
| Branch: | Tag: | Revision:
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

    
19
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
20

    
21
/**
22
 * @author cmathew
23
 * @date 27 Jan 2015
24
 *
25
 */
26
public class CdmAuthenticatedHttpInvokerRequestExecutor extends TimestampingHttpInvokerRequestExecutor {
27

    
28
    @Override
29
    protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
30
    	HttpPost postMethod = super.createHttpPost(config);
31

    
32
        SecurityContext securityContext = CdmApplicationState.getCurrentSecurityContext();
33
        if(securityContext != null) {
34
            Authentication auth = securityContext.getAuthentication();
35
            if ((auth != null) && (auth.getName() != null) &&
36
                    (auth.getCredentials() != null)) {
37
                String base64 = auth.getName() + ":" + auth.getCredentials().toString();
38
                postMethod.setHeader("Authorization", "Basic " +
39
                        new String(Base64.encodeBase64(base64.getBytes())));
40
            }
41
        }
42
        return postMethod;
43
    }
44
}
(2-2/7)