Skip to Content.
Sympa Menu

grouper-dev - Re: [grouper-dev] ldappc-ng - non LDAP spml provider

Subject: Grouper Developers Forum

List archive

Re: [grouper-dev] ldappc-ng - non LDAP spml provider


Chronological Thread 
  • From: Arnaud Deman <>
  • To: Tom Zeller <>
  • Cc:
  • Subject: Re: [grouper-dev] ldappc-ng - non LDAP spml provider
  • Date: Wed, 30 Mar 2011 16:41:25 +0200


Tom,

I have attached the sources.

My aim was to write an exemple as simple as possible that could be used
then to start more complex projects.

After improving my understanding of the process, my next step would be
to add a connection to a data base with few tables and to see the stems,
groups and members can be provisioned.

Thanks,
Arnaud.


Le mercredi 30 mars 2011 à 09:11:07, Tom Zeller a écrit :
> Great !
>
> Could you publish your code so that I can take a look, please ?
>
> I think it will be easier for me to help, and to document this
> process, if I know what you are doing.
>
> Thanks,
> TomZ
>
> On Wed, Mar 30, 2011 at 8:46 AM, Arnaud Deman
> <>
> wrote:
> > Hello everyone,
> >
> > I am trying to understand how to write an ldappc-ng extension in order
> > to publish into something else than LDAP, for instance a database.
> >
> > I have followed the instruction given by Tom in this thread :
> > https://lists.internet2.edu/sympa/arc/grouper-users/2011-02/msg00017.html
> >
> > And also the documentation for creating Custom IdP :
> > https://spaces.internet2.edu/display/SHIB2/IdPDevCustomExtension
> >
> > This first step seems to be ok :
> > I have written the Provider, the namespace handler, the parser, the
> > schema and added the corresponding target into ldappcng.xml
> >
> > For the moment my Provider is very simple : it always return false to
> > the lookup
> > queries and it logs the other ones.
> >
> > I have some difficulties to see the next step in order to make it more
> > functionnal.
> >
> > My first problem is about the independancy from LDAP :
> > In the queries given to my provider the psoid have a dn form
> > e.g. ou=esup,ou=groups,dc=univ,dc=fr
> > and the search requests have some LdapFilterQueryClause instances.
> >
> > I think it comes from the PSP class, but I was not able to understand if
> > I have to override it, partially or complety, or if it is a configuration
> > pb. I have also some difficulties to see the relationship between this
> > PSP class and my own provider. I suppose it's managed by Spring but I
> > can't see where it is defined.
> >
> > My second problem is to understand the mecanism used to compute the
> > objects to add/modify/delete. I wonder if i have to write some other
> > components or
> > if it is only based on the answers given by my provider. And how are
> > made the comparisons between the objects : with the psoid, with the
> > attributes ? Sorry if my questions are naive...
> >
> >
> > Thanks in advance for your help,
> > Best regards,
> > Arnaud.
> >
> >
> > --
> > Arnaud Deman
> > 04 91 28 85 25
> > DSI - Université Paul Cézanne Aix-Marseille III
> > Avenue Escadrille Normandie-Niemen
> > 13397 MARSEILLE CEDEX 20
> >
> >

--
Arnaud Deman
04 91 28 85 25
DSI - Université Paul Cézanne Aix-Marseille III
Avenue Escadrille Normandie-Niemen
13397 MARSEILLE CEDEX 20

package org.portail.esup.spml.config;

import javax.xml.namespace.QName;

import org.portail.esup.spml.provider.TestShibExtProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import edu.internet2.middleware.ldappc.spml.provider.LdapTargetProvider;
import edu.internet2.middleware.shibboleth.common.config.service.AbstractServiceBeanDefinitionParser;

public class TestShibExtBeanDefinitionParser extends AbstractServiceBeanDefinitionParser {

  private static final Logger LOG = LoggerFactory.getLogger(TestShibExtBeanDefinitionParser.class);

  public static final QName TYPE_NAME = new QName(TestShibExtNamespaceHandler.NAMESPACE, "TestShibExtProvider");

  protected Class getBeanClass(Element element) {
    return TestShibExtProvider.class;
  }

  protected void doParse(Element configElement, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(configElement, parserContext, builder);

    String id = configElement.getAttributeNS(null, "id");
    LOG.debug("Setting id to '{}'", id);
    builder.addPropertyValue("id", id);

    String fileName = configElement.getAttributeNS(null, "fileName");
    LOG.debug("Setting fileName to '{}'", fileName);
    builder.addPropertyValue("fileName", fileName);
  }
}
package org.portail.esup.spml.config;

import edu.internet2.middleware.grouper.shibboleth.attributeDefinition.config.LdapDnPSOIdentifierAttributeDefinitionBeanDefinitionParser;
import edu.internet2.middleware.grouper.shibboleth.attributeDefinition.config.PSOIdentifierAttributeDefinitionBeanDefinitionParser;
import edu.internet2.middleware.grouper.shibboleth.dataConnector.config.SPMLDataConnectorBeanDefinitionParser;
import edu.internet2.middleware.shibboleth.common.config.BaseSpringNamespaceHandler;

public class TestShibExtNamespaceHandler extends BaseSpringNamespaceHandler {

  public static final String NAMESPACE = "http://esup-portail.org/tse";;

  public void init() {
      registerBeanDefinitionParser(TestShibExtBeanDefinitionParser.TYPE_NAME, new TestShibExtBeanDefinitionParser());
  }
}
/**
 * Project: test-shib-extension
 * Author: A. Deman
 * Date: 2011
 */
package org.portail.esup.spml.provider;









