1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.impl;
18
19 import java.net.URL;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.apache.jetspeed.components.util.system.SystemResourceUtil;
25 import org.apache.jetspeed.components.util.system.ClassLoaderSystemResourceUtilImpl;
26 import org.apache.jetspeed.security.AuthenticationProvider;
27 import org.apache.jetspeed.security.spi.CredentialHandler;
28 import org.apache.jetspeed.security.spi.UserSecurityHandler;
29
30 /***
31 * @see org.apache.jetspeed.security.AuthenticationProvider
32 * @author <a href="mailto:LeStrat_David@emc.com">David Le Strat </a>
33 */
34 public class AuthenticationProviderImpl implements AuthenticationProvider
35 {
36
37 /*** The logger. */
38 private static final Log log = LogFactory.getLog(AuthenticationProviderImpl.class);
39
40 /*** The provider name. */
41 private String providerName;
42
43 /*** The provider description. */
44 private String providerDescription;
45
46 /*** The {@link CredentialHandler}. */
47 private CredentialHandler credHandler;
48
49 /*** The {@link UserSecurityHandler}. */
50 private UserSecurityHandler userSecurityHandler;
51
52 /***
53 * <p>
54 * Constructor to configure authenticatino user security and credential
55 * handlers.
56 * </p>
57 *
58 * @param providerName The provider name.
59 * @param providerDescription The provider description.
60 * @param credHandler The credential handler.
61 * @param userSecurityHandler The user security handler.
62 */
63 public AuthenticationProviderImpl(String providerName, String providerDescription, CredentialHandler credHandler,
64 UserSecurityHandler userSecurityHandler)
65 {
66
67 this.providerName = providerName;
68
69 this.providerDescription = providerDescription;
70
71
72 this.credHandler = credHandler;
73
74 this.userSecurityHandler = userSecurityHandler;
75 }
76
77 /***
78 * <p>
79 * Constructor configuring the security service with the correct
80 * <code>java.security.auth.login.config</code>.
81 * </p>
82 *
83 * @param providerName The provider name.
84 * @param providerDescription The provider description.
85 * @param loginConfig The login module config.
86 * @param credHandler The credential handler.
87 * @param userSecurityHandler The user security handler.
88 */
89 public AuthenticationProviderImpl(String providerName, String providerDescription, String loginConfig,
90 CredentialHandler credHandler, UserSecurityHandler userSecurityHandler)
91 {
92 this(providerName, providerDescription, credHandler, userSecurityHandler);
93
94 ClassLoader cl = Thread.currentThread().getContextClassLoader();
95 SystemResourceUtil resourceUtil = new ClassLoaderSystemResourceUtilImpl(cl);
96 URL loginConfigUrl = null;
97
98 try
99 {
100 loginConfigUrl = resourceUtil.getURL(loginConfig);
101 }
102 catch (Exception e)
103 {
104 throw new IllegalStateException("Could not locate the login config. Bad URL. " + e.toString());
105 }
106 if (null != loginConfigUrl)
107 {
108 if (log.isDebugEnabled())
109 log.debug("java.security.auth.login.config = " + loginConfigUrl.toString());
110 System.setProperty("java.security.auth.login.config", loginConfigUrl.toString());
111 }
112 }
113
114 /***
115 * @return Returns the providerDescription.
116 */
117 public String getProviderDescription()
118 {
119 return providerDescription;
120 }
121
122 /***
123 * @param providerDescription The providerDescription to set.
124 */
125 public void setProviderDescription(String providerDescription)
126 {
127 this.providerDescription = providerDescription;
128 }
129
130 /***
131 * @return Returns the providerName.
132 */
133 public String getProviderName()
134 {
135 return providerName;
136 }
137
138 /***
139 * @param providerName The providerName to set.
140 */
141 public void setProviderName(String providerName)
142 {
143 this.providerName = providerName;
144 }
145
146 /***
147 * @see org.apache.jetspeed.security.AuthenticationProvider#getCredentialHandler()
148 */
149 public CredentialHandler getCredentialHandler()
150 {
151 return this.credHandler;
152 }
153
154 /***
155 * @see org.apache.jetspeed.security.AuthenticationProvider#getUserSecurityHandler()
156 */
157 public UserSecurityHandler getUserSecurityHandler()
158 {
159 return this.userSecurityHandler;
160 }
161
162 /***
163 * @see org.apache.jetspeed.security.AuthenticationProvider#setCredentialHandler(CredentialHandler)
164 */
165 public void setCredentialHandler(CredentialHandler credHandler)
166 {
167 this.credHandler = credHandler;
168 }
169
170 /***
171 * @see org.apache.jetspeed.security.AuthenticationProvider#setUserSecurityHandler(UserSecurityHandler)
172 */
173 public void setUserSecurityHandler(UserSecurityHandler userSecurityHandler)
174 {
175 this.userSecurityHandler = userSecurityHandler;
176 }
177 }