1
14
15 package com.liferay.portal.spring.remoting;
16
17 import com.liferay.portal.PwdEncryptorException;
18 import com.liferay.portal.kernel.util.GetterUtil;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.security.pwd.PwdEncryptor;
21
22 import java.io.IOException;
23
24 import java.net.HttpURLConnection;
25
26 import org.apache.commons.codec.binary.Base64;
27
28 import org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor;
29
30
41 public class AuthenticatingHttpInvokerRequestExecutor
42 extends SimpleHttpInvokerRequestExecutor {
43
44 public AuthenticatingHttpInvokerRequestExecutor() {
45 super();
46 }
47
48 public long getUserId() {
49 return _userId;
50 }
51
52 public void setUserId(long userId) {
53 _userId = userId;
54 }
55
56 public String getPassword() {
57 return _password;
58 }
59
60 public void setPassword(String password) throws PwdEncryptorException {
61 _password = PwdEncryptor.encrypt(password);
62 }
63
64
69 protected void prepareConnection(HttpURLConnection con, int contentLength)
70 throws IOException {
71
72 super.prepareConnection(con, contentLength);
73
74 if (getUserId() > 0) {
75 String password = GetterUtil.getString(getPassword());
76
77 String base64 = getUserId() + StringPool.COLON + password;
78
79 con.setRequestProperty(
80 "Authorization",
81 "Basic " + new String(Base64.encodeBase64(base64.getBytes())));
82 }
83 }
84
85 private long _userId;
86 private String _password;
87
88 }