Tag Archives: PicketLink

How to Add an User to an Identity Manager in PicketLink

import org.picketlink.idm.IdentityManager;
import org.picketlink.idm.PartitionManager;
import org.picketlink.idm.config.IdentityConfigurationBuilder;
import org.picketlink.idm.internal.DefaultPartitionManager;
import org.picketlink.idm.model.basic.User;

public final class PicketLinkSample {

  public static void main(final String[] args) {
    final IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();

    builder.named("default").stores().file()...jpa()...ldap()...add(SampleIdentityStoreConfiguration.class, SampleIdentityStoreConfigurationBuilder.class).supportAllFeatures();

    final PartitionManager partitionManager = new DefaultPartitionManager(builder.buildAll());

    final IdentityManager identityManager = partitionManager.createIdentityManager();

    final User user = new User("user");

    identityManager.add(user);
  }

}
Advertisements

How to Create an Identity/Attribute/Credential/Partition Store for PicketLink

SampleIdentityStore.java

import org.picketlink.idm.internal.AbstractIdentityStore;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.model.IdentityType;
import org.picketlink.idm.model.Relationship;
import org.picketlink.idm.query.IdentityQuery;
import org.picketlink.idm.query.RelationshipQuery;
import org.picketlink.idm.spi.IdentityContext;

public final class SampleIdentityStore extends AbstractIdentityStore<SampleIdentityStoreConfiguration> {

  @Override
  protected void addAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public <V extends IdentityType> int countQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> int countQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  public <V extends IdentityType> List<V> fetchQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> List<V> fetchQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  protected void removeAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  protected void updateAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

}

SampleIdentityStoreConfiguration.java

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.picketlink.idm.config.AbstractIdentityStoreConfiguration;
import org.picketlink.idm.credential.handler.CredentialHandler;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.spi.ContextInitializer;

public final class SampleIdentityStoreConfiguration extends AbstractIdentityStoreConfiguration {

  protected SampleIdentityStoreConfiguration(final Map<Class<? extends AttributedType>, Set<IdentityOperation>> supportedTypes, final Map<Class<? extends AttributedType>, Set<IdentityOperation>> unsupportedTypes, final List<ContextInitializer> contextInitializers, final Map<String, Object> credentialHandlerProperties, @SuppressWarnings("rawtypes") final Set<Class<? extends CredentialHandler>> credentialHandlers, final boolean supportsAttribute, final boolean supportsCredential) {
    super(supportedTypes, unsupportedTypes, contextInitializers, credentialHandlerProperties, credentialHandlers, supportsAttribute, supportsCredential);
  }

  @Override
  protected void initConfig() {
  }

}

SampleIdentityStoreConfigurationBuilder.java

import org.picketlink.idm.config.IdentityStoreConfigurationBuilder;
import org.picketlink.idm.config.IdentityStoresConfigurationBuilder;

public final class SampleIdentityStoreConfigurationBuilder extends IdentityStoreConfigurationBuilder<SampleIdentityStoreConfiguration, SampleIdentityStoreConfigurationBuilder> {

  public SampleIdentityStoreConfigurationBuilder(final IdentityStoresConfigurationBuilder builder) {
    super(builder);
  }

  @Override
  protected SampleIdentityStoreConfiguration create() {
    return null;
  }

}

SampleAttributeStore.java

import java.io.Serializable;
import java.util.List;

import org.picketlink.idm.internal.AbstractIdentityStore;
import org.picketlink.idm.model.Attribute;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.model.IdentityType;
import org.picketlink.idm.model.Relationship;
import org.picketlink.idm.query.IdentityQuery;
import org.picketlink.idm.query.RelationshipQuery;
import org.picketlink.idm.spi.AttributeStore;
import org.picketlink.idm.spi.IdentityContext;

public final class SampleAttributeStore extends AbstractIdentityStore<SampleAttributeStoreConfiguration> implements AttributeStore<SampleAttributeStoreConfiguration> {

  @Override
  protected void addAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public <V extends IdentityType> int countQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> int countQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  public <V extends IdentityType> List<V> fetchQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> List<V> fetchQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  public <V extends Serializable> Attribute<V> getAttribute(final IdentityContext context, final AttributedType type, final String attributeName) {
    return null;
  }

