001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portal.spi;
020:
021: import java.rmi.RemoteException;
022: import java.util.Map;
023: import java.util.Vector;
024:
025: import javax.security.auth.login.LoginException;
026:
027: import com.nabhinc.spi.AuthenticationService;
028: import com.nabhinc.spi.LocalUserInfo;
029: import com.nabhinc.util.StringUtil;
030: import com.nabhinc.ws.service.core.BaseJavaWebService;
031:
032: /**
033: *
034: *
035: * @author Padmanabh Dabke
036: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
037: */
038: public class ChainedAuthenticationService extends BaseJavaWebService
039: implements AuthenticationService {
040: private String casServiceURLs = null;
041: private transient AuthenticationService[] casServices = null;
042:
043: public String getServiceURLs() {
044: return casServiceURLs;
045: }
046:
047: public void setServiceURLs(String urls) throws RemoteException {
048: casServiceURLs = urls;
049: String[] urlArray = StringUtil.split(urls, ",");
050: casServices = new AuthenticationService[urlArray.length];
051: for (int i = 0; i < urlArray.length; i++) {
052: casServices[i] = AuthenticationServiceLocator
053: .getAuthenticationService(urlArray[i]);
054: if (casServices[i] == null) {
055: throw new RemoteException("Service not found: "
056: + urlArray[i]);
057: }
058: }
059: }
060:
061: @SuppressWarnings("unchecked")
062: public LocalUserInfo authenticateUserByName(String userName,
063: String password, Map paramMap) throws LoginException,
064: RemoteException {
065: LocalUserInfo userInfo = casServices[0].authenticateUserByName(
066: userName, password, paramMap);
067: if (userInfo == null)
068: userInfo = new LocalUserInfo();
069: Vector allRoles = new Vector();
070: if (userInfo.roles != null) {
071: for (int i = 0; i < userInfo.roles.length; i++) {
072: allRoles.add(userInfo.roles[i]);
073: }
074: }
075: for (int i = 1; i < casServices.length; i++) {
076: LocalUserInfo currentUserInfo = casServices[i]
077: .authenticateUserByName(userName, password,
078: paramMap);
079: if (currentUserInfo != null) {
080: if (userInfo.principal == null)
081: userInfo.principal = currentUserInfo.principal;
082: if (userInfo.userName == null)
083: userInfo.userName = currentUserInfo.userName;
084:
085: if (currentUserInfo.roles != null) {
086: for (int j = 0; j < currentUserInfo.roles.length; j++) {
087: allRoles.add(currentUserInfo.roles[j]);
088: }
089: }
090: }
091: }
092: userInfo.roles = new String[allRoles.size()];
093: allRoles.copyInto(userInfo.roles);
094: return userInfo;
095: }
096:
097: @SuppressWarnings("unchecked")
098: public LocalUserInfo authenticateUserByEmail(String userEmail,
099: String password, Map paramMap) throws LoginException,
100: RemoteException {
101: LocalUserInfo userInfo = casServices[0]
102: .authenticateUserByEmail(userEmail, password, paramMap);
103: if (userInfo == null)
104: userInfo = new LocalUserInfo();
105: Vector allRoles = new Vector();
106: if (userInfo.roles != null) {
107: for (int i = 0; i < userInfo.roles.length; i++) {
108: allRoles.add(userInfo.roles[i]);
109: }
110: }
111: for (int i = 1; i < casServices.length; i++) {
112: LocalUserInfo currentUserInfo = casServices[i]
113: .authenticateUserByEmail(userEmail, password,
114: paramMap);
115: if (currentUserInfo != null) {
116: if (userInfo.principal == null)
117: userInfo.principal = currentUserInfo.principal;
118: if (userInfo.userName == null)
119: userInfo.userName = currentUserInfo.userName;
120:
121: if (currentUserInfo.roles != null) {
122: for (int j = 0; j < currentUserInfo.roles.length; j++) {
123: allRoles.add(currentUserInfo.roles[j]);
124: }
125: }
126: }
127: }
128: userInfo.roles = new String[allRoles.size()];
129: allRoles.copyInto(userInfo.roles);
130: return userInfo;
131: }
132:
133: }
|