Implémentation du contrôle d'accès dans l'infrastructure de commandes BOD

Dans le modèle de programmation BOD, les ressources sur lesquelles opèrent les services sont des noms, qui sont représentés par les objets SDO logiques générés. Cependant, ces objets SDO n'implémentent pas l'interface Protectable, requise par le gestionnaire PolicyManager pour vérifier qu'un service est autorisé à opérer sur ces noms. Une classe d'encapsulation doit être implémentée pour chaque nom afin d'extraire les informations requises par le gestionnaire PolicyManager pour effectuer ses vérifications. Ce mappage est défini dans le fichier wc-component.xml.

Procédure

  1. Ouvrez HCL Commerce Developer.
  2. Créez une classe d'encapsulation implémentant l'interface Protectable pour chaque nom de votre module de service. Lorsque le gestionnaire PolicyManager appellera les méthodes sur l'objet encapsuleur Protectable, l'objet Protectable utilisera le nom pour extraire des informations et renvoyer la réponse appropriée. Bien que certaines informations puissent être disponibles dans le nom (comme son propriétaire), la commande ne peut pas supposer que ces informations sont correctes. Cette hypothèse permettra à la vérification de contrôle d'accès d'aboutir quand bien même cette information ne serait pas valide. L'objet encapsuleur Protectable est celui pouvant éclaircir le nom et la corrélation des informations avec la vérification d'autorisation.
    1. Créez dans votre projet de personnalisation une classe Java étendant la classe AbstractProtectableProxy et implémentant l'interface Protectable. La classe doit suivre cette convention de nom : com.<company name>.<component>.facade.server.authorization.<noun name>ProtectableProxy.
      Remarque : Le squelette de cette classe est généré pour vous si vous avez suivi les procédures de la rubrique Création d'un module de service HCL Commerce.
    2. Deux méthodes doivent être implémentées pour chaque classe proxy : fulfills(Long member, String relationship) et getOwner().
      Le code suivant présente un exemple de la méthode 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);
      	}
      
      Le code suivant est un exemple de la méthode 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. Enregistrez la classe proxy Protectable.
  3. Créez le fichier XML de la stratégie de contrôle d'accès en vous basant sur les exemples des différents types de verbe OAGIS présentés dans la rubrique Contrôle d'accès dans l'infrastructure de commandes BOD
  4. Chargez la stratégie de contrôle d'accès en suivant les instructions de la rubrique Chargement de définitions de stratégie de contrôle d'accès et d'autres éléments relatifs aux stratégies..