  @Override
  public void loadAttributes(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public void removeAttribute(final IdentityContext context, final AttributedType type, final String attributeName) {
  }

  @Override
  protected void removeAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public void setAttribute(final IdentityContext context, final AttributedType type, final Attribute<? extends Serializable> attribute) {
  }

  @Override
  protected void updateAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

}

SampleAttributeStoreConfiguration.java

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.picketlink.idm.config.AbstractIdentityStoreConfiguration;
import org.picketlink.idm.credential.handler.CredentialHandler;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.spi.ContextInitializer;

public final class SampleAttributeStoreConfiguration extends AbstractIdentityStoreConfiguration {

  protected SampleAttributeStoreConfiguration(final Map<Class<? extends AttributedType>, Set<IdentityOperation>> supportedTypes, final Map<Class<? extends AttributedType>, Set<IdentityOperation>> unsupportedTypes, final List<ContextInitializer> contextInitializers, final Map<String, Object> credentialHandlerProperties, @SuppressWarnings("rawtypes") final Set<Class<? extends CredentialHandler>> credentialHandlers, final boolean supportsAttribute, final boolean supportsCredential) {
    super(supportedTypes, unsupportedTypes, contextInitializers, credentialHandlerProperties, credentialHandlers, supportsAttribute, supportsCredential);
  }

  @Override
  protected void initConfig() {
  }

}

SampleAttributeStoreConfigurationBuilder.java

import org.picketlink.idm.config.IdentityStoreConfigurationBuilder;
import org.picketlink.idm.config.IdentityStoresConfigurationBuilder;

public final class SampleAttributeStoreConfigurationBuilder extends IdentityStoreConfigurationBuilder<SampleAttributeStoreConfiguration, SampleAttributeStoreConfigurationBuilder> {

  public SampleAttributeStoreConfigurationBuilder(final IdentityStoresConfigurationBuilder builder) {
    super(builder);
  }

  @Override
  protected SampleAttributeStoreConfiguration create() {
  }

}

SampleCredentialStore.java

import java.util.List;

import org.picketlink.idm.credential.storage.CredentialStorage;
import org.picketlink.idm.internal.AbstractIdentityStore;
import org.picketlink.idm.model.Account;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.model.IdentityType;
import org.picketlink.idm.model.Relationship;
import org.picketlink.idm.query.IdentityQuery;
import org.picketlink.idm.query.RelationshipQuery;
import org.picketlink.idm.spi.CredentialStore;
import org.picketlink.idm.spi.IdentityContext;

public final class SampleCredentialStore extends AbstractIdentityStore<SampleCredentialStoreConfiguration> implements CredentialStore<SampleCredentialStoreConfiguration> {

  @Override
  protected void addAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public <V extends IdentityType> int countQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> int countQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  public <V extends IdentityType> List<V> fetchQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> List<V> fetchQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  protected void removeAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public <T extends CredentialStorage> List<T> retrieveCredentials(final IdentityContext context, final Account account, final Class<T> storageClass) {
    return null;
  }

  @Override
  public <T extends CredentialStorage> T retrieveCurrentCredential(final IdentityContext context, final Account account, final Class<T> storageClass) {
    return null;
  }

  @Override
  public void storeCredential(final IdentityContext context, final Account account, final CredentialStorage storage) {
  }

  @Override
  protected void updateAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

}

SampleCredentialStoreConfiguration.java

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.picketlink.idm.config.AbstractIdentityStoreConfiguration;
import org.picketlink.idm.credential.handler.CredentialHandler;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.spi.ContextInitializer;

public final class SampleCredentialStoreConfiguration extends AbstractIdentityStoreConfiguration {

  protected SampleCredentialStoreConfiguration(final Map<Class<? extends AttributedType>, Set<IdentityOperation>> supportedTypes, final Map<Class<? extends AttributedType>, Set<IdentityOperation>> unsupportedTypes, final List<ContextInitializer> contextInitializers, final Map<String, Object> credentialHandlerProperties, @SuppressWarnings("rawtypes") final Set<Class<? extends CredentialHandler>> credentialHandlers, final boolean supportsAttribute, final boolean supportsCredential) {
    super(supportedTypes, unsupportedTypes, contextInitializers, credentialHandlerProperties, credentialHandlers, supportsAttribute, supportsCredential);
  }

