001: /**
002: * $Id: EnableServices.java,v 1.24 2007/01/26 03:48:32 portalbld Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.fabric.tasks;
014:
015: import java.io.File;
016: import java.io.FileWriter;
017: import java.io.BufferedWriter;
018: import java.io.PrintWriter;
019: import java.io.FileInputStream;
020:
021: import java.util.List;
022: import java.util.ArrayList;
023: import java.util.Properties;
024: import java.util.logging.Level;
025: import java.util.logging.Logger;
026:
027: import com.sun.portal.admin.common.Tags;
028: import com.sun.portal.admin.common.context.PSConfigContext;
029: import com.sun.portal.admin.common.PSConfigConstants;
030: import com.sun.portal.fabric.util.AMTaskUtil;
031: import com.sun.portal.fabric.util.FileUtil;
032: import com.sun.portal.log.common.PortalLogger;
033: import com.sun.portal.util.Platform;
034:
035: /**
036: * Provides the functionality needed for configuring
037: * a Portal on a host.
038: *
039: */
040: public class EnableServices {
041:
042: /**
043: * The directory where the original service request files are located
044: */
045: private String psRequestLoc;
046:
047: /**
048: * The directory where the tagswapped service and request xmls are located
049: */
050: private String psTmpDir;
051:
052: /**
053: * The DN of the super user amadmin
054: */
055: private String amAdminDN;
056:
057: /**
058: * Logger instance
059: */
060: private static Logger logger = PortalLogger
061: .getLogger(EnableServices.class);
062:
063: /**
064: * Properties object that holds the request file configuration info
065: */
066: private Properties requestConfig;
067:
068: /**
069: * AMTaskUtil that will be used for invoking the request XMLs
070: */
071: private AMTaskUtil atu;
072:
073: /**
074: * IS basedir
075: */
076: private String isBaseDir;
077:
078: private String fcURL;
079:
080: private String nonAuthURL;
081:
082: /**
083: * File separator
084: */
085: public final static String fs = Platform.fs;
086:
087: /**
088: * Constructor
089: *
090: * @param psDataDir Location of the data directory for Portal Server as
091: String
092: * @param logger Logger object used for logging exceptions and events
093: * @param psBaseDir Portal Server installation directory path
094: * @param isBaseDir Identity Server SDK installation directory path
095: */
096: public EnableServices(PSConfigContext cc, String amAdminPassword) {
097:
098: String psBaseDir = cc.getPSBaseDir();
099: String psDataDir = cc.getPSDataDir();
100: this .isBaseDir = cc.getISBaseDir();
101: this .amAdminDN = cc.getAdminUserDN();
102:
103: this .amAdminDN = amAdminDN;
104: this .isBaseDir = isBaseDir;
105: psRequestLoc = psBaseDir + fs + "export" + fs + "request";
106: psTmpDir = psDataDir + fs + "tmp";
107:
108: // Load the property file that defines the set AM requests
109: logger.log(Level.FINEST, "PSFB_CSPFT0234");
110: String reqConfigPath = psBaseDir + fs + "lib" + fs
111: + PSConfigConstants.PS_AM_CONFIG_REQUESTS_FILE;
112: requestConfig = new Properties();
113:
114: try {
115: // Load the property file
116: requestConfig.load(new FileInputStream(reqConfigPath));
117: } catch (Exception e) {
118: logger.log(Level.SEVERE, "PSFB_CSPFT0235", e);
119: }
120:
121: // Create an instance of AMTaskUtil to load service and req
122: atu = new AMTaskUtil(isBaseDir, amAdminDN, amAdminPassword);
123:
124: }
125:
126: private List getRequestFileList(String type) {
127:
128: // Get the value of the property that defines the list of
129: // AM Request XMLs that should be invoked for the type of configuration
130: String requestString = requestConfig.getProperty(type, "");
131: requestString.trim();
132:
133: // The value of the requestString string is a space separated string
134: // of request file names. Create a tokenizer to tokenize the string into
135: // individual request file names
136: String[] reqTokenzr = null;
137: if (requestString.length() > 0) {
138: reqTokenzr = requestString.split("[\\s]+");
139: }
140: int iSize0 = (reqTokenzr != null) ? reqTokenzr.length : 0;
141:
142: // Initialize a Set stores request XML Paths
143: List requestPaths = new ArrayList();
144: for (int i = 0; i < iSize0; i++) {
145: // Get the request filename. The file extension is expected to
146: // be "request"
147: String requestFilePath = psRequestLoc + fs + reqTokenzr[i];
148: requestPaths.add(requestFilePath);
149: }
150:
151: return requestPaths;
152: }
153:
154: public void domainServices(String orgDN) {
155:
156: // String array of Tokens that needs to be replaced
157: String[] tokens = { Tags.ORG_DN, Tags.ADMIN_DN };
158: // String array of the values for the tokens
159: // TODO - Do not hardcode uid
160: String[] values = { orgDN, amAdminDN };
161:
162: List requestPaths = getRequestFileList("DomainSvcConfigRequests");
163:
164: logger.log(Level.FINEST, "PSFB_CSPFT0236", orgDN);
165: // Load the requests using the AMTaskUtils
166: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
167:
168: }
169:
170: public void unConfigdomainServices(String orgDN,
171: String UserNamingAttr) {
172:
173: // String array of Tokens that needs to be replaced
174: String[] tokens = { Tags.ORG_DN, Tags.IDSAME_USER_NAMING };
175: // String array of the values for the tokens
176: // TODO - Do not hardcode uid
177: String[] values = { orgDN, UserNamingAttr };
178:
179: List requestPaths = getRequestFileList("DomainSvcUnconfigRequests");
180:
181: logger.log(Level.FINEST, "PSFB_CSPFT0237", orgDN);
182: // remove the requests using the AMTaskUtils
183: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
184:
185: }
186:
187: public void unConfigSRAServices(String orgDN, String UserNamingAttr) {
188:
189: // String array of Tokens that needs to be replaced
190: String[] tokens = { Tags.ORG_DN, Tags.IDSAME_USER_NAMING };
191: // String array of the values for the tokens
192: // TODO - Do not hardcode uid
193: String[] values = { orgDN, UserNamingAttr };
194:
195: List requestPaths = getRequestFileList("DomainSRASvcUnconfigRequests");
196:
197: logger.log(Level.FINEST, "PSFB_CSPFT0237", orgDN);
198: // remove the requests using the AMTaskUtils
199: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
200:
201: }
202:
203: public void portalServices(String portalID, String orgDN,
204: String UserNamingAttr) {
205:
206: // String array of Tokens that needs to be replaced
207: String[] tokens = { Tags.PORTAL_ID, Tags.ORG_DN,
208: Tags.IDSAME_USER_NAMING, Tags.ADMIN_DN };
209: // String array of the values for the tokens
210: String[] values = { portalID, orgDN, UserNamingAttr, amAdminDN };
211:
212: List requestPaths = getRequestFileList("PortalSvcConfigRequests");
213:
214: logger.log(Level.FINEST, "PSFB_CSPFT0238", orgDN);
215: // Load the requests using the AMTaskUtils
216: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
217: }
218:
219: public void unconfigPortalRequests(String portalID, String orgDN,
220: String UserNamingAttr) {
221:
222: // String array of Tokens that needs to be replaced
223: String[] tokens = { Tags.PORTAL_ID, Tags.ORG_DN,
224: Tags.IDSAME_USER_NAMING, Tags.ADMIN_DN };
225: // String array of the values for the tokens
226: String[] values = { portalID, orgDN, UserNamingAttr, amAdminDN };
227:
228: List requestPaths = getRequestFileList("PortalSvcUnconfigRequests");
229:
230: logger.log(Level.FINEST, "PSFB_CSPFT0239", orgDN);
231: // Load the requests using the AMTaskUtils
232: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
233: }
234:
235: public void sraServices(String orgDN, String sraServerDomain,
236: String gwProtocol, String gwPort, String sraGWProfile,
237: String sraLogUserPassword, String isConsoleURI,
238: String isServerURI, String peopleDN, String portalAccessURI) {
239:
240: String enableEproxy, eproxyPort, enableRproxy, rproxyPort;
241: if ("https".equalsIgnoreCase(gwProtocol)) {
242: enableEproxy = "true";
243: eproxyPort = gwPort;
244: enableRproxy = "false";
245: rproxyPort = "80"; // default HTTP port
246: } else {
247: enableEproxy = "false";
248: eproxyPort = "443"; // default HTTPS port
249: enableRproxy = "true";
250: rproxyPort = gwPort;
251: }
252:
253: replaceFCNonAuth();
254:
255: // String array of Tokens that needs to be replaced
256: String[] tokens = { Tags.INST_FCURLS,
257: Tags.INST_IS_NONAUTH_URLS, Tags.ORG_DN,
258: Tags.IDSAME_AMCONSOLE, Tags.SRA_SERVER_DOMAIN,
259: Tags.IDSAME_AMSERVER, Tags.INST_ENABLE_EPROXY,
260: Tags.INST_ENABLE_RPROXY, Tags.INST_EPROXY_PORT,
261: Tags.INST_GWNAME, Tags.INST_RPROXY_PORT,
262: Tags.INST_USE_PROXY, Tags.ADMIN_DN, Tags.PEOPLE_DN,
263: Tags.SRA_LOG_USER_PASSWORD, Tags.INST_PS_SERVER_LIST };
264:
265: // String array of the values for the tokens
266: String[] values = { fcURL, nonAuthURL, orgDN, isConsoleURI,
267: sraServerDomain, isServerURI, enableEproxy,
268: enableRproxy, eproxyPort, sraGWProfile, rproxyPort,
269: "n", amAdminDN, peopleDN, sraLogUserPassword,
270: portalAccessURI };
271:
272: List requestPaths = getRequestFileList("DomainSRASvcConfigRequests");
273:
274: logger.log(Level.FINEST, "PSFB_CSPFT0240", orgDN);
275: // Load the requests using the AMTaskUtils
276: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
277: }
278:
279: public void postInstallRequests(String orgDN, String successLoginURL) {
280:
281: // String array of Tokens that needs to be replaced
282: String[] tokens = { Tags.LOGIN_URL, Tags.ORG_DN };
283: // String array of the values for the tokens
284:
285: String[] values = { successLoginURL, orgDN };
286:
287: List requestPaths = getRequestFileList("PostInstallRequests");
288:
289: logger.log(Level.FINEST, "PSFB_CSPFT0241", successLoginURL);
290: // Load the requests using the AMTaskUtils
291: atu.processRequestXML(tokens, values, requestPaths, psTmpDir);
292: }
293:
294: private void replaceFCNonAuth() {
295:
296: String requestFileName = "srapGatewayConfig.request";
297: File origRequestFile = new File(psRequestLoc + fs
298: + requestFileName);
299: if (origRequestFile.exists()) {
300: String serverList = getServerList();
301: String[] amServerURLs = new String[] {
302: "%IDSAME_AMSERVER%" + "/images",
303: "%IDSAME_AMSERVER%" + "/login_images",
304: "%IDSAME_AMSERVER%" + "/js",
305: "%IDSAME_AMSERVER%" + "/css" };
306: String[] amConsoleURLs = new String[] {
307: "%IDSAME_AMCONSOLE%" + "/console/images",
308: "%IDSAME_AMCONSOLE%" + "/console/css",
309: "%IDSAME_AMCONSOLE%" + "/console/js" };
310:
311: StringBuffer nonAuthURLs = new StringBuffer();
312: for (int i = 0; i < amServerURLs.length; i++) {
313: nonAuthURLs.append(" " + "<Value>" + serverList
314: + amServerURLs[i] + "</Value>");
315: }
316: for (int i = 0; i < amConsoleURLs.length; i++) {
317: nonAuthURLs.append(" " + "<Value>" + serverList
318: + amConsoleURLs[i] + "</Value>");
319: }
320: StringBuffer fcURLList = new StringBuffer();
321: fcURLList.append(" " + "<Value>" + serverList + "</Value>");
322: int endIndx = serverList.indexOf("://");
323: String protocol = serverList.substring(0, endIndx);
324: int beginIndx = serverList.indexOf("://");
325: int endIndx1 = serverList.substring(beginIndx + 3).indexOf(
326: ":");
327: if (endIndx1 == -1) {
328: endIndx1 = serverList.substring(beginIndx + 3).indexOf(
329: "/");
330: }
331: String host = serverList.substring(beginIndx + 3, beginIndx
332: + endIndx1 + 3);
333: String port = null;
334: int beginIndx1 = serverList.substring(beginIndx + 3)
335: .indexOf(":");
336: if (beginIndx1 == -1) {
337: port = "80";
338: } else {
339: port = serverList.substring(beginIndx + beginIndx1 + 4);
340: }
341: if (port.equals("80") || port.equals("443")) {
342: fcURLList.append("<Value>" + protocol + "://" + host
343: + "</Value>");
344: }
345:
346: fcURL = fcURLList.toString();
347:
348: nonAuthURL = nonAuthURLs.toString();
349:
350: }
351: }
352:
353: private String getServerList() {
354: String isServerList = null;
355: try {
356: File file = File.createTempFile("platformList", ".xml");
357: FileWriter fw = new FileWriter(file);
358: fw
359: .write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
360: fw
361: .write("<!DOCTYPE Requests SYSTEM \"jar://com/iplanet/am/admin/cli/amAdmin.dtd\">\n");
362: fw.write("<Requests>\n");
363: fw
364: .write(" <SchemaRequests serviceName=\"iPlanetAMPlatformService\" SchemaType=\"global\">\n");
365: fw.write(" <GetServiceDefaultValues>\n");
366: fw
367: .write(" <Attribute name=\"iplanet-am-platform-server-list\" />\n");
368: fw.write(" </GetServiceDefaultValues>\n");
369: fw.write(" </SchemaRequests>\n");
370: fw.write("</Requests>\n");
371: fw.close();
372: // Load the requests using the AMTaskUtils
373: List paths = new ArrayList();
374: paths.add(file.getAbsolutePath());
375: String out = atu.execAMRequest(paths);
376: out.trim();
377: String[] tokens = null;
378: if (out.length() > 0) {
379: tokens = out.split("\n");
380: }
381: int iSize0 = (tokens != null) ? tokens.length : 0;
382: String answer = null;
383: for (int i = 0; i < iSize0; i++) {
384: String token = tokens[i];
385: if (token.indexOf("iplanet-am-platform-server-list") >= 0) {
386: answer = token.substring(token.indexOf("=") + 1);
387: answer = answer.trim();
388: break;
389: }
390: }
391: if (answer != null && answer.trim().length() != 0) {
392: isServerList = answer.substring(
393: answer.indexOf("[") + 1, answer.indexOf("|"));
394: }
395: file.delete();
396:
397: } catch (Exception e) {
398: logger.log(Level.SEVERE, "PSFB_CSPFT0242", e);
399: }
400: return isServerList;
401: }
402: }
|