Package org.jboss.identity.idm.impl.api.session

Source Code of org.jboss.identity.idm.impl.api.session.IdentitySessionImpl

/*
* JBoss, a division of Red Hat
* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.identity.idm.impl.api.session;

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

import org.jboss.identity.idm.api.IdentitySession;
import org.jboss.identity.idm.api.Transaction;
import org.jboss.identity.idm.api.PersistenceManager;
import org.jboss.identity.idm.api.RelationshipManager;
import org.jboss.identity.idm.api.AttributesManager;
import org.jboss.identity.idm.api.RoleManager;
import org.jboss.identity.idm.api.User;
import org.jboss.identity.idm.api.Group;
import org.jboss.identity.idm.api.Role;
import org.jboss.identity.idm.api.query.UserQuery;
import org.jboss.identity.idm.api.query.GroupQuery;
import org.jboss.identity.idm.api.query.RoleQuery;
import org.jboss.identity.idm.api.query.UserQueryBuilder;
import org.jboss.identity.idm.api.query.GroupQueryBuilder;
import org.jboss.identity.idm.api.query.RoleQueryBuilder;
import org.jboss.identity.idm.api.query.QueryException;
import org.jboss.identity.idm.common.exception.IdentityException;
import org.jboss.identity.idm.common.exception.FeatureNotSupportedException;
import org.jboss.identity.idm.spi.store.IdentityStoreSession;
import org.jboss.identity.idm.spi.store.IdentityStoreInvocationContext;
import org.jboss.identity.idm.spi.repository.IdentityStoreRepository;
import org.jboss.identity.idm.impl.store.SimpleIdentityStoreInvocationContext;
import org.jboss.identity.idm.impl.api.session.context.IdentitySessionContext;
import org.jboss.identity.idm.impl.api.session.context.IdentitySessionContextImpl;
import org.jboss.identity.idm.impl.api.session.context.IdentityStoreInvocationContextResolver;
import org.jboss.identity.idm.impl.api.session.mapper.IdentityObjectTypeMapper;
import org.jboss.identity.idm.impl.api.session.managers.PersistenceManagerImpl;
import org.jboss.identity.idm.impl.api.session.managers.RelationshipManagerImpl;
import org.jboss.identity.idm.impl.api.session.managers.AttributesManagerImpl;
import org.jboss.identity.idm.impl.api.session.managers.RoleManagerImpl;
import org.jboss.identity.idm.impl.api.session.SimpleTransactionImpl;
import org.jboss.identity.idm.impl.api.query.UserQueryImpl;
import org.jboss.identity.idm.impl.api.query.GroupQueryImpl;
import org.jboss.identity.idm.impl.api.query.RoleQueryImpl;
import org.jboss.identity.idm.impl.api.query.UserQueryExecutorImpl;
import org.jboss.identity.idm.impl.api.query.GroupQueryExecutorImpl;
import org.jboss.identity.idm.impl.api.query.RoleQueryExecutorImpl;
import org.jboss.identity.idm.impl.api.query.UserQueryBuilderImpl;
import org.jboss.identity.idm.impl.api.query.GroupQueryBuilderImpl;
import org.jboss.identity.idm.impl.api.query.RoleQueryBuilderImpl;

/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw Dawidowicz</a>
* @version : 0.1 $
*/
public class IdentitySessionImpl implements IdentitySession, Serializable
{

   private static final long serialVersionUID = 7615238887627699243L;

   private final String realmName;

   private final IdentitySessionContext sessionContext;

   private final PersistenceManager persistenceManager;

   private final RelationshipManager relationshipManager;

   private final AttributesManager profileManager;

   private final RoleManager roleManager;

   private final UserQueryExecutorImpl userQueryExecutor;

   private final GroupQueryExecutorImpl groupQueryExecutor;

   private final RoleQueryExecutorImpl roleQueryExecutor;

   public IdentitySessionContext getSessionContext()
   {
      return sessionContext;
   }

