1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.portletbridge.portlet;
17
18 import java.io.Serializable;
19
20 import javax.portlet.PortletPreferences;
21 import javax.portlet.RenderRequest;
22
23 import org.apache.commons.httpclient.Credentials;
24 import org.apache.commons.httpclient.NTCredentials;
25 import org.apache.commons.httpclient.UsernamePasswordCredentials;
26 import org.portletbridge.PortletBridgeException;
27 import org.portletbridge.ResourceException;
28
29 public class DefaultBridgeAuthenticator implements BridgeAuthenticator, Serializable {
30
31 public Credentials getCredentials(RenderRequest request)
32 throws ResourceException {
33 PortletPreferences preferences = request.getPreferences();
34 String configAuthentication = preferences.getValue("authentication",
35 "none");
36 String configAuthenticationUsername = preferences.getValue(
37 "authenticationUsername", null);
38 String configAuthenticationPassword = preferences.getValue(
39 "authenticationPassword", null);
40 String configAuthenticationHost = preferences.getValue(
41 "authenticationHost", null);
42 String configAuthenticationDomain = preferences.getValue(
43 "authenticationDomain", null);
44 if (configAuthentication != null
45 && configAuthentication.trim().length() > 0) {
46 if ("ntlm".equalsIgnoreCase(configAuthentication)) {
47 return new NTCredentials(configAuthenticationUsername,
48 configAuthenticationPassword, configAuthenticationHost,
49 configAuthenticationDomain);
50 } else if ("basic".equalsIgnoreCase(configAuthentication)) {
51 return
52 new UsernamePasswordCredentials(
53 configAuthenticationUsername,
54 configAuthenticationPassword);
55 } else if ("none".equalsIgnoreCase(configAuthentication)) {
56 return null;
57 } else {
58 throw new PortletBridgeException("error.configAuthentication");
59 }
60 }
61 return null;
62 }
63 }