import org.openspml.v2.msg.spmlsearch.Query;

import org.openspml.v2.msg.spml.AddRequest;
import org.openspml.v2.msg.spml.AddResponse;
import org.openspml.v2.msg.spml.DeleteRequest;
import org.openspml.v2.msg.spml.DeleteResponse;
import org.openspml.v2.msg.spml.LookupResponse;
import org.openspml.v2.msg.spml.LookupRequest;
import org.openspml.v2.msg.spml.ErrorCode;
import org.openspml.v2.msg.spml.ModifyRequest;
import org.openspml.v2.msg.spml.ModifyResponse;
import org.openspml.v2.msg.spml.PSO;
import org.openspml.v2.msg.spml.StatusCode;
import org.openspml.v2.msg.spmlsearch.SearchRequest;
import org.openspml.v2.msg.spmlsearch.SearchResponse;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.context.ApplicationContext;

import edu.internet2.middleware.grouper.util.GrouperUtil;
import edu.internet2.middleware.ldappc.spml.PSPConstants;
import edu.internet2.middleware.ldappc.spml.provider.BaseSpmlTargetProvider;
import edu.internet2.middleware.ldappc.util.PSPUtil;
import edu.internet2.middleware.shibboleth.common.service.ServiceException;

/**
 * <h1><code>FileTargetProvider</code>.</h1>
 * <hr/>
 * <br/>
 * 
 * <br/><br/>
 * <hr/>
 * <b>Creation date:</b> 2011<br/>
 * <hr/>
 * <i>Author: A. Deman.</i>
 */
public class TestShibExtProvider extends BaseSpmlTargetProvider {

    /** The logger. */
    private static final Logger LOG = LoggerFactory.getLogger(TestShibExtProvider.class);

    /** The file name to use. */
    private String fileName;

    /** The writer to use. */
    private  PrintWriter writer;

    /**
     * {@inheritDoc}
     * @see edu.internet2.middleware.shibboleth.common.config.BaseService#onNewContextCreated(org.springframework.context.ApplicationContext)
     */
    @Override
    protected void onNewContextCreated(ApplicationContext arg0)
    throws ServiceException {
        LOG.info("Create a new context (TSE).");
      
    }

    public AddResponse execute(AddRequest addRequest) {
        String msg = PSPUtil.toString(addRequest);
        LOG.info(msg);
        AddResponse addResponse = new AddResponse();
        addResponse.setRequestID(this.getOrGenerateRequestID(addRequest));
        writer.println(this.toXML(addRequest));
        writer.flush();
        addResponse.setStatus(StatusCode.SUCCESS);
        return addResponse;

    }

    public ModifyResponse execute(ModifyRequest modifyRequest) {
        String msg = PSPUtil.toString(modifyRequest);
        ModifyResponse modifyResponse = new ModifyResponse();
        modifyResponse.setRequestID(this.getOrGenerateRequestID(modifyRequest));
        writer.println(this.toXML(modifyRequest));
        writer.flush();
        modifyResponse.setStatus(StatusCode.SUCCESS);
        return modifyResponse;
    }

    public DeleteResponse execute(DeleteRequest deleteRequest) {
        String msg = PSPUtil.toString(deleteRequest);
        LOG.info(msg);
        DeleteResponse deleteResponse = new DeleteResponse();
        deleteResponse.setRequestID(this.getOrGenerateRequestID(deleteRequest));
        writer.println(this.toXML(deleteRequest));
        writer.flush();
        deleteResponse.setStatus(StatusCode.SUCCESS);
        return deleteResponse;
    }
    
    public LookupResponse execute(LookupRequest lookupRequest) {
        String msg = PSPUtil.toString(lookupRequest);
        LOG.info("{}", msg);
        LookupResponse lookupResponse = new LookupResponse();
        lookupResponse.setRequestID(this.getOrGenerateRequestID(lookupRequest));
        writer.println(this.toXML(lookupRequest));
        writer.flush();
        fail(lookupResponse, ErrorCode.NO_SUCH_IDENTIFIER);
//        lookupResponse.setStatus(StatusCode.SUCCESS);
//        PSO pso = new PSO();
//        pso.setPsoID(lookupRequest.getPsoID());
//        lookupResponse.setPso(pso);
        return lookupResponse;
    }

    public SearchResponse execute(SearchRequest searchRequest) {

        String msg = PSPUtil.toString(searchRequest);
        LOG.info("{}", msg);
        SearchResponse searchResponse = new SearchResponse();
        searchResponse.setRequestID(this.getOrGenerateRequestID(searchRequest));
        writer.println(this.toXML(searchRequest));
        writer.flush();
        searchResponse.setStatus(StatusCode.SUCCESS);
        return searchResponse;
    }

    public boolean isValidTargetId(org.openspml.v2.msg.spml.PSOIdentifier psoID, org.openspml.v2.msg.spml.Response response) {

        if (!psoID.getTargetID().equals(this.getTargetDefinition().getId())) {
            fail(response, ErrorCode.INVALID_IDENTIFIER);
            return false;
        }

        return true;
    }
    
    /**
     * Getter for fileName.
     * @return the fileName
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * Setter for fileName.
     * @param fileName the fileName to set.
     */
    public void setFileName(final String fileName) throws ServiceException {
        this.fileName = fileName;
        try {
            writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(getFileName()), false)));
        } catch (FileNotFoundException e) {
            LOG.error(e.getLocalizedMessage(), e);
            throw new ServiceException(e);
        }
    }
}

Attachment: testshibext.xsd
Description: application/xml




Archive powered by MHonArc 2.6.16.

Top of Page