0001: /**
0002: * Copyright 2003 Sun Microsystems, Inc. All
0003: * rights reserved. Use of this product is subject
0004: * to license terms. Federal Acquisitions:
0005: * Commercial Software -- Government Users
0006: * Subject to Standard License Terms and
0007: * Conditions.
0008: *
0009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010: * are trademarks or registered trademarks of Sun Microsystems,
0011: * Inc. in the United States and other countries.
0012: */package com.sun.portal.wsrp.consumer.producermanager.impl;
0013:
0014: import java.util.Set;
0015: import java.util.Map;
0016: import java.util.List;
0017: import java.util.ArrayList;
0018:
0019: import java.util.HashSet;
0020: import java.util.HashMap;
0021: import java.util.Iterator;
0022: import java.util.Collections;
0023: import java.util.ResourceBundle;
0024: import java.util.PropertyResourceBundle;
0025: import java.util.logging.Level;
0026: import java.util.logging.Logger;
0027:
0028: import java.net.URL;
0029: import java.net.MalformedURLException;
0030:
0031: import javax.servlet.http.HttpServletRequest;
0032:
0033: import java.rmi.RemoteException;
0034:
0035: import com.iplanet.sso.SSOTokenManager;
0036: import com.iplanet.sso.SSOToken;
0037: import com.iplanet.sso.SSOException;
0038:
0039: import com.sun.identity.policy.PolicyEvaluator;
0040: import com.sun.identity.policy.PolicyException;
0041: import com.sun.identity.policy.NameNotFoundException;
0042:
0043: import com.iplanet.am.sdk.AMConstants;
0044: import com.iplanet.am.sdk.AMStoreConnection;
0045: import com.iplanet.am.sdk.AMOrganization;
0046: import com.iplanet.am.sdk.AMOrganizationalUnit;
0047: import com.iplanet.am.sdk.AMTemplate;
0048: import com.iplanet.am.sdk.AMException;
0049:
0050: import com.sun.identity.sm.ServiceSchema;
0051: import com.sun.identity.sm.ServiceSchemaManager;
0052: import com.sun.identity.sm.SMSException;
0053: import com.sun.identity.sm.ServiceListener;
0054: import com.sun.identity.sm.ServiceConfigManager;
0055:
0056: import com.sun.portal.desktop.context.DesktopAppContext;
0057: import com.sun.portal.desktop.context.DesktopAppContextThreadLocalizer;
0058: import com.sun.portal.desktop.context.ConfigContext;
0059:
0060: import com.sun.portal.wsrp.WSRPException;
0061:
0062: import com.sun.portal.wsrp.common.stubs.WSRP_v1_ServiceDescription_PortType;
0063: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Registration_PortType;
0064:
0065: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
0066: import com.sun.portal.wsrp.common.stubs.GetServiceDescription;
0067: import com.sun.portal.wsrp.common.stubs.RegistrationContext;
0068: import com.sun.portal.wsrp.common.stubs.RegistrationData;
0069: import com.sun.portal.wsrp.common.stubs.RegistrationState;
0070: import com.sun.portal.wsrp.common.stubs.ModifyRegistration;
0071: import com.sun.portal.wsrp.common.stubs.ReturnAny;
0072:
0073: import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
0074: import com.sun.portal.wsrp.common.stubs.InvalidRegistrationFault;
0075: import com.sun.portal.wsrp.common.stubs.MissingParametersFault;
0076:
0077: import com.sun.portal.wsrp.common.WSRPFactory;
0078: import com.sun.portal.wsrp.common.KeyGenerator;
0079: import com.sun.portal.wsrp.common.Timer;
0080: import com.sun.portal.wsrp.common.IdentityPropagationConstants;
0081:
0082: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
0083: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManagerFactory;
0084: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManager;
0085:
0086: import com.sun.portal.wsrp.consumer.producermanager.ConsumerObjectFactory;
0087: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
0088: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
0089: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityStatus;
0090: import com.sun.portal.wsrp.consumer.producermanager.InbandRegistrationNotSupportedException;
0091: import com.sun.portal.log.common.PortalLogger;
0092: import com.sun.portal.util.SSOUtil;
0093:
0094: // private class from jax-rpm need to remove when
0095: // other refrence of jax-rpc WSDL parser refrences are removed
0096: import com.sun.xml.rpc.wsdl.framework.ParseException;
0097:
0098: /**
0099: * An implementation of the <code>ProducerEntityManager</code> interface
0100: * using Identity Server as a persistent data storage.
0101: */
0102: public class ProducerEntityManagerImpl implements
0103: ProducerEntityManager, ISConstants {
0104:
0105: //
0106: // debug
0107: //
0108: //
0109: // cache of producer entities (key = producerEntityId)
0110: // we use synchronized map.
0111: // make sure you synchronize properly when interating over it.
0112: //
0113: private static Map producerEntities = Collections
0114: .synchronizedMap(new HashMap());
0115:
0116: //
0117: // IS Admin ssoToken
0118: // lazy instantiation. use getAdminSSOToken() to get a handle.
0119: //
0120: private static SSOToken adminSSOToken = null;
0121:
0122: //
0123: // IS Admin connection
0124: // lazy instantiation. use getAdminConnection() to get a handle.
0125: // lazy instantiation. use getAdminConnection() to get a handle.
0126: //
0127: private static AMStoreConnection adminConnection = null;
0128:
0129: //
0130: // IS Schema manager
0131: // lazy instantiation. use getServiceSchemaManager() to get a handle.
0132: //
0133: private static ServiceSchemaManager serviceSchemaMgr = null;
0134:
0135: //
0136: // config context to get portal id
0137: //
0138: private static ConfigContext configContext = null;
0139:
0140: //
0141: // portal id
0142: // init'd by init() method
0143: //
0144: protected static String portalId = null;
0145:
0146: //
0147: // wsrp object factory
0148: // lazy instantiation. use getWSRPFactory() to get a handle.
0149: //
0150: protected static WSRPFactory factory = null;
0151:
0152: //
0153: // consumer object factory
0154: // lazy instantiation. use getConsumerObjectFactory() to get a handle.
0155: //
0156: protected static ConsumerObjectFactory cofactory = null;
0157:
0158: //
0159: // consumer agent
0160: // lazy instantiation. use getConsumerAgent() to get a handle.
0161: //
0162: protected static String consumerAgent = null;
0163:
0164: //
0165: // stub manager
0166: // init'd by init() method
0167: //
0168: protected static RemoteServiceStubManager stubMgr = null;
0169:
0170: //
0171: // IS user connection
0172: // init'd by init() method
0173: //
0174: protected AMStoreConnection userConnection = null;
0175:
0176: //
0177: // SSOToken for the current user
0178: // init'd by init() method
0179: //
0180: protected SSOToken ssoToken = null;
0181:
0182: //
0183: // dn of the consumer organization node
0184: // init'd by init() method
0185: //
0186: protected String consumerOrgDN = null;
0187:
0188: protected Set serviceNames = null;
0189:
0190: private static Map organizationServiceNameMap = new HashMap();
0191:
0192: private static Logger logger = PortalLogger
0193: .getLogger(ProducerEntityManagerImpl.class);
0194:
0195: private static ServiceListener orgChangeListener = new ServiceListener() {
0196:
0197: public void schemaChanged(String serviceName, String version) {
0198:
0199: }
0200:
0201: public void globalConfigChanged(String serviceName,
0202: String version, String groupName,
0203: String serviceComponent, int type) {
0204: }
0205:
0206: public void organizationConfigChanged(String serviceName,
0207: String version, String orgName, String groupName,
0208: String serviceComponent, int type) {
0209: // Clear the cache
0210: organizationServiceNameMap.clear();
0211: }
0212: };
0213:
0214: private static ServiceConfigManager serviceConfigManager = null;
0215:
0216: public ProducerEntityManagerImpl() {
0217:
0218: }
0219:
0220: public void init(String consumerId, HttpServletRequest request)
0221: throws WSRPConsumerException {
0222:
0223: //
0224: // first determine if the request comes from an authless
0225: // anonymous session. if so use admin ssotoken.
0226: //
0227: DesktopAppContext appContext = DesktopAppContextThreadLocalizer
0228: .get();
0229: if (appContext.isAuthless(request)) {
0230: ssoToken = getAdminSSOToken();
0231: } else {
0232: SSOTokenManager ssoTokenMgr = null;
0233: try {
0234: ssoTokenMgr = SSOTokenManager.getInstance();
0235: ssoToken = ssoTokenMgr.createSSOToken(request);
0236: } catch (SSOException se) {
0237: throw new WSRPConsumerException(
0238: "ProducerEntityManagerImpl.init(): failed to create ssoToken.",
0239: se);
0240: }
0241: }
0242:
0243: doInit(consumerId);
0244: }
0245:
0246: public void init(String consumerId, final String username,
0247: String password) throws WSRPConsumerException {
0248: //SSOTokenManager ssoTokenMgr = null;
0249: try {
0250: //FOLLOWING IS COMMENTED TO FIX CR 6273650
0251: /*
0252: ssoTokenMgr = SSOTokenManager.getInstance();
0253: ssoToken = ssoTokenMgr.createSSOToken(
0254: new java.security.Principal() {
0255: public String getName() { return username; }
0256: }, password);
0257: */
0258: //FOLLOWING IS REPLACEMENT OF ABOVE CALL
0259: ssoToken = SSOUtil.createSSOToken(username, password);
0260: } catch (SSOException se) {
0261: throw new WSRPConsumerException(
0262: "ProducerEntityManagerImpl.init(): failed to create ssoToken.",
0263: se);
0264: }
0265: doInit(consumerId);
0266: }
0267:
0268: public void init(SSOToken ssoToken, String portalId,
0269: String consumerId) throws WSRPConsumerException {
0270:
0271: this .ssoToken = ssoToken;
0272: this .portalId = portalId;
0273:
0274: doInit(consumerId);
0275: }
0276:
0277: private void doInit(String consumerId) throws WSRPConsumerException {
0278:
0279: if (serviceConfigManager == null) {
0280: try {
0281: serviceConfigManager = new ServiceConfigManager(
0282: getAdminSSOToken(),
0283: ISConsumerMultiPortalConstants
0284: .getInstance(portalId).MP_SERVICE_WSRP_CONSUMER,
0285: SERVICE_WSRP_CONSUMER_VERSION);
0286: serviceConfigManager.addListener(orgChangeListener);
0287: } catch (SSOException se) {
0288: throw new WSRPConsumerException(
0289: "ProducerEntityManagerImpl.doInit(): ", se);
0290: } catch (SMSException sme) {
0291: throw new WSRPConsumerException(
0292: "ProducerEntityManagerImpl.doInit(): ", sme);
0293: }
0294: }
0295: //
0296: // get remote service stub manager
0297: //
0298: stubMgr = RemoteServiceStubManagerFactory
0299: .getRemoteServiceStubManager();
0300:
0301: //
0302: // initialize IS-related objects
0303: //
0304: consumerOrgDN = consumerId;
0305: //serviceNames = null;
0306: try {
0307: userConnection = new AMStoreConnection(ssoToken);
0308: } catch (SSOException se) {
0309: throw new WSRPConsumerException(
0310: "ProducerEntityManagerImpl.doInit():", se);
0311: }
0312:
0313: //
0314: // security check: does the user belong to the node where he/she can
0315: // access the given consumer node?
0316: //
0317: if (!isAccessible()) {
0318: throw new WSRPConsumerException(
0319: "ProducerEntityManagerImpl.doInit(): security violation. user does not have access to the given consumer. dn="
0320: + consumerOrgDN);
0321: }
0322:
0323: //
0324: // TBD: this should really be triggered by the amconsole
0325: // when template is created. pem should make an assumption
0326: // that cou already exists - otherwise, error out.
0327: //
0328: if (!existsConsumerOU()) {
0329: createConsumerOU();
0330: }
0331: }
0332:
0333: public boolean isActivated() throws WSRPConsumerException {
0334:
0335: Timer t = new Timer();
0336:
0337: String serviceEnabled = getGlobalStringAttribute(ATTR_ISDISABLED);
0338:
0339: if (logger.isLoggable(Level.FINEST)) {
0340: String[] param = { "elapsed", "" + t.getElapsed() };
0341: logger.log(Level.FINEST, "PSWS_CSPWCPI0002", param);
0342: }
0343:
0344: return (!Boolean.valueOf(serviceEnabled).booleanValue());
0345: }
0346:
0347: protected boolean isAccessible() throws WSRPConsumerException {
0348: //
0349: // first perform a simple string comparison to determine if the user
0350: // belongs to the tree where he/she can access the consumer ou
0351: //
0352: boolean isAccessible = false;
0353: String userDN = null;
0354: try {
0355: userDN = ssoToken.getPrincipal().getName();
0356: } catch (SSOException ssoe) {
0357: throw new WSRPConsumerException(
0358: "ProducerEntityManagerImpl.isAccessible(): failed to extract user dn from the sso token.",
0359: ssoe);
0360: }
0361:
0362: if (userDN.endsWith(consumerOrgDN)) {
0363: isAccessible = true;
0364: } else {
0365: //
0366: // still check to see if the user can access the org.
0367: // this would ensure an admin access to other orgs that he/she
0368: // does not belong to
0369: //
0370: AMOrganization org = null;
0371: try {
0372: org = userConnection.getOrganization(consumerOrgDN);
0373: } catch (Exception ex) {
0374: //
0375: // must mean that the user cannot access the org
0376: // thus access denied.
0377: //
0378: isAccessible = false;
0379: }
0380: //
0381: // failed to retrieve org. must mean that he/she cannot access
0382: //
0383: isAccessible = (org != null);
0384: }
0385:
0386: return isAccessible;
0387: }
0388:
0389: public String getConsumerName() throws WSRPConsumerException {
0390: String consumerName = null;
0391: AMTemplate template = getOrganizationServiceTemplate(getAdminConnection());
0392:
0393: if (template != null) {
0394: try {
0395: consumerName = template
0396: .getStringAttribute(ATTR_CONSUMER_NAME);
0397: } catch (AMException ae) {
0398: throw new WSRPConsumerException(
0399: "ProducerEntityManagerImpl.getConsumerName(): failed to retrieve consumer name.",
0400: ae);
0401: } catch (SSOException se) {
0402: throw new WSRPConsumerException(
0403: "ProducerEntityManagerImpl.getConsumerName(): failed to retrieve consumer name.",
0404: se);
0405: }
0406: }
0407: return consumerName;
0408: }
0409:
0410: public ServiceDescription getServiceDescription(URL producerURL)
0411: throws WSRPConsumerException {
0412:
0413: //
0414: // no registration info supplied. pass null registrationContext
0415: //
0416: return getServiceDescription(producerURL, null);
0417: }
0418:
0419: public ServiceDescription getServiceDescription(URL producerURL,
0420: RegistrationContext regContext)
0421: throws WSRPConsumerException {
0422:
0423: String endpoint = stubMgr.getEndpoint(producerURL,
0424: stubMgr.SERVICE_DESCRIPTION_PORT_BINDING);
0425:
0426: WSRP_v1_ServiceDescription_PortType sdPort = stubMgr
0427: .getServiceDescriptionPortType(endpoint);
0428:
0429: //
0430: // we query all available locales
0431: // this may have a performance impact but since this is a
0432: // rarely used method, it's acceptable.
0433: //
0434: String[] locales = null;
0435: ServiceDescription sd = null;
0436: GetServiceDescription gsd = new GetServiceDescription(
0437: regContext, locales);
0438:
0439: try {
0440: sd = sdPort.getServiceDescription(gsd);
0441: } catch (OperationFailedFault off) {
0442: throw new WSRPConsumerException(
0443: "ProducerEntityManagerImpl.getServiceDescription(): failed to get service description. WSRP producer may be disabled. producerURL="
0444: + producerURL, off);
0445: } catch (InvalidRegistrationFault irf) {
0446: throw new WSRPConsumerException(
0447: "ProducerEntityManagerImpl.getServiceDescription(): failed to get service description. producerURL="
0448: + producerURL, irf);
0449: } catch (RemoteException re) {
0450: throw new WSRPConsumerException(
0451: "ProducerEntityManagerImpl.getServiceDescription(): failed to get service description. producerURL="
0452: + producerURL, re);
0453: }
0454:
0455: //
0456: // log it!
0457: //
0458: //if (sd != null && debug.isServiceDescLogEnabled()) {
0459: if (sd != null && logger.isLoggable(Level.FINEST)) {
0460: String sdXML = null;
0461: try {
0462: sdXML = getWSRPFactory().getServiceDescriptionXML(sd,
0463: true);
0464: } catch (WSRPException we) {
0465: throw new WSRPConsumerException(
0466: "ProducerEntityManagerImpl.getServiceDescription(): failed to serialize service description. sd="
0467: + sd, we);
0468: }
0469:
0470: StringBuffer logBuf = new StringBuffer();
0471: logBuf.append("PRODUCER_WSDL_URL=").append(producerURL);
0472: if (regContext != null) {
0473: logBuf.append("\nREG_HANDLE=").append(
0474: regContext.getRegistrationHandle());
0475: } else {
0476: logBuf.append("\nREG_HANDLE=<none>");
0477: }
0478:
0479: logBuf.append("\nSERVICE_DESCRIPTION=").append(sdXML);
0480:
0481: if (logger.isLoggable(Level.FINEST))
0482: logger.log(Level.FINEST, logBuf.toString());
0483: }
0484:
0485: return sd;
0486: }
0487:
0488: public boolean isInbandRegistrationSupported(URL producerURL)
0489: throws WSRPConsumerException {
0490:
0491: String endpoint = stubMgr.getEndpoint(producerURL,
0492: stubMgr.REGISTRATION_PORT_BINDING);
0493:
0494: WSRP_v1_Registration_PortType regPort = stubMgr
0495: .getRegistrationPortType(endpoint);
0496:
0497: return (regPort != null);
0498: }
0499:
0500: public ProducerEntity getProducerEntity(String producerEntityId)
0501: throws WSRPConsumerException {
0502:
0503: ProducerEntity pe = (ProducerEntity) producerEntities
0504: .get(producerEntityId);
0505:
0506: if (pe != null) {
0507: //
0508: // found existing producer entity in the cache
0509: // check to see if it's stale
0510: //
0511: String modified = getProducerEntityLastModified(producerEntityId);
0512: String cacheModified = pe.getLastModified();
0513: if (cacheModified.compareTo(modified) >= 0) {
0514: //debug.debugMessage("ProducerEntityManagerImpl.getProducerEntity(): retrieved PE from cache peId=" + producerEntityId);
0515: return pe;
0516: }
0517: }
0518:
0519: //
0520: // get a fresh one and add to cache
0521: //
0522: synchronized (producerEntities) {
0523: //
0524: // check again to see if we still need reload
0525: //
0526: pe = (ProducerEntity) producerEntities
0527: .get(producerEntityId);
0528:
0529: String modified = null;
0530: String cacheModified = null;
0531: if (pe != null) {
0532: modified = getProducerEntityLastModified(producerEntityId);
0533: cacheModified = pe.getLastModified();
0534: }
0535:
0536: if (pe == null || cacheModified.compareTo(modified) < 0) {
0537: pe = loadProducerEntity(producerEntityId);
0538: producerEntities.put(producerEntityId, pe);
0539: //debug.debugMessage("ProducerEntityManagerImpl.getProducerEntity(): retrieved PE from DB peId=" + producerEntityId);
0540: } else {
0541: //debug.debugMessage("ProducerEntityManagerImpl.getProducerEntity(): retrieved PE from cache peId=" + producerEntityId);
0542: }
0543: }
0544: return pe;
0545: }
0546:
0547: public String addProducerEntity(String producerName,
0548: URL producerURL, String identityPropagationType,
0549: RegistrationData regData, Map userCategories,
0550: Map allowedUserProfiles, Map customUserProfiles)
0551: throws WSRPConsumerException,
0552: InbandRegistrationNotSupportedException {
0553:
0554: // TBD: this method needs to be made atomic
0555:
0556: //
0557: // get service description
0558: //
0559: ServiceDescription serviceDesc = getServiceDescription(producerURL);
0560:
0561: //
0562: // if required, register at the producer end
0563: //
0564: RegistrationContext regContext = null;
0565: if (serviceDesc.isRequiresRegistration()) {
0566: String endpoint = stubMgr.getEndpoint(producerURL,
0567: stubMgr.REGISTRATION_PORT_BINDING);
0568:
0569: WSRP_v1_Registration_PortType regPort = stubMgr
0570: .getRegistrationPortType(endpoint);
0571:
0572: //
0573: // registration port is not exposed: i.e. in-band reg. not supported
0574: //
0575: if (regPort == null) {
0576: throw new InbandRegistrationNotSupportedException(
0577: "ProducerEntityManagerImpl.addProducerEntity(): registration port not available. producerURL="
0578: + producerURL);
0579: }
0580:
0581: try {
0582: regContext = regPort.register(regData);
0583: } catch (MissingParametersFault mpf) {
0584: throw new WSRPConsumerException(
0585: "ProducerEntityManagerImpl.addProducerEntity(): failed to register. producerURL="
0586: + producerURL + ", regData=" + regData,
0587: mpf);
0588: } catch (OperationFailedFault off) {
0589: throw new WSRPConsumerException(
0590: "ProducerEntityManagerImpl.addProducerEntity(): failed to register. producerURL="
0591: + producerURL + ", regData=" + regData,
0592: off);
0593: } catch (RemoteException re) {
0594: throw new WSRPConsumerException(
0595: "ProducerEntityManagerImpl.addProducerEntity(): failed to register. producerURL="
0596: + producerURL + ", regData=" + regData,
0597: re);
0598: }
0599:
0600: //
0601: // get service description again with registration context
0602: //
0603: serviceDesc = getServiceDescription(producerURL, regContext);
0604: }
0605:
0606: String producerEntityId = addProducerEntity(producerName,
0607: producerURL, regData, regContext, serviceDesc,
0608: userCategories, allowedUserProfiles,
0609: customUserProfiles, identityPropagationType);
0610:
0611: return producerEntityId;
0612: }
0613:
0614: public String addProducerEntity(String producerName,
0615: URL producerURL, String identityPropagationType,
0616: String regHandle, Map userCategories,
0617: Map allowedUserProfiles, Map customUserProfiles)
0618: throws WSRPConsumerException {
0619:
0620: // TBD: this method needs to be made atomic
0621:
0622: RegistrationContext regContext = new RegistrationContext(
0623: regHandle, null, null);
0624:
0625: ServiceDescription serviceDesc = getServiceDescription(
0626: producerURL, regContext);
0627:
0628: //
0629: // passing null for registration data
0630: //
0631: String producerEntityId = addProducerEntity(producerName,
0632: producerURL, null, regContext, serviceDesc,
0633: userCategories, allowedUserProfiles,
0634: customUserProfiles, identityPropagationType);
0635:
0636: return producerEntityId;
0637: }
0638:
0639: private String addProducerEntity(String producerName,
0640: URL producerURL, RegistrationData regData,
0641: RegistrationContext regContext,
0642: ServiceDescription serviceDesc, Map userCategories,
0643: Map allowedUserProfiles, Map customUserProfiles,
0644: String identityPropagationType)
0645: throws WSRPConsumerException {
0646:
0647: //
0648: // generate unique key for the producerEntityId
0649: //
0650: String producerEntityId = KeyGenerator.generateKey();
0651:
0652: //
0653: // get markup port type endpoint from wsdl
0654: //
0655: String markupEndpoint = stubMgr.getEndpoint(producerURL,
0656: stubMgr.MARKUP_PORT_BINDING);
0657:
0658: //
0659: // create producer entity obj
0660: //
0661: long now = System.currentTimeMillis();
0662: ProducerEntity pe = createProducerEntity(producerEntityId,
0663: producerName, producerURL, markupEndpoint,
0664: ProducerEntityStatus.OK, regData, regContext,
0665: serviceDesc, userCategories, allowedUserProfiles,
0666: customUserProfiles, now, Long.toString(now),
0667: identityPropagationType);
0668:
0669: //
0670: // persist producer entity
0671: //
0672: createProducerEntityOU(pe.getId());
0673: storeProducerEntity(pe);
0674:
0675: //
0676: // add to cache
0677: //
0678: synchronized (producerEntities) {
0679: producerEntities.put(pe.getId(), pe);
0680: }
0681:
0682: if (logger.isLoggable(Level.FINEST))
0683: logger.log(Level.FINEST, "PSWS_CSPWCPI0003");
0684:
0685: return pe.getId();
0686: }
0687:
0688: public void updateServiceDescription(String producerEntityId)
0689: throws WSRPConsumerException {
0690:
0691: ProducerEntity pe = getProducerEntity(producerEntityId);
0692: if (pe == null) {
0693: throw new WSRPConsumerException(
0694: "ProducerEntityManagerImpl.updateServiceDescription(): invalid producer entity id. peId="
0695: + producerEntityId);
0696: }
0697:
0698: URL producerURL = pe.getURL();
0699: RegistrationContext rc = pe.getRegistrationContext();
0700:
0701: //
0702: // get fresh service description
0703: //
0704: ServiceDescription sd = getServiceDescription(producerURL, rc);
0705:
0706: //
0707: // update IS
0708: //
0709: String sdXML = null;
0710: if (sd != null) {
0711: try {
0712: sdXML = getWSRPFactory().getServiceDescriptionXML(sd);
0713: } catch (WSRPException we) {
0714: throw new WSRPConsumerException(
0715: "ProducerEntityManagerImpl.storeProducerEntity(): failed to serialize service description. sd="
0716: + sd, we);
0717: }
0718: }
0719:
0720: AMOrganizationalUnit peou = getProducerEntityOU(
0721: producerEntityId, userConnection);
0722: if (peou == null) {
0723: throw new WSRPConsumerException(
0724: "ProducerEntityManagerImpl.updateServiceDescription(): invalid producerEntityId="
0725: + producerEntityId);
0726: }
0727:
0728: try {
0729: peou.setStringAttribute(ATTR_SERVICE_DESCRIPTION, sdXML);
0730: peou.setStringAttribute(
0731: ATTR_SERVICE_DESCRIPTION_LAST_MODIFIED, Long
0732: .toString(System.currentTimeMillis()));
0733: peou.store();
0734:
0735: } catch (AMException ae) {
0736: throw new WSRPConsumerException(
0737: "ProducerEntityManagerImpl.updateServiceDescription(): failed to persist producer entity. producerEntityId="
0738: + producerEntityId, ae);
0739: } catch (SSOException se) {
0740: throw new WSRPConsumerException(
0741: "ProducerEntityManagerImpl.updateServiceDescription(): failed to persist producer entity. producerEntityId="
0742: + producerEntityId, se);
0743: }
0744:
0745: //
0746: // update cache by removing the entry
0747: //
0748: synchronized (producerEntities) {
0749: producerEntities.remove(producerEntityId);
0750: }
0751: }
0752:
0753: public void modifyRegistration(String producerEntityId,
0754: RegistrationData regData) throws WSRPConsumerException,
0755: InbandRegistrationNotSupportedException {
0756:
0757: // TBD: this method needs to be made atomic
0758:
0759: //
0760: // modify registration at the producer end
0761: //
0762: ProducerEntity ope = getProducerEntity(producerEntityId);
0763: if (ope == null) {
0764: throw new WSRPConsumerException(
0765: "ProducerEntityManagerImpl.modifyRegistration(): invalid producer entity id. peId="
0766: + producerEntityId);
0767: }
0768:
0769: URL producerURL = ope.getURL();
0770: RegistrationContext regContext = ope.getRegistrationContext();
0771:
0772: String endpoint = stubMgr.getEndpoint(producerURL,
0773: stubMgr.REGISTRATION_PORT_BINDING);
0774:
0775: WSRP_v1_Registration_PortType regPort = stubMgr
0776: .getRegistrationPortType(endpoint);
0777:
0778: //
0779: // registration port is not exposed: i.e. in-band reg. not supported
0780: //
0781: if (regPort == null) {
0782: throw new InbandRegistrationNotSupportedException(
0783: "ProducerEntityManagerImpl.modifyRegistration(): registration port not available. producerrEntityId="
0784: + producerEntityId);
0785: }
0786:
0787: ModifyRegistration modReg = new ModifyRegistration(regContext,
0788: regData);
0789: RegistrationState regState = null;
0790: try {
0791: regState = regPort.modifyRegistration(modReg);
0792: } catch (InvalidRegistrationFault irf) {
0793: throw new WSRPConsumerException(
0794: "ProducerEntityManagerImpl.modifyRegistration(): failed to modify registration producerEntityId="
0795: + producerEntityId + ", regData=" + regData,
0796: irf);
0797: } catch (MissingParametersFault mpf) {
0798: throw new WSRPConsumerException(
0799: "ProducerEntityManagerImpl.modifyRegistration(): failed to modify registration producerEntityId="
0800: + producerEntityId + ", regData=" + regData,
0801: mpf);
0802: } catch (OperationFailedFault off) {
0803: throw new WSRPConsumerException(
0804: "ProducerEntityManagerImpl.modifyRegistration(): failed to modify registration producerEntityId="
0805: + producerEntityId + ", regData=" + regData,
0806: off);
0807: } catch (RemoteException re) {
0808: throw new WSRPConsumerException(
0809: "ProducerEntityManagerImpl.modifyRegistration(): failed to modify registration producerEntityId="
0810: + producerEntityId + ", regData=" + regData,
0811: re);
0812: }
0813:
0814: //
0815: // update registration state (only if it's non-empty value)
0816: //
0817: if (regState != null) {
0818: regContext.setRegistrationState(regState
0819: .getRegistrationState());
0820: }
0821:
0822: //
0823: // update IS
0824: //
0825:
0826: String rdXML = null;
0827: if (regData != null) {
0828: try {
0829: rdXML = getWSRPFactory()
0830: .getRegistrationDataXML(regData);
0831: } catch (WSRPException we) {
0832: throw new WSRPConsumerException(
0833: "ProducerEntityManagerImpl.modifyRegistration(): failed to serialize registration data. regData="
0834: + regData, we);
0835: }
0836: }
0837:
0838: String rcXML = null;
0839: if (regContext != null) {
0840: try {
0841: rcXML = getWSRPFactory().getRegistrationContextXML(
0842: regContext);
0843: } catch (WSRPException we) {
0844: throw new WSRPConsumerException(
0845: "ProducerEntityManagerImpl.modifyRegistration(): failed to serialize registration context. regContext="
0846: + regContext, we);
0847: }
0848: }
0849:
0850: AMOrganizationalUnit peou = getProducerEntityOU(
0851: producerEntityId, userConnection);
0852: if (peou == null) {
0853: throw new WSRPConsumerException(
0854: "ProducerEntityManagerImpl.modifyRegistration(): invalid producerEntityId="
0855: + producerEntityId);
0856: }
0857:
0858: try {
0859: peou.setStringAttribute(ATTR_REGISTRATION_DATA, rdXML);
0860: peou.setStringAttribute(ATTR_REGISTRATION_CONTEXT, rcXML);
0861: peou.store();
0862: } catch (AMException ae) {
0863: throw new WSRPConsumerException(
0864: "ProducerEntityManagerImpl.modifyRegistration(): failed to persist registration context. producerEntityId="
0865: + producerEntityId, ae);
0866: } catch (SSOException se) {
0867: throw new WSRPConsumerException(
0868: "ProducerEntityManagerImpl.modifyRegistration(): failed to persist registration context. producerEntityId="
0869: + producerEntityId, se);
0870: }
0871:
0872: //
0873: // update cache by removing the entry
0874: //
0875: synchronized (producerEntities) {
0876: producerEntities.remove(producerEntityId);
0877: }
0878: }
0879:
0880: public void removeProducerEntity(String producerEntityId)
0881: throws WSRPConsumerException,
0882: InbandRegistrationNotSupportedException {
0883:
0884: // TBD: this method needs to be made atomic
0885: ProducerEntity pe = getProducerEntity(producerEntityId);
0886: if (pe == null) {
0887: throw new WSRPConsumerException(
0888: "ProducerEntityManagerImpl.removeProducerEntity(): invalid producer entity id. peId="
0889: + producerEntityId);
0890: }
0891:
0892: //
0893: // deregister from the producer
0894: //
0895:
0896: // TBD: deregister only if registration is required?
0897: try {
0898: if (pe.getServiceDescription().isRequiresRegistration()) {
0899: URL producerURL = pe.getURL();
0900: RegistrationContext regContext = pe
0901: .getRegistrationContext();
0902:
0903: String endpoint = stubMgr.getEndpoint(producerURL,
0904: stubMgr.REGISTRATION_PORT_BINDING);
0905:
0906: WSRP_v1_Registration_PortType regPort = stubMgr
0907: .getRegistrationPortType(endpoint);
0908: ;
0909:
0910: //
0911: // registration port is not exposed: i.e. in-band reg. not supported
0912: //
0913: if (regPort == null) {
0914: throw new InbandRegistrationNotSupportedException(
0915: "ProducerEntityManagerImpl.removeProducerEntity(): registration port not available. producerEntityId="
0916: + producerEntityId);
0917: }
0918:
0919: ReturnAny ret = null;
0920: try {
0921: ret = regPort.deregister(regContext);
0922: } catch (InvalidRegistrationFault irf) {
0923: //Ignoring this exception as a registration handle deleted by the Producer would throw this
0924: //throw new WSRPConsumerException("ProducerEntityManagerImpl.removeProducerEntity(): failed to deregister from the producer. producerEntityId=" + producerEntityId + ", regContext=" + regContext, irf);
0925: if (logger.isLoggable(Level.FINEST))
0926: logger.log(Level.FINEST, irf.getMessage(), irf);
0927: } catch (OperationFailedFault off) {
0928: throw new WSRPConsumerException(
0929: "ProducerEntityManagerImpl.removeProducerEntity(): failed to deregister from the producer. producerEntityId="
0930: + producerEntityId
0931: + ", regContext=" + regContext, off);
0932: } catch (RemoteException re) {
0933: throw new WSRPConsumerException(
0934: "ProducerEntityManagerImpl.removeProducerEntity(): failed to deregister from the producer. producerEntityId="
0935: + producerEntityId
0936: + ", regContext=" + regContext, re);
0937: }
0938: }
0939: } catch (ParseException e) {
0940: logger.log(Level.WARNING, "PSWS_CSPWCPI0017", e);
0941: logger.log(Level.WARNING, "PSWS_CSPWCPI0018");
0942: }
0943:
0944: //
0945: // remove the pe from is
0946: //
0947: eliminateProducerEntity(producerEntityId);
0948: }
0949:
0950: public void eliminateProducerEntity(String producerEntityId)
0951: throws WSRPConsumerException {
0952:
0953: //
0954: // remove the pe from is
0955: //
0956: purgeProducerEntity(producerEntityId);
0957:
0958: //
0959: // remove from cache
0960: //
0961: synchronized (producerEntities) {
0962: producerEntities.remove(producerEntityId);
0963: }
0964: }
0965:
0966: public Set getProducerEntityIds() throws WSRPConsumerException {
0967:
0968: AMOrganizationalUnit cou = getConsumerOU(getAdminConnection());
0969: Set peDNs = null;
0970: try {
0971: peDNs = cou
0972: .getSubOrganizationalUnits(AMConstants.SCOPE_ONE);
0973: } catch (AMException ae) {
0974: throw new WSRPConsumerException(
0975: "ProducerEntityManagerImpl.getProducerEntityIds(): failed to retrieve sub organizations from dn="
0976: + cou.getDN(), ae);
0977: } catch (SSOException se) {
0978: throw new WSRPConsumerException(
0979: "ProducerEntityManagerImpl.getProducerEntityIds(): failed to retrieve sub organizations from dn="
0980: + cou.getDN(), se);
0981: }
0982:
0983: Set peIds = new HashSet();
0984: for (Iterator i = peDNs.iterator(); i.hasNext();) {
0985: String dn = (String) i.next();
0986: // TBD: there should be a better way to get RDN off of the DN
0987: int index = dn.indexOf(',');
0988: if (index > 0) {
0989: //
0990: // get rid of the "ou="
0991: //
0992: String ouRDN = dn.substring(0, index);
0993: int ind = ouRDN.indexOf('=');
0994: if (ind > 0) {
0995: peIds.add(ouRDN.substring(ind + 1));
0996: }
0997: }
0998: }
0999:
1000: return peIds;
1001: }
1002:
1003: public Map getStandardUserProfileMapping()
1004: throws WSRPConsumerException {
1005:
1006: Timer t = new Timer();
1007:
1008: Map userProfileMapping = null;
1009: Set supSet = getGlobalAttribute(ATTR_USER_PROFILE_MAPPING);
1010: if (supSet.size() > 0) {
1011: userProfileMapping = new HashMap();
1012: for (Iterator i = supSet.iterator(); i.hasNext();) {
1013: String map = (String) i.next();
1014: int index = map.indexOf(MAPPING_DELIMITER);
1015: userProfileMapping.put(map.substring(0, index), map
1016: .substring(index + 1));
1017: }
1018: }
1019:
1020: if (logger.isLoggable(Level.FINEST)) {
1021: String[] param = { "elapsed", "" + t.getElapsed() };
1022: logger.log(Level.FINEST, "PSWS_CSPWCPI0002", param);
1023: }
1024:
1025: return userProfileMapping;
1026: }
1027:
1028: public RegistrationData getDefaultRegistrationData()
1029: throws WSRPConsumerException {
1030:
1031: Timer t = new Timer();
1032:
1033: RegistrationData defaultRegistrationData = null;
1034: Set rdSet = getGlobalAttribute(ATTR_DEFAULT_REGISTRATION_DATA);
1035: if (rdSet.size() > 0) {
1036: String rdXML = (String) rdSet.iterator().next();
1037: try {
1038: defaultRegistrationData = getWSRPFactory()
1039: .getRegistrationData(rdXML);
1040: } catch (WSRPException we) {
1041: throw new WSRPConsumerException(
1042: "ProducerEntityManagerImpl.getDefaultRegistrationData(): failed to unmarshal registration data. xml="
1043: + rdXML, we);
1044: }
1045: }
1046:
1047: //
1048: // replace consumer name with the one from service template if avail.
1049: //
1050: String consumerName = getConsumerName();
1051:
1052: if (consumerName == null || consumerName.length() == 0) {
1053: consumerName = defaultRegistrationData.getConsumerName();
1054: if (logger.isLoggable(Level.FINEST))
1055: logger.log(Level.FINEST, "PSWS_CSPWCPI0004");
1056: }
1057:
1058: //
1059: // replace consumer agent
1060: //
1061: String consumerAgent = getConsumerAgent();
1062:
1063: RegistrationData defRegData = new RegistrationData(
1064: consumerName, consumerAgent, defaultRegistrationData
1065: .isMethodGetSupported(),
1066: defaultRegistrationData.getConsumerModes(),
1067: defaultRegistrationData.getConsumerWindowStates(),
1068: defaultRegistrationData.getConsumerUserScopes(),
1069: defaultRegistrationData.getCustomUserProfileData(),
1070: defaultRegistrationData.getRegistrationProperties(),
1071: defaultRegistrationData.getExtensions());
1072:
1073: if (logger.isLoggable(Level.FINEST)) {
1074: String[] param = { "elapsed", "" + t.getElapsed() };
1075: logger.log(Level.FINEST, "PSWS_CSPWCPI0002", param);
1076: }
1077:
1078: return defRegData;
1079: }
1080:
1081: public void setConsumerName(String consumerName)
1082: throws WSRPConsumerException {
1083:
1084: AMTemplate template = getOrganizationServiceTemplate(userConnection);
1085:
1086: if (template != null) {
1087: try {
1088: Map attrMap = new HashMap();
1089: Set valueSet = new HashSet();
1090: valueSet.add(consumerName);
1091: attrMap.put(ATTR_CONSUMER_NAME, valueSet);
1092: template.setAttributes(attrMap);
1093: template.store();
1094: } catch (AMException ae) {
1095: throw new WSRPConsumerException(
1096: "ProducerEntityManagerImpl.setConsumerName(): failed to set consumer name.",
1097: ae);
1098: } catch (SSOException se) {
1099: throw new WSRPConsumerException(
1100: "ProducerEntityManagerImpl.setConsumerName(): failed to set consumer name.",
1101: se);
1102: }
1103: } else {
1104: throw new WSRPConsumerException(
1105: "ProducerEntityManagerImpl.setConsumerName(): failed to get wsrp consumer service template. consumerOrgDN="
1106: + consumerOrgDN);
1107: }
1108: }
1109:
1110: public void setName(String producerEntityId, String name)
1111: throws WSRPConsumerException {
1112:
1113: AMOrganizationalUnit peou = getProducerEntityOU(
1114: producerEntityId, userConnection);
1115: if (peou == null) {
1116: throw new WSRPConsumerException(
1117: "ProducerEntityManagerImpl.setName(): invalid producerEntityId="
1118: + producerEntityId);
1119: }
1120:
1121: try {
1122: peou.setStringAttribute(ATTR_PRODUCER_NAME, name);
1123: peou.store();
1124: } catch (AMException ae) {
1125: throw new WSRPConsumerException(
1126: "ProducerEntityManagerImpl.setName(): failed to set name. producerEntityId="
1127: + producerEntityId + "name=" + name, ae);
1128: } catch (SSOException se) {
1129: throw new WSRPConsumerException(
1130: "ProducerEntityManagerImpl.setName(): failed to set name. producerEntityId="
1131: + producerEntityId + "name=" + name, se);
1132: }
1133:
1134: //
1135: // update cache by removing the entry
1136: //
1137: synchronized (producerEntities) {
1138: producerEntities.remove(producerEntityId);
1139: }
1140: }
1141:
1142: public void setIdentityPropagationType(String producerEntityId,
1143: String type) throws WSRPConsumerException {
1144:
1145: AMOrganizationalUnit peou = getProducerEntityOU(
1146: producerEntityId, userConnection);
1147: if (peou == null) {
1148: throw new WSRPConsumerException(
1149: "ProducerEntityManagerImpl.setIdentityPropagationType(): invalid producerEntityId="
1150: + producerEntityId);
1151: }
1152: if (!(type
1153: .equals(IdentityPropagationConstants.NO_IDENTITY_PROPAGATION)
1154: || type
1155: .equals(IdentityPropagationConstants.OASIS_WSS_USERNAME_ONLY_PROPAGATION)
1156: || type
1157: .equals(IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_DIGEST_PROPAGATION)
1158: || type
1159: .equals(IdentityPropagationConstants.OASIS_WSS_USERNAME_PASSWORD_PLAINTEXT_PROPAGATION) || type
1160: .equals(IdentityPropagationConstants.SSOTOKEN_IDENTITY_PROPAGATION))) {
1161: throw new WSRPConsumerException(
1162: "ProducerEntityManagerImpl.setIdentityPropagationType():Invalid type, type="
1163: + type);
1164: }
1165: try {
1166: peou.setStringAttribute(ATTR_IDENTITY_PROPAGATION_TYPE,
1167: type);
1168: peou.store();
1169: } catch (AMException ae) {
1170: throw new WSRPConsumerException(
1171: "ProducerEntityManagerImpl.setIdentityPropagationType(): failed to set identityPropagationType. producerEntityId="
1172: + producerEntityId + "type=" + type, ae);
1173: } catch (SSOException se) {
1174: throw new WSRPConsumerException(
1175: "ProducerEntityManagerImpl.setIdentityPropagationType(): failed to set identityPropagationType. producerEntityId="
1176: + producerEntityId + "type=" + type, se);
1177: }
1178:
1179: //
1180: // update cache by removing the entry
1181: //
1182: synchronized (producerEntities) {
1183: producerEntities.remove(producerEntityId);
1184: }
1185: }
1186:
1187: public void setURL(String producerEntityId, URL url)
1188: throws WSRPConsumerException {
1189:
1190: AMOrganizationalUnit peou = getProducerEntityOU(
1191: producerEntityId, userConnection);
1192: if (peou == null) {
1193: throw new WSRPConsumerException(
1194: "ProducerEntityManagerImpl.setURL(): invalid producerEntityId="
1195: + producerEntityId);
1196: }
1197:
1198: if (url == null) {
1199: throw new WSRPConsumerException(
1200: "ProducerEntityManagerImpl.setURL(): url cannot be null. producerEntityId="
1201: + producerEntityId);
1202: }
1203:
1204: //
1205: // refresh markup endpoint
1206: //
1207: String markupEndpoint = stubMgr.getEndpoint(url,
1208: stubMgr.MARKUP_PORT_BINDING);
1209:
1210: try {
1211: peou.setStringAttribute(ATTR_PRODUCER_URL, url.toString());
1212: peou.setStringAttribute(ATTR_PRODUCER_MARKUP_ENDPOINT,
1213: markupEndpoint);
1214: peou.store();
1215: } catch (AMException ae) {
1216: throw new WSRPConsumerException(
1217: "ProducerEntityManagerImpl.setURL(): failed to set url. producerEntityId="
1218: + producerEntityId + "url=" + url, ae);
1219: } catch (SSOException se) {
1220: throw new WSRPConsumerException(
1221: "ProducerEntityManagerImpl.setURL(): failed to set url. producerEntityId="
1222: + producerEntityId + "url=" + url, se);
1223: }
1224:
1225: //
1226: // update cache by removing the entry
1227: //
1228: synchronized (producerEntities) {
1229: producerEntities.remove(producerEntityId);
1230: }
1231: }
1232:
1233: public void setStatus(String producerEntityId,
1234: ProducerEntityStatus status) throws WSRPConsumerException {
1235:
1236: AMOrganizationalUnit peou = getProducerEntityOU(
1237: producerEntityId, userConnection);
1238: if (peou == null) {
1239: throw new WSRPConsumerException(
1240: "ProducerEntityManagerImpl.setStatus(): invalid producerEntityId="
1241: + producerEntityId);
1242: }
1243:
1244: if (status == null) {
1245: throw new WSRPConsumerException(
1246: "ProducerEntityManagerImpl.setStatus(): status cannot be null. producerEntityId="
1247: + producerEntityId);
1248: }
1249:
1250: try {
1251: peou.setStringAttribute(ATTR_PRODUCER_STATUS, Short
1252: .toString(status.getValue()));
1253: peou.store();
1254: } catch (AMException ae) {
1255: throw new WSRPConsumerException(
1256: "ProducerEntityManagerImpl.setStatus(): failed to set status. producerEntityId="
1257: + producerEntityId + "status=" + status, ae);
1258: } catch (SSOException se) {
1259: throw new WSRPConsumerException(
1260: "ProducerEntityManagerImpl.setStatus(): failed to set status. producerEntityId="
1261: + producerEntityId + "status=" + status, se);
1262: }
1263:
1264: //
1265: // update cache by removing the entry
1266: //
1267: synchronized (producerEntities) {
1268: producerEntities.remove(producerEntityId);
1269: }
1270: }
1271:
1272: public void setUserCategoryMapping(String producerEntityId,
1273: Map userCategoryMap) throws WSRPConsumerException {
1274:
1275: String ucXML = getConsumerObjectFactory().getMultiValueMapXML(
1276: userCategoryMap);
1277:
1278: AMOrganizationalUnit peou = getProducerEntityOU(
1279: producerEntityId, userConnection);
1280: if (peou == null) {
1281: throw new WSRPConsumerException(
1282: "ProducerEntityManagerImpl.setUserCategoryMapping(): invalid producerEntityId="
1283: + producerEntityId);
1284: }
1285:
1286: try {
1287: peou.setStringAttribute(ATTR_USER_CATEGORY_MAPPING, ucXML);
1288: peou.store();
1289: } catch (AMException ae) {
1290: throw new WSRPConsumerException(
1291: "ProducerEntityManagerImpl.setUserCategoryMapping(): failed to persist user category mapping. producerEntityId="
1292: + producerEntityId, ae);
1293: } catch (SSOException se) {
1294: throw new WSRPConsumerException(
1295: "ProducerEntityManagerImpl.setUserCategoryMapping(): failed to persist user category mapping. producerEntityId="
1296: + producerEntityId, se);
1297: }
1298:
1299: //
1300: // update cache by removing the entry
1301: //
1302: synchronized (producerEntities) {
1303: producerEntities.remove(producerEntityId);
1304: }
1305: }
1306:
1307: public void setAllowedUserProfileMapping(String producerEntityId,
1308: Map allowedUserProfileMap) throws WSRPConsumerException {
1309:
1310: Set cupSet = new HashSet();
1311: for (Iterator i = allowedUserProfileMap.keySet().iterator(); i
1312: .hasNext();) {
1313: String key = (String) i.next();
1314: StringBuffer buf = new StringBuffer();
1315: buf.append(key).append(MAPPING_DELIMITER).append(
1316: allowedUserProfileMap.get(key));
1317: cupSet.add(buf.toString());
1318: }
1319:
1320: AMOrganizationalUnit peou = getProducerEntityOU(
1321: producerEntityId, userConnection);
1322: if (peou == null) {
1323: throw new WSRPConsumerException(
1324: "ProducerEntityManagerImpl.setAllowedUserProfileMapping(): invalid producerEntityId="
1325: + producerEntityId);
1326: }
1327:
1328: try {
1329: Map attrs = new HashMap();
1330: attrs.put(ATTR_ALLOWED_USER_PROFILE_MAPPING, cupSet);
1331: peou.setAttributes(attrs);
1332: peou.store();
1333: } catch (AMException ae) {
1334: throw new WSRPConsumerException(
1335: "ProducerEntityManagerImpl.setAllowedUserProfileMapping(): failed to persist allowed user profile mapping. producerEntityId="
1336: + producerEntityId, ae);
1337: } catch (SSOException se) {
1338: throw new WSRPConsumerException(
1339: "ProducerEntityManagerImpl.setAllowedUserProfileMapping(): failed to persist allowed user profile mapping. producerEntityId="
1340: + producerEntityId, se);
1341: }
1342:
1343: //
1344: // update cache by removing the entry
1345: //
1346: synchronized (producerEntities) {
1347: producerEntities.remove(producerEntityId);
1348: }
1349: }
1350:
1351: public void setCustomUserProfileMapping(String producerEntityId,
1352: Map customUserProfileMap) throws WSRPConsumerException {
1353:
1354: Set cupSet = new HashSet();
1355: for (Iterator i = customUserProfileMap.keySet().iterator(); i
1356: .hasNext();) {
1357: String key = (String) i.next();
1358: StringBuffer buf = new StringBuffer();
1359: buf.append(key).append(MAPPING_DELIMITER).append(
1360: customUserProfileMap.get(key));
1361: cupSet.add(buf.toString());
1362: }
1363:
1364: AMOrganizationalUnit peou = getProducerEntityOU(
1365: producerEntityId, userConnection);
1366: if (peou == null) {
1367: throw new WSRPConsumerException(
1368: "ProducerEntityManagerImpl.setCustomUserProfileMapping(): invalid producerEntityId="
1369: + producerEntityId);
1370: }
1371:
1372: try {
1373: Map attrs = new HashMap();
1374: attrs.put(ATTR_CUSTOM_USER_PROFILE_MAPPING, cupSet);
1375: peou.setAttributes(attrs);
1376: peou.store();
1377: } catch (AMException ae) {
1378: throw new WSRPConsumerException(
1379: "ProducerEntityManagerImpl.setCustomUserProfileMapping(): failed to persist custom user profile mapping. producerEntityId="
1380: + producerEntityId, ae);
1381: } catch (SSOException se) {
1382: throw new WSRPConsumerException(
1383: "ProducerEntityManagerImpl.setCustomUserProfileMapping(): failed to persist custom user profile mapping. producerEntityId="
1384: + producerEntityId, se);
1385: }
1386:
1387: //
1388: // update cache by removing the entry
1389: //
1390: synchronized (producerEntities) {
1391: producerEntities.remove(producerEntityId);
1392: }
1393: }
1394:
1395: public void setStandardUserProfileMapping(Map standardUserProfileMap)
1396: throws WSRPConsumerException {
1397:
1398: Set supSet = null;
1399: if (standardUserProfileMap != null
1400: && standardUserProfileMap.size() > 0) {
1401: supSet = new HashSet();
1402: for (Iterator i = standardUserProfileMap.keySet()
1403: .iterator(); i.hasNext();) {
1404: String key = (String) i.next();
1405: StringBuffer buf = new StringBuffer();
1406: buf.append(key).append(MAPPING_DELIMITER).append(
1407: standardUserProfileMap.get(key));
1408: supSet.add(buf.toString());
1409: }
1410: }
1411: setGlobalAttribute(ATTR_USER_PROFILE_MAPPING, supSet);
1412: }
1413:
1414: public void setDefaultRegistrationData(RegistrationData rd)
1415: throws WSRPConsumerException {
1416:
1417: Set rdSet = null;
1418: if (rd != null) {
1419: rdSet = new HashSet();
1420: String rdXML = null;
1421: try {
1422: rdXML = getWSRPFactory().getRegistrationDataXML(rd);
1423: } catch (WSRPException we) {
1424: throw new WSRPConsumerException(
1425: "ProducerEntityImpl.setDefaultRegistrationData(): failed to marshal registration data.",
1426: we);
1427: }
1428: rdSet.add(rdXML);
1429: }
1430: setGlobalAttribute(ATTR_DEFAULT_REGISTRATION_DATA, rdSet);
1431: }
1432:
1433: protected ProducerEntity createProducerEntity(
1434: String producerEntityId, String producerName,
1435: URL producerURL, String markupEndpoint,
1436: ProducerEntityStatus status, RegistrationData regData,
1437: RegistrationContext regContext,
1438: ServiceDescription serviceDesc, Map userCategories,
1439: Map allowedUserProfiles, Map customUserProfiles,
1440: long serviceDescLastModified, String lastModified,
1441: String identityPropagationType)
1442: throws WSRPConsumerException {
1443:
1444: ProducerEntity pe = new ProducerEntityImpl(producerEntityId,
1445: producerName, producerURL, markupEndpoint, status,
1446: regData, regContext, serviceDesc, userCategories,
1447: allowedUserProfiles, customUserProfiles,
1448: serviceDescLastModified, lastModified,
1449: identityPropagationType);
1450: return pe;
1451: }
1452:
1453: protected ProducerEntity loadProducerEntity(String producerEntityId)
1454: throws WSRPConsumerException {
1455:
1456: if (logger.isLoggable(Level.FINEST))
1457: logger.log(Level.FINEST, "PSWS_CSPWCPI0005",
1458: producerEntityId);
1459:
1460: AMOrganizationalUnit peou = getProducerEntityOU(
1461: producerEntityId, getAdminConnection());
1462: if (peou == null) {
1463: throw new WSRPConsumerException(
1464: "ProducerEntityManagerImpl.loadProducerEntity(): failed to load producer entity. id="
1465: + producerEntityId);
1466: }
1467:
1468: String id = null;
1469: String name = null;
1470: String urlString = null;
1471: String markupEndpoint = null;
1472: String identityPropagationType = null;
1473: ProducerEntityStatus status = null;
1474: String rdXML = null;
1475: String rcXML = null;
1476: String sdXML = null;
1477: String ucXML = null;
1478: Set aups = null;
1479: Set cups = null;
1480: long sdLastModified = -1;
1481: String lastModified = null;
1482:
1483: try {
1484: id = peou.getStringAttribute(ATTR_PRODUCER_ID);
1485: name = peou.getStringAttribute(ATTR_PRODUCER_NAME);
1486: urlString = peou.getStringAttribute(ATTR_PRODUCER_URL);
1487: markupEndpoint = peou
1488: .getStringAttribute(ATTR_PRODUCER_MARKUP_ENDPOINT);
1489: identityPropagationType = peou
1490: .getStringAttribute(ATTR_IDENTITY_PROPAGATION_TYPE);
1491: String statusString = peou
1492: .getStringAttribute(ATTR_PRODUCER_STATUS);
1493: status = ProducerEntityStatus
1494: .getProducerEntityStatus(statusString);
1495: rdXML = peou.getStringAttribute(ATTR_REGISTRATION_DATA);
1496: rcXML = peou.getStringAttribute(ATTR_REGISTRATION_CONTEXT);
1497: sdXML = peou.getStringAttribute(ATTR_SERVICE_DESCRIPTION);
1498: ucXML = peou.getStringAttribute(ATTR_USER_CATEGORY_MAPPING);
1499: aups = peou.getAttribute(ATTR_ALLOWED_USER_PROFILE_MAPPING);
1500: cups = peou.getAttribute(ATTR_CUSTOM_USER_PROFILE_MAPPING);
1501: String sdLastModifiedString = peou
1502: .getStringAttribute(ATTR_SERVICE_DESCRIPTION_LAST_MODIFIED);
1503: if (sdLastModifiedString != null
1504: && sdLastModifiedString.length() > 0) {
1505: sdLastModified = Long.parseLong(sdLastModifiedString);
1506: }
1507: lastModified = peou.getStringAttribute(ATTR_LAST_MODIFIED);
1508: } catch (AMException ae) {
1509: throw new WSRPConsumerException(
1510: "ProducerEntityManagerImpl.loadProducerEntity(): failed to retrieve producer entity. producerEntityId="
1511: + producerEntityId, ae);
1512: } catch (SSOException se) {
1513: throw new WSRPConsumerException(
1514: "ProducerEntityManagerImpl.loadProducerEntity(): failed to retrieve producer entity. producerEntityId="
1515: + producerEntityId, se);
1516: } catch (NumberFormatException nfe) {
1517: throw new WSRPConsumerException(
1518: "ProducerEntityManagerImpl.loadProducerEntity(): failed to retrieve producer entity. producerEntityId="
1519: + producerEntityId, nfe);
1520: }
1521:
1522: URL url = null;
1523: try {
1524: url = new URL(urlString);
1525: } catch (MalformedURLException mfue) {
1526: throw new WSRPConsumerException(
1527: "ProducerEntityManagerImpl.loadProducerEntity(): failed to create URL urlString="
1528: + urlString, mfue);
1529: }
1530:
1531: RegistrationData rd = null;
1532: if (rdXML != null && rdXML.length() > 0) {
1533: try {
1534: rd = getWSRPFactory().getRegistrationData(rdXML);
1535: } catch (WSRPException we) {
1536: throw new WSRPConsumerException(
1537: "ProducerEntityManagerImpl.loadProducerEntity(): failed to unserialize registration data. xml="
1538: + rdXML, we);
1539: }
1540: }
1541:
1542: RegistrationContext rc = null;
1543: if (rcXML != null && rcXML.length() > 0) {
1544: try {
1545: rc = getWSRPFactory().getRegistrationContext(rcXML);
1546: } catch (WSRPException we) {
1547: throw new WSRPConsumerException(
1548: "ProducerEntityManagerImpl.loadProducerEntity(): failed to unserialize registration context. xml="
1549: + rcXML, we);
1550: }
1551: }
1552:
1553: ServiceDescription sd = null;
1554: if (sdXML != null) {
1555: try {
1556: sd = getWSRPFactory().getServiceDescription(sdXML);
1557: } catch (WSRPException we) {
1558: throw new WSRPConsumerException(
1559: "ProducerEntityManagerImpl.loadProducerEntity(): failed to unserialize service description. xml="
1560: + sdXML, we);
1561: }
1562: }
1563:
1564: Map ucMap = getConsumerObjectFactory().getMap(ucXML);
1565:
1566: Map aupMap = new HashMap();
1567: if (aups != null && aups.size() > 0) {
1568: for (Iterator i = aups.iterator(); i.hasNext();) {
1569: String aup = (String) i.next();
1570: int index = aup.indexOf(MAPPING_DELIMITER);
1571: aupMap.put(aup.substring(0, index), aup
1572: .substring(index + 1));
1573: }
1574: }
1575:
1576: Map cupMap = new HashMap();
1577: if (cups != null && cups.size() > 0) {
1578: for (Iterator i = cups.iterator(); i.hasNext();) {
1579: String cup = (String) i.next();
1580: int index = cup.indexOf(MAPPING_DELIMITER);
1581: cupMap.put(cup.substring(0, index), cup
1582: .substring(index + 1));
1583: }
1584: }
1585:
1586: ProducerEntity pe = new ProducerEntityImpl(id, name, url,
1587: markupEndpoint, status, rd, rc, sd, ucMap, aupMap,
1588: cupMap, sdLastModified, lastModified,
1589: identityPropagationType);
1590: return pe;
1591: }
1592:
1593: protected String getProducerEntityLastModified(
1594: String producerEntityId) throws WSRPConsumerException {
1595:
1596: //debug.debugMessage("ProducerEntityManagerImpl.getProducerEntityLastModified(): getting PE's last modified time peID=" + producerEntityId);
1597:
1598: AMOrganizationalUnit peou = getProducerEntityOU(
1599: producerEntityId, getAdminConnection());
1600:
1601: if (peou == null) {
1602: throw new WSRPConsumerException(
1603: "ProducerEntityManagerImpl.getProducerEntityLastModified(): failed to load producer entity. id="
1604: + producerEntityId);
1605: }
1606:
1607: String lastModified = null;
1608: try {
1609: lastModified = peou.getStringAttribute(ATTR_LAST_MODIFIED);
1610: } catch (AMException ae) {
1611: throw new WSRPConsumerException(
1612: "ProducerEntityManagerImpl.getProducerEntityLastModified(): failed to retrieve producer entity. producerEntityId="
1613: + producerEntityId, ae);
1614: } catch (SSOException se) {
1615: throw new WSRPConsumerException(
1616: "ProducerEntityManagerImpl.getProducerEntityLastModified(): failed to retrieve producer entity. producerEntityId="
1617: + producerEntityId, se);
1618: }
1619:
1620: return lastModified;
1621: }
1622:
1623: /**
1624: * assumes that producer entity OU already exists
1625: */
1626: protected void storeProducerEntity(ProducerEntity pe)
1627: throws WSRPConsumerException {
1628:
1629: if (logger.isLoggable(Level.FINEST))
1630: logger.log(Level.FINEST, "PSWS_CSPWCPI0006", pe);
1631:
1632: String producerEntityId = pe.getId();
1633:
1634: RegistrationData rd = pe.getRegistrationData();
1635: String rdXML = null;
1636: if (rd != null) {
1637: try {
1638: rdXML = getWSRPFactory().getRegistrationDataXML(rd);
1639: } catch (WSRPException we) {
1640: throw new WSRPConsumerException(
1641: "ProducerEntityManagerImpl.storeProducerEntity(): failed to serialize registration data. rd="
1642: + rd, we);
1643: }
1644: }
1645:
1646: RegistrationContext rc = pe.getRegistrationContext();
1647: String rcXML = null;
1648: if (rc != null) {
1649: try {
1650: rcXML = getWSRPFactory().getRegistrationContextXML(rc);
1651: } catch (WSRPException we) {
1652: throw new WSRPConsumerException(
1653: "ProducerEntityManagerImpl.storeProducerEntity(): failed to serialize registration context. rc="
1654: + rc, we);
1655: }
1656: }
1657:
1658: ServiceDescription sd = pe.getServiceDescription();
1659: String sdXML = null;
1660: if (sd != null) {
1661: try {
1662: sdXML = getWSRPFactory().getServiceDescriptionXML(sd);
1663: } catch (WSRPException we) {
1664: throw new WSRPConsumerException(
1665: "ProducerEntityManagerImpl.storeProducerEntity(): failed to serialize service description. sd="
1666: + sd, we);
1667: }
1668: }
1669:
1670: Map ucMap = pe.getUserCategoryMapping();
1671: String ucXML = null;
1672: if (ucMap != null && ucMap.size() > 0) {
1673: ucXML = getConsumerObjectFactory().getMultiValueMapXML(
1674: ucMap);
1675: }
1676:
1677: Map aupMap = pe.getAllowedUserProfileMapping();
1678: Set aupSet = null;
1679: if (aupMap != null && aupMap.size() > 0) {
1680: aupSet = new HashSet();
1681: for (Iterator i = aupMap.keySet().iterator(); i.hasNext();) {
1682: String key = (String) i.next();
1683: StringBuffer buf = new StringBuffer();
1684: buf.append(key).append(MAPPING_DELIMITER).append(
1685: aupMap.get(key));
1686: aupSet.add(buf.toString());
1687: }
1688: }
1689:
1690: Map cupMap = pe.getCustomUserProfileMapping();
1691: Set cupSet = null;
1692: if (cupMap != null && cupMap.size() > 0) {
1693: cupSet = new HashSet();
1694: for (Iterator i = cupMap.keySet().iterator(); i.hasNext();) {
1695: String key = (String) i.next();
1696: StringBuffer buf = new StringBuffer();
1697: buf.append(key).append(MAPPING_DELIMITER).append(
1698: cupMap.get(key));
1699: cupSet.add(buf.toString());
1700: }
1701: }
1702:
1703: AMOrganizationalUnit peou = getProducerEntityOU(
1704: producerEntityId, userConnection);
1705: if (peou == null) {
1706: throw new WSRPConsumerException(
1707: "ProducerEntityManagerImpl.storeProducerEntity(): failed to load producer entity. id="
1708: + producerEntityId);
1709: }
1710:
1711: try {
1712: peou.setStringAttribute(ATTR_PRODUCER_ID, producerEntityId);
1713: peou.setStringAttribute(ATTR_PRODUCER_NAME, pe.getName());
1714: peou.setStringAttribute(ATTR_PRODUCER_URL, pe.getURL()
1715: .toString());
1716: peou.setStringAttribute(ATTR_IDENTITY_PROPAGATION_TYPE, pe
1717: .getIdentityPropagationType());
1718: peou.setStringAttribute(ATTR_PRODUCER_MARKUP_ENDPOINT, pe
1719: .getMarkupEndpoint());
1720: peou.setStringAttribute(ATTR_PRODUCER_STATUS, Short
1721: .toString(pe.getStatus().getValue()));
1722: peou.setStringAttribute(ATTR_REGISTRATION_DATA, rdXML);
1723: peou.setStringAttribute(ATTR_REGISTRATION_CONTEXT, rcXML);
1724: peou.setStringAttribute(ATTR_SERVICE_DESCRIPTION, sdXML);
1725: long sdLastModified = pe
1726: .getServiceDescriptionLastModified();
1727: peou.setStringAttribute(
1728: ATTR_SERVICE_DESCRIPTION_LAST_MODIFIED, Long
1729: .toString(sdLastModified));
1730:
1731: peou.setStringAttribute(ATTR_USER_CATEGORY_MAPPING, ucXML);
1732: Map attrs = new HashMap();
1733: if (aupSet != null) {
1734: attrs.put(ATTR_ALLOWED_USER_PROFILE_MAPPING, aupSet);
1735: }
1736: if (cupSet != null) {
1737: attrs.put(ATTR_CUSTOM_USER_PROFILE_MAPPING, cupSet);
1738: }
1739: peou.setAttributes(attrs);
1740:
1741: peou.store();
1742:
1743: } catch (AMException ae) {
1744: throw new WSRPConsumerException(
1745: "ProducerEntityManagerImpl.storeProducerEntity(): failed to persist producer entity. producerEntityId="
1746: + producerEntityId, ae);
1747: } catch (SSOException se) {
1748: throw new WSRPConsumerException(
1749: "ProducerEntityManagerImpl.storeProducerEntity(): failed to persist producer entity. producerEntityId="
1750: + producerEntityId, se);
1751: }
1752: }
1753:
1754: protected void purgeProducerEntity(String producerEntityId)
1755: throws WSRPConsumerException {
1756:
1757: AMOrganizationalUnit peou = getProducerEntityOU(
1758: producerEntityId, userConnection);
1759: if (peou == null) {
1760: throw new WSRPConsumerException(
1761: "ProducerEntityManagerImpl.purgeProducerEntity(): invalid producerEntityId="
1762: + producerEntityId);
1763: }
1764:
1765: try {
1766: //
1767: // delete OU as well as all its children nodes
1768: //
1769: peou.delete(true);
1770: } catch (AMException ae) {
1771: throw new WSRPConsumerException(
1772: "ProducerEntityManagerImpl.purgeProducerEntity(): failed to remove producer entity. producerEntityId="
1773: + producerEntityId, ae);
1774: } catch (SSOException se) {
1775: throw new WSRPConsumerException(
1776: "ProducerEntityManagerImpl.purgeProducerEntity(): failed to remove producer entity. producerEntityId="
1777: + producerEntityId, se);
1778: }
1779: }
1780:
1781: protected AMOrganization getConsumerOrganization()
1782: throws WSRPConsumerException {
1783:
1784: boolean isCoValid = false;
1785: try {
1786: isCoValid = getAdminConnection()
1787: .isValidEntry(consumerOrgDN);
1788: } catch (SSOException se) {
1789: throw new WSRPConsumerException(
1790: "ProducerEntityManagerImpl.getConsumerOrganization(): failed to validate dn. dn= "
1791: + consumerOrgDN, se);
1792: }
1793: if (!isCoValid) {
1794: throw new WSRPConsumerException(
1795: "ProducerEntityManagerImpl.getConsumerOrganization(): not a valid entry in IS. dn="
1796: + consumerOrgDN);
1797: }
1798:
1799: AMOrganization co = null;
1800: try {
1801: co = getAdminConnection().getOrganization(consumerOrgDN);
1802: } catch (SSOException se) {
1803: throw new WSRPConsumerException(
1804: "ProducerEntityManagerImpl.getConsumerOrganization(): failed to access organizational. dn="
1805: + consumerOrgDN, se);
1806: }
1807: return co;
1808:
1809: }
1810:
1811: protected boolean existsConsumerOU() throws WSRPConsumerException {
1812:
1813: // TBD: is this correct way to construct DN?
1814: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
1815: .getInstance(portalId);
1816: String couDN = iscmpc.MP_RDN_CONSUMER + "," + consumerOrgDN;
1817: boolean couValid = false;
1818: try {
1819: couValid = getAdminConnection().isValidEntry(couDN);
1820: } catch (SSOException se) {
1821: throw new WSRPConsumerException(
1822: "ProducerEntityManagerImpl.existsConsumerOU(): failed to validate dn. dn= "
1823: + couDN, se);
1824: }
1825: return couValid;
1826: }
1827:
1828: protected AMOrganizationalUnit createConsumerOU()
1829: throws WSRPConsumerException {
1830:
1831: //
1832: // check to see if the ou already exists
1833: //
1834: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
1835: .getInstance(portalId);
1836: // TBD: is this correct way to construct DN?
1837: String couDN = iscmpc.MP_RDN_CONSUMER + "," + consumerOrgDN;
1838:
1839: if (logger.isLoggable(Level.FINEST))
1840: logger.log(Level.FINEST, "PSWS_CSPWCPI0007", couDN);
1841:
1842: boolean isValidEntry = false;
1843: try {
1844: isValidEntry = getAdminConnection().isValidEntry(couDN);
1845: } catch (SSOException se) {
1846: throw new WSRPConsumerException(
1847: "ProducerEntityManagerImpl.createConsumerOU(): failed to validate entry. dn="
1848: + couDN, se);
1849: }
1850: if (isValidEntry) {
1851: throw new WSRPConsumerException(
1852: "ProducerEntityManagerImpl.createConsumerOU(): producer entity organizational unit already exists. dn="
1853: + couDN);
1854: }
1855:
1856: AMOrganization co = getConsumerOrganization();
1857: Set ous = new HashSet();
1858: ous.add(iscmpc.MP_CONSUMER);
1859: try {
1860: co.createOrganizationalUnits(ous);
1861: } catch (AMException ae) {
1862: throw new WSRPConsumerException(
1863: "ProducerEntityManagerImpl.createConsumerOU(): failed to create organizational unit under dn="
1864: + consumerOrgDN, ae);
1865: } catch (SSOException se) {
1866: throw new WSRPConsumerException(
1867: "ProducerEntityManagerImpl.createConsumerOU(): failed to create organizational unit under dn="
1868: + consumerOrgDN, se);
1869: }
1870:
1871: //
1872: // get a hold of the ou just created
1873: //
1874: AMOrganizationalUnit cou = null;
1875: try {
1876: cou = getAdminConnection().getOrganizationalUnit(couDN);
1877: } catch (SSOException se) {
1878: throw new WSRPConsumerException(
1879: "ProducerEntityManagerImpl.createConsumerOU(): failed to get newly created organizational unit. dn="
1880: + couDN, se);
1881: }
1882: if (cou == null) {
1883: throw new WSRPConsumerException(
1884: "ProducerEntityManagerImpl.createConsumerOU(): failed to get newly created organizational unit. dn="
1885: + couDN);
1886: }
1887:
1888: return cou;
1889: }
1890:
1891: protected AMOrganizationalUnit getConsumerOU(
1892: AMStoreConnection connection) throws WSRPConsumerException {
1893:
1894: AMOrganization co = getConsumerOrganization();
1895: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
1896: .getInstance(portalId);
1897: //
1898: // make sure consumer service is enabled for the org that the
1899: // consumer ou belongs to
1900: //
1901: boolean wsrpConsumerServiceRegistered = false;
1902: if (organizationServiceNameMap.get(co.getDN()) == null) {
1903:
1904: try {
1905: Set services = co.getRegisteredServiceNames();
1906: wsrpConsumerServiceRegistered = services
1907: .contains(iscmpc.MP_SERVICE_WSRP_CONSUMER);
1908: organizationServiceNameMap.put(co.getDN(), new Boolean(
1909: wsrpConsumerServiceRegistered));
1910: } catch (AMException ae) {
1911: throw new WSRPConsumerException(
1912: "ProducerEntityManagerImpl.getConsumerOU(): failed to access service names. dn="
1913: + consumerOrgDN, ae);
1914: } catch (SSOException se) {
1915: throw new WSRPConsumerException(
1916: "ProducerEntityManagerImpl.getConsumerOU(): failed to access service names. dn="
1917: + consumerOrgDN, se);
1918: }
1919: } else {
1920: wsrpConsumerServiceRegistered = ((Boolean) organizationServiceNameMap
1921: .get(co.getDN())).booleanValue();
1922: }
1923: if (!wsrpConsumerServiceRegistered) {
1924: throw new WSRPConsumerException(
1925: "ProducerEntityManagerImpl.getConsumerOU(): "
1926: + iscmpc.MP_SERVICE_WSRP_CONSUMER
1927: + " is not registered for dn="
1928: + consumerOrgDN);
1929: }
1930:
1931: // TBD: is this correct way to construct DN?
1932: String couDN = iscmpc.MP_RDN_CONSUMER + "," + consumerOrgDN;
1933: boolean couValid = false;
1934: try {
1935: couValid = getAdminConnection().isValidEntry(couDN);
1936: } catch (SSOException se) {
1937: throw new WSRPConsumerException(
1938: "ProducerEntityManagerImpl.getConsumerOU(): failed to validate dn. dn= "
1939: + couDN, se);
1940: }
1941: if (!couValid) {
1942: throw new WSRPConsumerException(
1943: "ProducerEntityManagerImpl.getConsumerOU(): invalid entry. DN="
1944: + couDN);
1945: }
1946:
1947: AMOrganizationalUnit cou = null;
1948: try {
1949: cou = connection.getOrganizationalUnit(couDN);
1950: } catch (SSOException se) {
1951: throw new WSRPConsumerException(
1952: "ProducerEntityManagerImpl.getConsumerOU(): failed to access organizational unit. dn="
1953: + couDN, se);
1954: }
1955: return cou;
1956: }
1957:
1958: protected AMOrganizationalUnit createProducerEntityOU(
1959: String producerEntityId) throws WSRPConsumerException {
1960:
1961: AMOrganizationalUnit cou = getConsumerOU(userConnection);
1962:
1963: // TBD: is this correct way to construct DN?
1964: String peouDN = "ou=" + producerEntityId + "," + cou.getDN();
1965:
1966: boolean isValidEntry = false;
1967: try {
1968: isValidEntry = getAdminConnection().isValidEntry(peouDN);
1969: } catch (SSOException se) {
1970: throw new WSRPConsumerException(
1971: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to validate entry. dn="
1972: + peouDN, se);
1973: }
1974: if (isValidEntry) {
1975: throw new WSRPConsumerException(
1976: "ProducerEntityManagerImpl.createProducerEntityOU(): producer entity organizational unit already exists. dn="
1977: + peouDN);
1978: }
1979:
1980: Set ous = new HashSet();
1981: ous.add(producerEntityId);
1982: try {
1983: cou.createSubOrganizationalUnits(ous);
1984: } catch (AMException ae) {
1985: throw new WSRPConsumerException(
1986: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to create organizational unit under dn="
1987: + cou.getDN(), ae);
1988: } catch (SSOException se) {
1989: throw new WSRPConsumerException(
1990: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to create organizational unit under dn="
1991: + cou.getDN(), se);
1992: }
1993:
1994: //
1995: // get a hold of the ou just created
1996: //
1997: AMOrganizationalUnit peou = null;
1998: try {
1999: peou = cou.getSubOrganizationalUnit(peouDN);
2000: } catch (AMException ae) {
2001: throw new WSRPConsumerException(
2002: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to get newly created organizational unit. dn="
2003: + peouDN, ae);
2004: } catch (SSOException se) {
2005: throw new WSRPConsumerException(
2006: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to get newly created organizational unit. dn="
2007: + peouDN, se);
2008: }
2009: if (peou == null) {
2010: throw new WSRPConsumerException(
2011: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to create producer entity organizational unit . dn="
2012: + peouDN);
2013: }
2014:
2015: //
2016: // register objectclass to the newly created pe ou
2017: //
2018: try {
2019: Set ocs = peou.getAttribute("objectclass");
2020: ocs.add(OC_PRODUCER_ENTITY);
2021: Map attrMap = new HashMap();
2022: attrMap.put("objectclass", ocs);
2023: peou.setAttributes(attrMap);
2024: peou.store();
2025: } catch (AMException ae) {
2026: throw new WSRPConsumerException(
2027: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to register objectclass to the newly created organizational unit. dn="
2028: + peouDN
2029: + ", objectclass="
2030: + OC_PRODUCER_ENTITY, ae);
2031: } catch (SSOException se) {
2032: throw new WSRPConsumerException(
2033: "ProducerEntityManagerImpl.createProducerEntityOU(): failed to registerobjectclass to the newly created organizational unit. dn="
2034: + peouDN
2035: + ", objectclass="
2036: + OC_PRODUCER_ENTITY, se);
2037: }
2038:
2039: return peou;
2040: }
2041:
2042: protected AMOrganizationalUnit getProducerEntityOU(
2043: String producerEntityId, AMStoreConnection connection)
2044: throws WSRPConsumerException {
2045:
2046: AMOrganizationalUnit peou = null;
2047:
2048: AMOrganizationalUnit cou = getConsumerOU(connection);
2049:
2050: // TBD: is this correct way to construct DN?
2051: String peouDN = "ou=" + producerEntityId + "," + cou.getDN();
2052:
2053: boolean isValidEntry = false;
2054: try {
2055: isValidEntry = getAdminConnection().isValidEntry(peouDN);
2056: } catch (SSOException se) {
2057: throw new WSRPConsumerException(
2058: "ProducerEntityManagerImpl.getProducerEntityOU(): failed to validate entry. dn="
2059: + peouDN, se);
2060: }
2061: if (isValidEntry) {
2062: try {
2063: peou = cou.getSubOrganizationalUnit(peouDN);
2064: } catch (AMException ae) {
2065: throw new WSRPConsumerException(
2066: "ProducerEntityManagerImpl.getProducerEntityOU(): failed to get organizational unit. dn="
2067: + peouDN, ae);
2068: } catch (SSOException se) {
2069: throw new WSRPConsumerException(
2070: "ProducerEntityManagerImpl.getProducerEntityOU(): failed to get organizational unit. dn="
2071: + peouDN, se);
2072: }
2073: }
2074:
2075: return peou;
2076: }
2077:
2078: protected WSRPFactory getWSRPFactory() throws WSRPConsumerException {
2079:
2080: if (factory == null) {
2081: try {
2082: factory = WSRPFactory.getInstance();
2083: } catch (WSRPException we) {
2084: throw new WSRPConsumerException(
2085: "ProducerEntityManagerImpl.getWSRPFactory(): failed to get an instance of WSRPFactory.",
2086: we);
2087: }
2088: }
2089: return factory;
2090: }
2091:
2092: protected ConsumerObjectFactory getConsumerObjectFactory()
2093: throws WSRPConsumerException {
2094:
2095: if (cofactory == null) {
2096: cofactory = ConsumerObjectFactory.getInstance();
2097: }
2098: return cofactory;
2099: }
2100:
2101: protected AMTemplate getOrganizationServiceTemplate(
2102: AMStoreConnection connection) throws WSRPConsumerException {
2103:
2104: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
2105: .getInstance(portalId);
2106:
2107: boolean isOrgValid = false;
2108: try {
2109: isOrgValid = getAdminConnection().isValidEntry(
2110: consumerOrgDN);
2111: } catch (SSOException se) {
2112: throw new WSRPConsumerException(
2113: "ProducerEntityManagerImpl.getOrganizationServiceTemplate(): failed to validate dn. dn= "
2114: + consumerOrgDN, se);
2115: }
2116: if (!isOrgValid) {
2117: throw new WSRPConsumerException(
2118: "ProducerEntityManagerImpl.getOrganizationServiceTemplate(): invalid dn. dn="
2119: + consumerOrgDN);
2120: }
2121:
2122: AMOrganization org = null;
2123: try {
2124: org = connection.getOrganization(consumerOrgDN);
2125: } catch (SSOException se) {
2126: throw new WSRPConsumerException(
2127: "ProducerEntityManagerImpl.getOrganizationServiceTemplate(): failed to get organization. dn= "
2128: + consumerOrgDN, se);
2129: }
2130:
2131: AMTemplate serviceTemplate = null;
2132: try {
2133: if (org.orgTemplateExists(iscmpc.MP_SERVICE_WSRP_CONSUMER)) {
2134: serviceTemplate = org.getTemplate(
2135: iscmpc.MP_SERVICE_WSRP_CONSUMER,
2136: AMTemplate.ORGANIZATION_TEMPLATE);
2137: }
2138: } catch (AMException ae) {
2139: throw new WSRPConsumerException(
2140: "ProducerEntityManagerImpl.getOrganizationServiceTemplate(): failed retrieve WSRP Consumer service template. dn= "
2141: + consumerOrgDN, ae);
2142: } catch (SSOException se) {
2143: throw new WSRPConsumerException(
2144: "ProducerEntityManagerImpl.getOrganizationServiceTemplate(): failed retrieve WSRP Consumer service template. dn= "
2145: + consumerOrgDN, se);
2146: }
2147:
2148: return serviceTemplate;
2149: }
2150:
2151: protected Set getGlobalAttribute(String attrName)
2152: throws WSRPConsumerException {
2153:
2154: ServiceSchema schema = null;
2155: try {
2156: schema = getServiceSchemaManager().getGlobalSchema();
2157: } catch (SMSException se) {
2158: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
2159: .getInstance(portalId);
2160: throw new WSRPConsumerException(
2161: "ProducerEntityManagerImpl.getGlobalAttribute(): failed to retrieve global schema for service="
2162: + iscmpc.MP_SERVICE_WSRP_CONSUMER, se);
2163: }
2164: Map attrMap = schema.getReadOnlyAttributeDefaults();
2165: return (Set) attrMap.get(attrName);
2166: }
2167:
2168: protected String getGlobalStringAttribute(String attrName)
2169: throws WSRPConsumerException {
2170:
2171: Set set = getGlobalAttribute(attrName);
2172: if (set != null && set.size() > 0) {
2173: return (String) set.iterator().next();
2174: }
2175: return null;
2176: }
2177:
2178: protected void setGlobalAttribute(String attrName, Set value)
2179: throws WSRPConsumerException {
2180:
2181: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
2182: .getInstance(portalId);
2183: ServiceSchema schema = null;
2184: Map attrMap = new HashMap();
2185: attrMap.put(attrName, value);
2186: try {
2187: schema = getServiceSchemaManager().getGlobalSchema();
2188: } catch (SMSException se) {
2189: throw new WSRPConsumerException(
2190: "ProducerEntityManagerImpl.getGlobalAttribute(): failed to retrieve global schema for service="
2191: + iscmpc.MP_SERVICE_WSRP_CONSUMER, se);
2192: }
2193: try {
2194: schema.setAttributeDefaults(attrMap);
2195: } catch (SMSException se) {
2196: throw new WSRPConsumerException(
2197: "ProducerEntityManagerImpl.getGlobalAttribute(): failed to set global attribute. service="
2198: + iscmpc.MP_SERVICE_WSRP_CONSUMER
2199: + ", attrName=" + attrName, se);
2200: } catch (SSOException sse) {
2201: throw new WSRPConsumerException(
2202: "ProducerEntityManagerImpl.getGlobalAttribute(): failed to set global attribute. service="
2203: + iscmpc.MP_SERVICE_WSRP_CONSUMER
2204: + ", attrName=" + attrName, sse);
2205: }
2206: }
2207:
2208: /**
2209: * To get around DSAME bug #4619045
2210: * Abusing this method can lead to a security hole - use with CAUTION!
2211: */
2212: private static AMStoreConnection getAdminConnection()
2213: throws WSRPConsumerException {
2214:
2215: if (adminConnection == null) {
2216: try {
2217: SSOToken sso = getAdminSSOToken();
2218: adminConnection = new AMStoreConnection(sso);
2219: } catch (SSOException se) {
2220: throw new WSRPConsumerException(
2221: "ProducerEntityManagerImpl.getAdminConnection(): ",
2222: se);
2223: }
2224: }
2225: return adminConnection;
2226: }
2227:
2228: private static SSOToken getAdminSSOToken()
2229: throws WSRPConsumerException {
2230:
2231: if (adminSSOToken == null) {
2232: adminSSOToken = SSOUtil.getAdminSSOToken();
2233: }
2234: return adminSSOToken;
2235: }
2236:
2237: /* private static PolicyEvaluator getPolicyEvaluator()
2238: throws WSRPConsumerException {
2239:
2240: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants.getInstance(portalId);
2241: if (policyEvaluator == null) {
2242: try{
2243: policyEvaluator = new PolicyEvaluator(iscmpc.MP_SERVICE_WSRP_CONSUMER);
2244: } catch(SSOException ssoe) {
2245: throw new WSRPConsumerException("ProducerEntityManagerImpl.getPolicyEvaluator(): ", ssoe);
2246: } catch (NameNotFoundException nnfe) {
2247: throw new WSRPConsumerException("ProducerEntityManagerImpl.getPolicyEvaluator(): " + "Service name not found. ", nnfe);
2248: } catch(PolicyException pe) {
2249: throw new WSRPConsumerException("ProducerEntityManagerImpl.getPolicyEvaluator(): ", pe);
2250: }
2251: }
2252: return policyEvaluator;
2253: } */
2254:
2255: private ServiceSchemaManager getServiceSchemaManager()
2256: throws WSRPConsumerException {
2257:
2258: ISConsumerMultiPortalConstants iscmpc = ISConsumerMultiPortalConstants
2259: .getInstance(portalId);
2260: if (serviceSchemaMgr == null) {
2261: try {
2262: serviceSchemaMgr = new ServiceSchemaManager(
2263: getAdminSSOToken(),
2264: iscmpc.MP_SERVICE_WSRP_CONSUMER,
2265: SERVICE_WSRP_CONSUMER_VERSION);
2266: } catch (SSOException se) {
2267: throw new WSRPConsumerException(
2268: "ProducerEntityManagerImpl.getServiceSchemaManager(): ",
2269: se);
2270: } catch (SMSException sme) {
2271: throw new WSRPConsumerException(
2272: "ProducerEntityManagerImpl.getServiceSchemaManager(): ",
2273: sme);
2274: }
2275: }
2276: return serviceSchemaMgr;
2277: }
2278:
2279: protected static String getConsumerAgent() {
2280: if (consumerAgent == null) {
2281: ResourceBundle prodRB = PropertyResourceBundle
2282: .getBundle("PSversion");
2283: StringBuffer caBuffer = new StringBuffer();
2284: caBuffer.append(prodRB.getString("productname"))
2285: .append(".").append(
2286: prodRB.getString("productversion"));
2287: consumerAgent = caBuffer.toString();
2288: }
2289: return consumerAgent;
2290: }
2291:
2292: public List getEndpoints(URL producerURL)
2293: throws WSRPConsumerException {
2294:
2295: List result = new ArrayList();
2296: String sdEndpoint = stubMgr.getEndpoint(producerURL,
2297: stubMgr.SERVICE_DESCRIPTION_PORT_BINDING);
2298:
2299: String reEndpoint = stubMgr.getEndpoint(producerURL,
2300: stubMgr.REGISTRATION_PORT_BINDING);
2301:
2302: String pmEndpoint = stubMgr.getEndpoint(producerURL,
2303: stubMgr.PORTLET_MANAGEMENT_PORT_BINDING);
2304:
2305: String mkEndpoint = stubMgr.getEndpoint(producerURL,
2306: stubMgr.MARKUP_PORT_BINDING);
2307:
2308: if (mkEndpoint != null) {
2309: result.add(mkEndpoint);
2310: }
2311: if (sdEndpoint != null) {
2312: result.add(sdEndpoint);
2313: }
2314: if (reEndpoint != null) {
2315: result.add(reEndpoint);
2316: }
2317: if (pmEndpoint != null) {
2318: result.add(pmEndpoint);
2319: }
2320: return result;
2321: }
2322:
2323: }
|