[8.5.5.8 or later]
This topic applies to WebSphere Application Server Liberty V8.5.5.9 and earlier. For the latest Liberty topics, see the WebSphere Application Server Liberty documentation.

Developing a custom user repository for Liberty

You can develop a custom user repository class by implementing the com.ibm.ws.security.wim.RepositoryFactory and com.ibm.ws.security.wim.Repository interfaces that are provided in the Liberty server.

About this task

The repository interfaces enable support to virtually any type of account repository.

Procedure

  1. Implement the repository factory (com.ibm.ws.security.wim.RepositoryFactory) interface. The RepositoryFactory interface gets the configuration parameters and creates an instance of the repository. For example,
    	public Repository getRepository(Map<String, Object> properties) throws WIMException {
    	return new CustomRepository(properties);}
  2. Implement the repository (com.ibm.ws.security.wim.Repository) interface. This class has the actual repository operations.
    public class CustomRepository extends RepositoryConfiguration implements Repository {
    
        public CustomRepository(Map<String, Object> properties) {
            System.out.println("Constructor with " + properties);
        }
  3. Convert the implementation class into an OSGi service. For more information, see Declaring your services to OSGi Declarative Services.
  4. Package the custom user repository as an OSGi bundle and export the user repository service. For more information about creating an OSGi bundle, see Creating an OSGi service bundle.
  5. Create a feature manifest to include the OSGi bundle. For more information, see Product extension.
  6. After the feature is installed into the user product extension location, configure the server.xml file with the feature name. For example:
    <featureManager>
    	...
    	<feature>usr:customRepositorySample-1.0</feature>
    </featureManager>
    For a downloadable custom user registry sample, see https://developer.ibm.com/wasdev/downloads/#asset/samples-Custom_User_Registry.

Example

Refer to the following samples of repository factory and repository interfaces.
Repository factory interface
package com.myorg;

import java.util.Map;

import org.osgi.service.component.ComponentContext;

import com.ibm.websphere.security.wim.exception.WIMException;
import com.ibm.ws.security.wim.Repository;
import com.ibm.ws.security.wim.RepositoryFactory;

public class CustomRepositoryFactory implements RepositoryFactory {

    @Override
    public Repository getRepository(Map<String, Object> properties) throws WIMException {
        System.out.println("getRepository " + properties);
        return new CustomRepository(properties);
    }

    public void activate(ComponentContext cc, Map<String, Object> properties) {
        System.out.println("In activate");
    }

    public void deactivate(ComponentContext cc) {
        System.out.println("In deactivate");
    }
}
Repository interface
package com.myorg;

import java.util.Map;

import com.ibm.websphere.security.wim.exception.WIMException;
import com.ibm.websphere.security.wim.model.Root;
import com.ibm.ws.security.wim.Repository;
import com.ibm.ws.security.wim.RepositoryConfiguration;

public class CustomRepository extends RepositoryConfiguration implements Repository {

    public CustomRepository(Map<String, Object> properties) {
        System.out.println("Constructor with " + properties);
    }

    @Override
    public Root create(Root arg0) throws WIMException {
        throw new WIMException("Method not supported");
    }

    @Override
    public Root delete(Root arg0) throws WIMException {
        throw new WIMException("Method not supported");
    }

    @Override
    public Root get(Root arg0) throws WIMException {
        throw new WIMException("Method not supported");
    }

    @Override
    public String getRealm() {
        return "customRepository";
    }

    @Override
    public Root login(Root arg0) throws WIMException {
        throw new WIMException("Method not supported");
    }

    @Override
    public Root search(Root arg0) throws WIMException {
        throw new WIMException("Method not supported");
    }

    @Override
    public Root update(Root arg0) throws WIMException {
        throw new WIMException("Method not supported");
    }
}

Icon that indicates the type of topic Task topic



Timestamp icon Last updated: Tuesday, 12 December 2017
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_sec_cust_repository
File name: twlp_sec_cust_repository.html