Package org.exoplatform.services.security

Examples of org.exoplatform.services.security.ConversationState


         }
      }

      public boolean hasEditPermission(PortalConfig portal)
      {
         ConversationState.setCurrent(new ConversationState(identity));
         try
         {
            return ua.hasEditPermission(portal);
         }
         finally
View Full Code Here


         }
      }

      public boolean hasCreatePortalPermission()
      {
         ConversationState.setCurrent(new ConversationState(identity));
         try
         {
            return ua.hasCreatePortalPermission();
         }
         finally
View Full Code Here

         throw new LoginException(
            "Credentials for the authentication should be CredentialsImpl or SimpleCredentials type");

      SessionFactory sessionFactory = (SessionFactory)container.getComponentInstanceOfType(SessionFactory.class);

      ConversationState newState =
         new ConversationState(new Identity(name, userState.getIdentity().getMemberships(), userState.getIdentity()
            .getRoles()));
      return sessionFactory.createSession(newState);

   }
View Full Code Here

   {

      if (getState() == OFFLINE)
         LOG.warn("Repository " + getName() + " is OFFLINE.");

      ConversationState state;

      PrivilegedExceptionAction<ConversationState> action = new PrivilegedExceptionAction<ConversationState>()
      {
         public ConversationState run() throws Exception
         {
View Full Code Here

            "Credentials for the authentication should be CredentialsImpl or SimpleCredentials type");
      }

      SessionFactory sessionFactory = (SessionFactory)container.getComponentInstanceOfType(SessionFactory.class);

      ConversationState newState =
         new ConversationState(new Identity(name, userState.getIdentity().getMemberships(), userState.getIdentity()
            .getRoles()));
      return sessionFactory.createSession(newState);

   }
View Full Code Here

      ConversationRegistry conversationRegistry =
         (ConversationRegistry)getContainer(httpSession.getServletContext()).getComponentInstanceOfType(
            ConversationRegistry.class);

      ConversationState conversationState = conversationRegistry.unregister(stateKey);

      if (conversationState != null)
         if (log.isDebugEnabled())
            log.debug("Remove conversation state " + httpSession.getId());
View Full Code Here

      ExoContainer container = getContainer();

      try
      {
         ExoContainerContext.setCurrentContainer(container);
         ConversationState state = getCurrentState(container, httpRequest);
         ConversationState.setCurrent(state);
         chain.doFilter(request, response);
      }
      finally
      {
View Full Code Here

         (ConversationRegistry)container.getComponentInstanceOfType(ConversationRegistry.class);

      IdentityRegistry identityRegistry =
         (IdentityRegistry)container.getComponentInstanceOfType(IdentityRegistry.class);

      ConversationState state = null;
      String userId = httpRequest.getRemoteUser();

      // only if user authenticated, otherwise there is no reason to do anythings
      if (userId != null)
      {
         HttpSession httpSession = httpRequest.getSession();
         StateKey stateKey = new HttpSessionStateKey(httpSession);

         if (log.isDebugEnabled())
         {
            log.debug("Looking for Conversation State " + httpSession.getId());
         }

         state = conversationRegistry.getState(stateKey);

         if (state == null)
         {
            if (log.isDebugEnabled())
            {
               log.debug("Conversation State not found, try create new one.");
            }

            Identity identity = identityRegistry.getIdentity(userId);
            if (identity != null)
            {
               state = new ConversationState(identity);
               // Keep subject as attribute in ConversationState.
               // TODO remove this, do not need it any more.
               state.setAttribute(ConversationState.SUBJECT, identity.getSubject());
            }
            else
            {
               if (restoreIdentity)
               {
                  if (log.isDebugEnabled())
                  {
                     log.debug("Not found identity for " + userId + " try to restore it. ");
                  }

                  Authenticator authenticator =
                     (Authenticator)container.getComponentInstanceOfType(Authenticator.class);
                  try
                  {
                     identity = authenticator.createIdentity(userId);
                     identityRegistry.register(identity);
                  }
                  catch (Exception e)
                  {
                     log.error("Unable restore identity. " + e.getMessage(), e);
                  }

                  if (identity != null)
                  {
                     state = new ConversationState(identity);
                  }
               }
               else
               {
                  log.error("Not found identity in IdentityRegistry for user " + userId + ", check Login Module.");
               }
            }

            if (state != null)
            {
               conversationRegistry.register(stateKey, state);
               if (log.isDebugEnabled())
               {
                  log.debug("Register Conversation state " + httpSession.getId());
               }
            }
         }
      }
      else
      {
         state = new ConversationState(new Identity(IdentityConstants.ANONIM));
      }
      return state;
   }
View Full Code Here

      {
         ExoContainer container = getContainer(httpSession.getServletContext());
         ConversationRegistry conversationRegistry =
            (ConversationRegistry)container.getComponentInstanceOfType(ConversationRegistry.class);

         ConversationState conversationState = conversationRegistry.unregister(stateKey);

         if (conversationState != null)
         {
            if (log.isDebugEnabled())
               log.debug("Remove conversation state " + httpSession.getId());
            if (conversationState.getAttribute(ConversationState.SUBJECT) != null)
            {
               Subject subject = (Subject)conversationState.getAttribute(ConversationState.SUBJECT);
               String realmName =
                  container instanceof PortalContainer ? ((PortalContainer)container).getRealmName()
                     : PortalContainer.DEFAULT_REALM_NAME;
               LoginContext ctx = new LoginContext(realmName, subject);
               ctx.logout();
View Full Code Here

      // SYSTEM
      if (thisCredentials.getUserID().equals(SystemIdentity.SYSTEM))
      {
         Identity sid = new Identity(SystemIdentity.SYSTEM, new HashSet<MembershipEntry>());
         return new ConversationState(sid);
      }

      // prepare to new login
      // uses BasicCallbackHandler
      CallbackHandler handler = new BasicCallbackHandler(thisCredentials.getUserID(), thisCredentials.getPassword());

      // and try to login
      try
      {

         LoginContext loginContext = new LoginContext(config.getSecurityDomain(), handler);
         loginContext.login();

      }
      catch (javax.security.auth.login.LoginException e)
      {
         throw new LoginException("Login failed for " + thisCredentials.getUserID() + " " + e);
      }

      if (log.isDebugEnabled())
         log.debug("Logged " + thisCredentials.getUserID());

      // supposed to be set
      Identity identity = identityRegistry.getIdentity(thisCredentials.getUserID());
      if (identity == null)
      {
         throw new LoginException("Identity not found, check Loginmodule, userId " + thisCredentials.getUserID());
      }
      ConversationState state = new ConversationState(identity);
      String[] aNames = thisCredentials.getAttributeNames();
      for (String name : aNames)
      {
         state.setAttribute(name, thisCredentials.getAttribute(name));
      }

      ConversationState.setCurrent(state);
      return state;
View Full Code Here

TOP

Related Classes of org.exoplatform.services.security.ConversationState

Copyright © 2018 www.massapicom. 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.