001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.impl;
018:
019: import java.net.URL;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023:
024: import org.apache.jetspeed.components.util.system.SystemResourceUtil;
025: import org.apache.jetspeed.components.util.system.ClassLoaderSystemResourceUtilImpl;
026: import org.apache.jetspeed.security.AuthenticationProvider;
027: import org.apache.jetspeed.security.spi.CredentialHandler;
028: import org.apache.jetspeed.security.spi.UserSecurityHandler;
029:
030: /**
031: * @see org.apache.jetspeed.security.AuthenticationProvider
032: * @author <a href="mailto:LeStrat_David@emc.com">David Le Strat </a>
033: */
034: public class AuthenticationProviderImpl implements
035: AuthenticationProvider {
036:
037: /** The logger. */
038: private static final Log log = LogFactory
039: .getLog(AuthenticationProviderImpl.class);
040:
041: /** The provider name. */
042: private String providerName;
043:
044: /** The provider description. */
045: private String providerDescription;
046:
047: /** The {@link CredentialHandler}. */
048: private CredentialHandler credHandler;
049:
050: /** The {@link UserSecurityHandler}. */
051: private UserSecurityHandler userSecurityHandler;
052:
053: /**
054: * <p>
055: * Constructor to configure authenticatino user security and credential
056: * handlers.
057: * </p>
058: *
059: * @param providerName The provider name.
060: * @param providerDescription The provider description.
061: * @param credHandler The credential handler.
062: * @param userSecurityHandler The user security handler.
063: */
064: public AuthenticationProviderImpl(String providerName,
065: String providerDescription, CredentialHandler credHandler,
066: UserSecurityHandler userSecurityHandler) {
067: // The provider name.
068: this .providerName = providerName;
069: // The provider description.
070: this .providerDescription = providerDescription;
071:
072: // The credential handler.
073: this .credHandler = credHandler;
074: // The user security handler.
075: this .userSecurityHandler = userSecurityHandler;
076: }
077:
078: /**
079: * <p>
080: * Constructor configuring the security service with the correct
081: * <code>java.security.auth.login.config</code>.
082: * </p>
083: *
084: * @param providerName The provider name.
085: * @param providerDescription The provider description.
086: * @param loginConfig The login module config.
087: * @param credHandler The credential handler.
088: * @param userSecurityHandler The user security handler.
089: */
090: public AuthenticationProviderImpl(String providerName,
091: String providerDescription, String loginConfig,
092: CredentialHandler credHandler,
093: UserSecurityHandler userSecurityHandler) {
094: this (providerName, providerDescription, credHandler,
095: userSecurityHandler);
096:
097: ClassLoader cl = Thread.currentThread().getContextClassLoader();
098: SystemResourceUtil resourceUtil = new ClassLoaderSystemResourceUtilImpl(
099: cl);
100: URL loginConfigUrl = null;
101: // The login module config.
102: try {
103: loginConfigUrl = resourceUtil.getURL(loginConfig);
104: } catch (Exception e) {
105: throw new IllegalStateException(
106: "Could not locate the login config. Bad URL. "
107: + e.toString());
108: }
109: if (null != loginConfigUrl) {
110: if (log.isDebugEnabled())
111: log.debug("java.security.auth.login.config = "
112: + loginConfigUrl.toString());
113: System.setProperty("java.security.auth.login.config",
114: loginConfigUrl.toString());
115: }
116: }
117:
118: /**
119: * @return Returns the providerDescription.
120: */
121: public String getProviderDescription() {
122: return providerDescription;
123: }
124:
125: /**
126: * @param providerDescription The providerDescription to set.
127: */
128: public void setProviderDescription(String providerDescription) {
129: this .providerDescription = providerDescription;
130: }
131:
132: /**
133: * @return Returns the providerName.
134: */
135: public String getProviderName() {
136: return providerName;
137: }
138:
139: /**
140: * @param providerName The providerName to set.
141: */
142: public void setProviderName(String providerName) {
143: this .providerName = providerName;
144: }
145:
146: /**
147: * @see org.apache.jetspeed.security.AuthenticationProvider#getCredentialHandler()
148: */
149: public CredentialHandler getCredentialHandler() {
150: return this .credHandler;
151: }
152:
153: /**
154: * @see org.apache.jetspeed.security.AuthenticationProvider#getUserSecurityHandler()
155: */
156: public UserSecurityHandler getUserSecurityHandler() {
157: return this .userSecurityHandler;
158: }
159:
160: /**
161: * @see org.apache.jetspeed.security.AuthenticationProvider#setCredentialHandler(CredentialHandler)
162: */
163: public void setCredentialHandler(CredentialHandler credHandler) {
164: this .credHandler = credHandler;
165: }
166:
167: /**
168: * @see org.apache.jetspeed.security.AuthenticationProvider#setUserSecurityHandler(UserSecurityHandler)
169: */
170: public void setUserSecurityHandler(
171: UserSecurityHandler userSecurityHandler) {
172: this.userSecurityHandler = userSecurityHandler;
173: }
174: }
|