  @Override
  protected void initConfig() {
  }

}

SampleCredentialStoreConfigurationBuilder.java

import org.picketlink.idm.config.IdentityStoreConfigurationBuilder;
import org.picketlink.idm.config.IdentityStoresConfigurationBuilder;

public final class SampleCredentialStoreConfigurationBuilder extends IdentityStoreConfigurationBuilder<SampleCredentialStoreConfiguration, SampleCredentialStoreConfigurationBuilder> {

  public SampleCredentialStoreConfigurationBuilder(final IdentityStoresConfigurationBuilder builder) {
    super(builder);
  }

  @Override
  protected SampleCredentialStoreConfiguration create() {
    return null;
  }

}

SamplePartitionStore.java

import java.util.List;

import org.picketlink.idm.internal.AbstractIdentityStore;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.model.IdentityType;
import org.picketlink.idm.model.Partition;
import org.picketlink.idm.model.Relationship;
import org.picketlink.idm.query.IdentityQuery;
import org.picketlink.idm.query.RelationshipQuery;
import org.picketlink.idm.spi.IdentityContext;
import org.picketlink.idm.spi.PartitionStore;

public final class SamplePartitionStore extends AbstractIdentityStore<SamplePartitionStoreConfiguration> implements PartitionStore<SamplePartitionStoreConfiguration> {

  @Override
  public void add(final IdentityContext identityContext, final Partition partition, final String configurationName) {
  }

  @Override
  protected void addAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public <V extends IdentityType> int countQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> int countQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  public <V extends IdentityType> List<V> fetchQueryResults(final IdentityContext context, final IdentityQuery<V> identityQuery) {
    return null;
  }

  @Override
  public <V extends Relationship> List<V> fetchQueryResults(final IdentityContext context, final RelationshipQuery<V> query) {
    return null;
  }

  @Override
  public <P extends Partition> List<P> get(final IdentityContext identityContext, final Class<P> partitionClass) {
    return null;
  }

  @Override
  public <P extends Partition> P get(final IdentityContext identityContext, final Class<P> partitionClass, final String name) {
    return null;
  }

  @Override
  public String getConfigurationName(final IdentityContext identityContext, final Partition partition) {
    return null;
  }

  @Override
  public <P extends Partition> P lookupById(final IdentityContext context, final Class<P> partitionClass, final String id) {
    return null;
  }

  @Override
  public void remove(final IdentityContext identityContext, final Partition partition) {
  }

  @Override
  protected void removeAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

  @Override
  public void update(final IdentityContext identityContext, final Partition partition) {
  }

  @Override
  protected void updateAttributedType(final IdentityContext context, final AttributedType attributedType) {
  }

}

SamplePartitionStoreConfiguration.java

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.picketlink.idm.config.AbstractIdentityStoreConfiguration;
import org.picketlink.idm.credential.handler.CredentialHandler;
import org.picketlink.idm.model.AttributedType;
import org.picketlink.idm.spi.ContextInitializer;

public final class SamplePartitionStoreConfiguration extends AbstractIdentityStoreConfiguration {

  protected SamplePartitionStoreConfiguration(final Map<Class<? extends AttributedType>, Set<IdentityOperation>> supportedTypes, final Map<Class<? extends AttributedType>, Set<IdentityOperation>> unsupportedTypes, final List<ContextInitializer> contextInitializers, final Map<String, Object> credentialHandlerProperties, @SuppressWarnings("rawtypes") final Set<Class<? extends CredentialHandler>> credentialHandlers, final boolean supportsAttribute, final boolean supportsCredential) {
    super(supportedTypes, unsupportedTypes, contextInitializers, credentialHandlerProperties, credentialHandlers, supportsAttribute, supportsCredential);
  }

  @Override
  protected void initConfig() {
  }

}

SamplePartitionStoreConfigurationBuilder.java

import org.picketlink.idm.config.IdentityStoreConfigurationBuilder;
import org.picketlink.idm.config.IdentityStoresConfigurationBuilder;

public final class SamplePartitionStoreConfigurationBuilder extends IdentityStoreConfigurationBuilder<SamplePartitionStoreConfiguration, SamplePartitionStoreConfigurationBuilder> {

  public SamplePartitionStoreConfigurationBuilder(final IdentityStoresConfigurationBuilder builder) {
    super(builder);
  }

  @Override
  protected SamplePartitionStoreConfiguration create() {
    return null;
  }

}

A sample is available here.