Implementar el control de acceso en la infraestructura de mandatos de BOD

En el modelo de programación de BOD, los recursos en los cuales los servicios llevan a cabo acciones son nombres, que se representan mediante SDO lógicos generados. No obstante, estos SDO no implementan la interfaz Protectable, que es necesaria para que el Gestor de políticas verifique que un servicio tiene los derechos pertinentes para trabajar con estos nombres. Debe implementarse una clase wrapper para cada nombre para poder extraer la información que el Gestor de políticas necesita para realizar sus comprobaciones. Esta correlación se define en el archivo wc-component.xml.

Procedimiento

  1. Abra HCL Commerce Developer.
  2. Para cada nombre del módulo de servicio, cree una clase wrapper que implemente la interfaz Protectable. Cuando el Gestor de políticas invoque los métodos del objeto wrapper Protectable, el objeto Protectable utilizará el nombre para recuperar la información y, así, poder devolver la respuesta adecuada. Aunque es posible que el nombre contenga cierta información, por ejemplo el propietario, el mandato no puede presuponer que dicha información es correcta. Esta suposición permitirá pasar la comprobación de control de acceso aunque pueda no ser válida. Es el objeto wrapper protegible el que comprende el nombre y cómo se correlaciona la información con la comprobación de autorización.
    1. Cree una clase Java en el proyecto de personalización que se amplíe a partir de la clase AbstractProtectableProxy e implemente la interfaz Protectable. La clase debe seguir este convenio de denominación: com.<company name>.<component>.facade.server.authorization.<noun name>ProtectableProxy.
      Nota: El esqueleto de la clase se genera de forma automática, si ha seguido los pasos de Creación de un módulo de servicio de HCL Commerce.
    2. Hay dos métodos que se deben implementar para cada clase proxy, fulfills(Long member, String relationship) y getOwner().
      El código siguiente es un ejemplo del método fulfills():
      	/**
      	 * This method determines if a given member fulfills a given relationship
      	 * with the resource.
      	 * 
      	 * @param member
      	 *            This is the member id of the member.
      	 * @param relationship
      	 *            This is the relationship the member has with to the resource.
      	 * @return This method will always return <code>true</code>.
      	 * @exception RemoteException
      	 * @exception Exception
      	 */
      	public boolean fulfills(Long member, String relationship)
      			throws RemoteException, Exception {
      		final String METHODNAME = "fulfills(Long, String)";
      		if (com.ibm.commerce.foundation.common.util.logging.LoggingHelper
      				.isEntryExitTraceEnabled(LOGGER)) {
      			LOGGER.entering(CLASSNAME, METHODNAME);
      			LOGGER.exiting(CLASSNAME, METHODNAME);
      		}
      
      		return super.fulfills(member, relationship);
      	}
      
      El código siguiente es un ejemplo del método getOwner():
      		/**
      	 * This method will return the owner of the protectable object. If the owner
      	 * has not been specified on the proxy object, then the owner is the
      	 * owner of the store that can be resolved from the command context.
      	 * 
      	 * @return The owner of the protectable proxy.
      	 * @exception Exception
      	 *                A problem occurred while resolving the owner.
      	 * @exception RemoteException
      	 *                A problem occurred while accessing a remote resource.
      	 * @see com.ibm.commerce.security.Protectable#getOwner()
      	 */
      public Long getOwner() throws Exception, RemoteException {
      
      		final String METHODNAME = "getOwner()";
      		if (com.ibm.commerce.foundation.common.util.logging.LoggingHelper
      				.isEntryExitTraceEnabled(LOGGER)) {
      			LOGGER.entering(CLASSNAME, METHODNAME);
      		}
      		Long oOwner = null;
      		CampaignType aCampaignType = (CampaignType) getObject();
      		// We expect the storeId information in IdentifierType to be resolved
      		if (aCampaignType != null
      				&& aCampaignType.getCampaignIdentifier() != null
      				&& aCampaignType.getCampaignIdentifier()
      						.getExternalIdentifier() != null
      				&& aCampaignType.getCampaignIdentifier()
      						.getExternalIdentifier().getStoreIdentifier() != null
      				&& aCampaignType.getCampaignIdentifier()
      						.getExternalIdentifier().getStoreIdentifier()
      						.getUniqueID() != null) {
      			Integer nStoreId = new Integer(aCampaignType
      					.getCampaignIdentifier().getExternalIdentifier()
      					.getStoreIdentifier().getUniqueID());
      			if (LoggingHelper.isTraceEnabled(LOGGER)) {
      				LOGGER.logp(Level.FINE, CLASSNAME, METHODNAME, "storeId=" + nStoreId);
      			}
      			StoreAccessBean abStore = StoreRegistry.singleton().find(nStoreId);
      			if (abStore != null) {
      				oOwner = abStore.getOwner();
      			} else {
      				// this is site level
      				oOwner = super.getOwner();
      			}
      		} else {
      			oOwner = super.getOwner();
      		}
      
      		if (com.ibm.commerce.foundation.common.util.logging.LoggingHelper
      				.isEntryExitTraceEnabled(LOGGER)) {
      			LOGGER.exiting(CLASSNAME, METHODNAME);
      		}
      
      		return oOwner;
      	}
      
    3. Registre la clase proxy protegible (ProtectableProxy).
  3. Cree el archivo XML de política de control de acceso, siguiendo los ejemplos para los diferentes tipos de verbos OAGIS presentados en Control de acceso en la infraestructura de mandato BOD.
  4. Cargue la política de control de acceso siguiendo las instrucciones de Cargar definiciones de políticas de control de acceso y otros elementos relacionados con políticas.