[16.0.0.3 and later]

Developing a custom user repository for Liberty

You can develop a custom user repository as a user feature by implementing the com.ibm.wsspi.security.wim.CustomRepository interface in the Liberty server. The custom repository interface enables support for most types of account repository.

Procedure

  1. Create a class that implements the custom repository interface, com.ibm.wsspi.security.wim.CustomRepository. This class provides the repository operations. For information about the interface, see the com.ibm.websphere.appserver.spi.federatedRepository_1.0 SPI information in Programming interfaces or in the Java documentation that is provided with the product in the ${wlp.install.dir}/dev/spi/ibm/ directory.

    For an example of implementing the interface, see Repository interface example.

  2. Convert the implementation class into an OSGi service. For more information, see Declaring your services to OSGi Declarative Services.
  3. 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.
  4. Create a feature manifest file to include the OSGi bundle. For more information, see Product extension.
  5. After the feature is installed into the user product extension location, add your custom repository feature in the server.xml configuration file. Also add the appSecurity-2.0 and federatedRegistry-1.0 features, which are required for the custom repository. For example:
    <featureManager>
    	...
    	<feature>usr:customRepositorySample-1.0</feature>
    	<feature>appSecurity-2.0</feature>
    	<feature>federatedRegistry-1.0</feature>
    </featureManager>
  6. Optional: If you want to define customized attributes for users and groups, configure the attributes in a federatedRepository element in the server.xml file.
    In the following example, the myProp attribute is defined for the PersonAccount entity, and the myGroupProp attribute is defined for the Group entity.
    <federatedRepository>
       <primaryRealm name="sampleCustomRepositoryRealm">
           <participatingBaseEntry name="o=ibm,c=us"/>
       </primaryRealm>
       <extendedProperty dataType="String" name="myProp" entityType="PersonAccount"></extendedProperty>
       <extendedProperty dataType="String" name="myGroupProp" entityType="Group"></extendedProperty>
    </federatedRepository>

Repository interface example

package com.myorg;

import java.util.Map;
import com.ibm.wsspi.security.wim.exception.WIMException;
import com.ibm.wsspi.security.wim.model.Root;
import com.ibm.wsspi.security.wim.CustomRepository;

public class MyCustomRepository implements CustomRepository {

    public CustomRepository() {
        System.out.println(“In my custom repository implementation”);
    }

    @Override
    public Root create(Root arg0) throws WIMException {
        System.out.println(“In my create method”);
        //Add your code here
    }

    @Override
    public Root delete(Root arg0) throws WIMException {
        System.out.println(“In my delete method”);
        //Add your code here
    }

    @Override
    public Root get(Root arg0) throws WIMException {
        System.out.println(“In my get method”);
        //Add your code here
    }

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

    @Override
    public Root login(Root arg0) throws WIMException {
        System.out.println(“In my login method”);
        //Add your code here
    }

    @Override
    public Root search(Root arg0) throws WIMException {
        System.out.println(“In my search method”);
        //Add your code here
    }
 
    @Override
    public Root update(Root arg0) throws WIMException {
        System.out.println(“In my update method”);
        //Add your code here
    }

    @Override
    public Map<String, String> getRepositoryBaseEntries() {
        System.out.println(“In my getRepositoryBaseEntries method”);
        //Add your code here
    }

    @Override
    public String[] getRepositoriesForGroups() {
        System.out.println(“In my getRepositoriesForGroups method”);
        //Add your code here
    }
}

Icon that indicates the type of topic Task topic

File name: twlp_sec_cust_repository.html