   public IdentitySessionImpl(String realmName,
                              IdentityStoreRepository repository,
                              IdentityObjectTypeMapper typeMapper) throws IdentityException
   {
      this.realmName = realmName;

      IdentityStoreSession storeSession = repository.createIdentityStoreSession();
      final IdentityStoreInvocationContext invocationCtx = new SimpleIdentityStoreInvocationContext(storeSession, realmName);

      IdentityStoreInvocationContextResolver resolver = new IdentityStoreInvocationContextResolver()
      {
         public IdentityStoreInvocationContext resolveInvocationContext()
         {
            return invocationCtx;
         }
      };

      sessionContext = new IdentitySessionContextImpl(repository, typeMapper, resolver);

      this.persistenceManager = new PersistenceManagerImpl(this);
      this.relationshipManager = new RelationshipManagerImpl(this);
      this.profileManager = new AttributesManagerImpl(this);
      this.roleManager = new RoleManagerImpl(this);
      this.userQueryExecutor = new UserQueryExecutorImpl(this);
      this.groupQueryExecutor = new GroupQueryExecutorImpl(this);
      this.roleQueryExecutor = new RoleQueryExecutorImpl(this);


   }





   public String getRealmName()
   {
      return realmName;
   }

   public void close() throws IdentityException
   {
      sessionContext.resolveStoreInvocationContext().getIdentityStoreSession().close();
   }

   public void save() throws IdentityException
   {
      sessionContext.resolveStoreInvocationContext().getIdentityStoreSession().save();
   }

   public void clear() throws IdentityException
   {
      sessionContext.resolveStoreInvocationContext().getIdentityStoreSession().clear();
   }

   public boolean isOpen()
   {

      return sessionContext.resolveStoreInvocationContext().getIdentityStoreSession().isOpen();
   }

   public Transaction beginTransaction()
   {
      Transaction transaction = new SimpleTransactionImpl(sessionContext.resolveStoreInvocationContext().getIdentityStoreSession());
      transaction.start();
      return transaction;
   }

   public Transaction getTransaction()
   {
      return new SimpleTransactionImpl(sessionContext.resolveStoreInvocationContext().getIdentityStoreSession());
   }

   public PersistenceManager getPersistenceManager()
   {
      return persistenceManager;
   }

   public RelationshipManager getRelationshipManager()
   {
      return relationshipManager;
   }

   public AttributesManager getAttributesManager()
   {
      return profileManager;
   }

   public RoleManager getRoleManager() throws FeatureNotSupportedException
   {
      if (!getSessionContext().getIdentityStoreRepository().getSupportedFeatures().isNamedRelationshipsSupported())
      {
         throw new FeatureNotSupportedException("Role management not supported by underlaying configured identity stores");
      }

      return roleManager;
   }

   public UserQueryBuilder createUserQueryBuilder()
   {
      return new UserQueryBuilderImpl();

   }

   public GroupQueryBuilder createGroupQueryBuilder()
   {
      return new GroupQueryBuilderImpl();

   }

   public RoleQueryBuilder createRoleQueryBuilder() throws FeatureNotSupportedException
   {
      if (!getSessionContext().getIdentityStoreRepository().getSupportedFeatures().isNamedRelationshipsSupported())
      {
         throw new FeatureNotSupportedException("Role management not supported by underlaying configured identity stores");
      }

      return new RoleQueryBuilderImpl();
   }

   public Collection<User> execute(UserQuery userQuery) throws QueryException
   {
      return userQueryExecutor.execute((UserQueryImpl)userQuery);
   }

   public User uniqueResult(UserQuery userQuery) throws QueryException
   {
      return userQueryExecutor.uniqueResult((UserQueryImpl)userQuery);
   }

   public List<User> list(UserQuery userQuery) throws QueryException
   {
      return userQueryExecutor.list((UserQueryImpl)userQuery);
   }

   public Collection<Group> execute(GroupQuery groupQuery) throws QueryException
   {
      return groupQueryExecutor.execute((GroupQueryImpl)groupQuery);
   }

   public Group uniqueResult(GroupQuery groupQuery) throws QueryException
   {
      return groupQueryExecutor.uniqueResult((GroupQueryImpl)groupQuery);
   }

   public List<Group> list(GroupQuery groupQuery) throws QueryException
   {
      return groupQueryExecutor.list((GroupQueryImpl)groupQuery);
   }

   public Collection<Role> execute(RoleQuery roleQuery) throws QueryException
   {
      return roleQueryExecutor.execute((RoleQueryImpl)roleQuery);
   }

   public Role uniqueResult(RoleQuery roleQuery) throws QueryException
   {
      return roleQueryExecutor.uniqueResult((RoleQueryImpl)roleQuery);
   }

   public List<Role> list(RoleQuery roleQuery) throws QueryException
   {
      return roleQueryExecutor.list((RoleQueryImpl)roleQuery);
   }
}
TOP

Related Classes of org.jboss.identity.idm.impl.api.session.IdentitySessionImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.