001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.security.jaas;
022:
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: import javax.security.auth.login.AppConfigurationEntry;
027: import javax.security.auth.login.Configuration;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031:
032: /**
033: * <a href="PortalConfiguration.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Michael Weisser
036: * @author Brian Wing Shun Chan
037: *
038: */
039: public class PortalConfiguration extends Configuration {
040:
041: public static final String REALM_NAME = "PortalRealm";
042:
043: public static final String JBOSS_LOGIN_MODULE = "client-login";
044:
045: public PortalConfiguration(Configuration config) {
046: _config = config;
047: }
048:
049: public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
050: AppConfigurationEntry[] aceArray = _config
051: .getAppConfigurationEntry(name);
052:
053: if ((name != null) && !name.equals(JBOSS_LOGIN_MODULE)) {
054: if (_log.isDebugEnabled()) {
055: _log.debug(name);
056: }
057:
058: Map options = null;
059:
060: if (aceArray == null || aceArray.length == 0) {
061: options = new HashMap();
062: } else {
063: options = aceArray[0].getOptions();
064: }
065:
066: AppConfigurationEntry ace = new AppConfigurationEntry(
067: com.liferay.portal.kernel.security.jaas.PortalLoginModule.class
068: .getName(),
069: AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
070: options);
071:
072: if (aceArray == null || aceArray.length == 0) {
073: aceArray = new AppConfigurationEntry[] { ace };
074: } else {
075: AppConfigurationEntry[] newAceArray = new AppConfigurationEntry[aceArray.length + 1];
076:
077: if (name.equals(REALM_NAME)) {
078: newAceArray[0] = ace;
079:
080: System.arraycopy(aceArray, 0, newAceArray, 1,
081: aceArray.length);
082: } else {
083: newAceArray[aceArray.length] = ace;
084:
085: System.arraycopy(aceArray, 0, newAceArray, 0,
086: aceArray.length);
087: }
088:
089: aceArray = newAceArray;
090:
091: for (int i = 0; i < newAceArray.length; i++) {
092: if (newAceArray[i]
093: .getControlFlag()
094: .equals(
095: AppConfigurationEntry.LoginModuleControlFlag.REQUIRED)) {
096:
097: newAceArray[i] = new AppConfigurationEntry(
098: newAceArray[i].getLoginModuleName(),
099: AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT,
100: newAceArray[i].getOptions());
101: }
102:
103: if (_log.isDebugEnabled()) {
104: _log
105: .debug(newAceArray[i]
106: .getLoginModuleName()
107: + " "
108: + newAceArray[i]
109: .getControlFlag());
110: }
111: }
112: }
113: }
114:
115: return aceArray;
116: }
117:
118: public void refresh() {
119: _config.refresh();
120: }
121:
122: private static Log _log = LogFactory
123: .getLog(PortalConfiguration.class);
124:
125: private Configuration _config = null;
126:
127: }
|