Package org.apache.catalina

Examples of org.apache.catalina.Session


                           boolean canCreate, boolean access)
         throws Exception
   {
      //    Shift to Manager interface when we simulate Tomcat
      Manager mgr = dspm;
      Session sess = mgr.findSession(id);
      assertNull("session does not exist", sess);
      try
      {
         sess = mgr.createSession(id);
         if (!canCreate)
            fail("Could not create session" + id);
      }
      catch (IllegalStateException ise)
      {
         if (canCreate)
         {
            log.error("Failed to create session " + id, ise);
            fail("Could create session " + id);
         }
      }
     
      if (access)
      {
         sess.access();
         sess.getSession().setAttribute("test", "test");
        
         dspm.storeSession(sess);
        
         sess.endAccess();
      }
     
      return sess;
   }
View Full Code Here


   private Session useSession(DataSourcePersistentManager dspm, String id)
         throws Exception
   {
      //    Shift to Manager interface when we simulate Tomcat
      Manager mgr = dspm;
      Session sess = mgr.findSession(id);
      assertNotNull("session exists", sess);
     
      sess.access();
      sess.getSession().setAttribute("test", "test");
     
      dspm.storeSession(sess);
     
      sess.endAccess();
     
      return sess;
   }
View Full Code Here

   {
      request.setAuthType(AUTH_TYPE);
      request.setUserPrincipal(principal);

      //Cache the authentication principal in the session
      Session session = request.getSessionInternal(false);
      if (session != null)
      {
         session.setAuthType(AUTH_TYPE);
         session.setPrincipal(principal);
         if (username != null)
            session.setNote(Constants.SESS_USERNAME_NOTE, username);
         else
            session.removeNote(Constants.SESS_USERNAME_NOTE);
         if (password != null)
            session.setNote(Constants.SESS_PASSWORD_NOTE, getPasswordAsString(password));
         else
            session.removeNote(Constants.SESS_PASSWORD_NOTE);
      }

      // JBAS-4424: Programmatic web authentication with SSO
      SingleSignOn sso = this.getSingleSignOn(request);
      if (sso == null)
View Full Code Here

   {
      request.setAuthType(null);
      request.setUserPrincipal(null);

      // Cache the authentication principal in the session.
      Session session = request.getSessionInternal(false);
      if (session != null)
      {
         session.setAuthType(null);
         session.setPrincipal(null);
         session.removeNote(Constants.SESS_USERNAME_NOTE);
         session.removeNote(Constants.SESS_PASSWORD_NOTE);
      }
      // Unregister the SSOID.
      SingleSignOn sso = this.getSingleSignOn(request);
      if (sso != null)
      {
View Full Code Here

  
      Realm realm = context.getRealm();
      /**
       * You can get the userid/credential from the header
       */
      Session session = request.getSessionInternal(true);
      String username = request.getHeader("JBOSS_TEST_USER_NAME");
      String password = request.getHeader("JBOSS_TEST_CREDENTIAL");
      log.debug("Test UserName =" + username);
      log.debug("Test cred present?:" + (password != null));
      Principal principal = realm.authenticate(username,password);
      if(principal == null)
      {
         response.sendError(HttpServletResponse.SC_FORBIDDEN);
         return false;
      }
        
      //Save the authenticated Principal in our session
      session.setNote(Constants.SESS_USERNAME_NOTE, principal);
      request.setUserPrincipal(principal);
      return true;
   }
View Full Code Here

     
      manager.start();
      stopManager = true;
     
      // Set up a session
      Session sess1 = createAndUseSession(manager, "1", true, true);     
      Session sess2 = createAndUseSession(manager, "2", true, true);
     
      // Sanity check
      Session[] sessions = manager.findSessions();
      assertNotNull(sessions);
      assertEquals(2, sessions.length);
     
      manager.stop();
      stopManager = false;
     
      assertNull(manager.findSession("1"));
      assertNull(manager.findSession("2"));
      assertNull(manager.findSessions());
      assertNull(manager.createEmptySession());
      assertNull(manager.createSession());
      assertNull(manager.createSession("3"));
     
      assertFalse(sess1.isValid());
      assertFalse(sess2.isValid());
      manager.add(sess1); // shouldn't blow up
      assertFalse(sess1.isValid());
     
      manager.remove(sess2);
   }
View Full Code Here

  
   private Session createAndUseSession(JBossCacheManager<?> manager, String id, boolean canCreate, boolean access) throws Exception
   {
      //    Shift to Manager interface when we simulate Tomcat
      Manager mgr = manager;
      Session sess = mgr.findSession(id);
      assertNull("session does not exist", sess);
      try
      {
         sess = mgr.createSession(id);
         if (!canCreate)
            fail("Could not create session" + id);
      }
      catch (IllegalStateException ise)
      {
         if (canCreate)
         {
            log.error("Failed to create session " + id, ise);
            fail("Could create session " + id);
         }
      }
     
      if (access)
      {
         sess.access();
         sess.getSession().setAttribute("test", "test");
        
         manager.storeSession(sess);
        
         sess.endAccess();
      }
     
      return sess;
   }
View Full Code Here

   }

   public void invoke(Request request, Response response)
           throws IOException, ServletException
   {
      Session session = null;
      // Get the request caller which could be set due to SSO
      Principal caller = request.getPrincipal();
      // The cached web container principal
      JBossGenericPrincipal principal = null;
      HttpSession hsession = request.getSession(false);

      if( trace )
         log.trace("Begin invoke, caller="+caller);
     
      try
      {
         Wrapper servlet = null;
         try
         {
            servlet = request.getWrapper();
            if (servlet != null)
            {
               String name = servlet.getName();
               RunAsIdentityMetaData identity = metaData.getRunAsIdentity(name);
               RunAsIdentity runAsIdentity = null;
               if(identity != null)
               {
                  if (trace)
                     log.trace(name + ", runAs: " + identity);
                  runAsIdentity = new RunAsIdentity(identity.getRoleName(),
                        identity.getPrincipalName(), identity.getRunAsRoles());
               }
               SecurityAssociationActions.pushRunAsIdentity(runAsIdentity);
            }
            userPrincipal.set(caller);

            // If there is a session, get the tomcat session for the principal
            Manager manager = container.getManager();
            if (manager != null && hsession != null)
            {
               try
               {
                  session = manager.findSession(hsession.getId());
               }
               catch (IOException ignore)
               {
               }
            }

            if (caller == null || (caller instanceof JBossGenericPrincipal) == false)
            {
               // Look to the session for the active caller security context
               if (session != null)
               {
                  principal =
                     (JBossGenericPrincipal) session.getPrincipal();
               }
            }
            else
            {
               // Use the request principal as the caller identity
               principal = (JBossGenericPrincipal) caller;
            }

            // If there is a caller use this as the identity to propagate
            if (principal != null)
            {
               if (trace)
                  log.trace("Restoring principal info from cache");
               SecurityAssociationActions.setPrincipalInfo(principal.getAuthPrincipal(),
                  principal.getCredentials(), principal.getSubject())
            }
            // Put the authenticated subject in the session if requested
            if (subjectAttributeName != null)
            {
               javax.naming.Context securityNamingCtx = getSecurityNamingContext();
               if (securityNamingCtx != null)
               {
                  // Get the JBoss security manager from the ENC context
                  AuthenticationManager securityMgr = (AuthenticationManager) securityNamingCtx.lookup("securityMgr");
                  Subject subject = securityMgr.getActiveSubject();
                  request.getRequest().setAttribute(subjectAttributeName, subject);
               }
            }
         }
         catch (Throwable e)
         {
            log.debug("Failed to determine servlet", e);
         }
        
         // Perform the request
         getNext().invoke(request, response);
         if(servlet != null)
         {
            SecurityAssociationActions.popRunAsIdentity();
         }

         /* If the security domain cache is to be kept in synch with the
         session then flush the cache if the session has been invalidated.
         */
         if( secMgrService != null &&
            session != null && session.isValid() == false &&
            metaData.isFlushOnSessionInvalidation() == true )
         {
            if( principal != null )
            {
               String securityDomain = metaData.getSecurityDomain();
View Full Code Here

   }

   public void event(Request request, Response response, HttpEvent event)
      throws IOException, ServletException
   {
      Session session = null;
      // Get the request caller which could be set due to SSO
      Principal caller = request.getPrincipal();
      // The cached web container principal
      JBossGenericPrincipal principal = null;
      HttpSession hsession = request.getSession(false);
     
      if( trace )
         log.trace("Begin invoke, caller="+caller);
     
      try
      {
         Wrapper servlet = null;
         try
         {
            servlet = request.getWrapper();
            if (servlet != null)
            {
               String name = servlet.getName();
               RunAsIdentityMetaData identity = metaData.getRunAsIdentity(name);
               RunAsIdentity runAsIdentity = null;
               if(identity != null)
               {
                  if (trace)
                     log.trace(name + ", runAs: " + identity);
                  runAsIdentity = new RunAsIdentity(identity.getRoleName(),
                        identity.getPrincipalName(), identity.getRunAsRoles());
               }
               SecurityAssociationActions.pushRunAsIdentity(runAsIdentity);
            }
            userPrincipal.set(caller);
           
            // If there is a session, get the tomcat session for the principal
            Manager manager = container.getManager();
            if (manager != null && hsession != null)
            {
               try
               {
                  session = manager.findSession(hsession.getId());
               }
               catch (IOException ignore)
               {
               }
            }
           
            if (caller == null || (caller instanceof JBossGenericPrincipal) == false)
            {
               // Look to the session for the active caller security context
               if (session != null)
               {
                  principal =
                     (JBossGenericPrincipal) session.getPrincipal();
               }
            }
            else
            {
               // Use the request principal as the caller identity
               principal = (JBossGenericPrincipal) caller;
            }
           
            // If there is a caller use this as the identity to propagate
            if (principal != null)
            {
               if (trace)
                  log.trace("Restoring principal info from cache");
               SecurityAssociationActions.setPrincipalInfo(principal.getAuthPrincipal(),
                     principal.getCredentials(), principal.getSubject())
            }
            // Put the authenticated subject in the session if requested
            if (subjectAttributeName != null)
            {
               javax.naming.Context securityNamingCtx = getSecurityNamingContext();
               if (securityNamingCtx != null)
               {
                  // Get the JBoss security manager from the ENC context
                  AuthenticationManager securityMgr = (AuthenticationManager) securityNamingCtx.lookup("securityMgr");
                  Subject subject = securityMgr.getActiveSubject();
                  request.getRequest().setAttribute(subjectAttributeName, subject);
               }
            }
         }
         catch (Throwable e)
         {
            log.debug("Failed to determine servlet", e);
         }
        
         // Perform the request
         getNext().event(request, response, event);
         if(servlet != null)
         {
            SecurityAssociationActions.popRunAsIdentity();
         }
        
         /* If the security domain cache is to be kept in synch with the
    session then flush the cache if the session has been invalidated.
          */
         if( secMgrService != null &&
               session != null && session.isValid() == false &&
               metaData.isFlushOnSessionInvalidation() == true )
         {
            if( principal != null )
            {
               String securityDomain = metaData.getSecurityDomain();
View Full Code Here

                // that the top level request is the only one which can
                // create the cookie safely
                other = super.getSession(true);
            }
            if (other != null) {
                Session localSession = null;
                try {
                    localSession =
                        context.getManager().findSession(other.getId());
                    if (localSession != null && !localSession.isValid()) {
                        localSession = null;
                    }
                } catch (IOException e) {
                    // Ignore
                }
                if (localSession == null && create) {
                    localSession =
                        context.getManager().createSession(other.getId());
                }
                if (localSession != null) {
                    localSession.access();
                    session = localSession;
                    return session.getSession();
                }
            }
            return null;
View Full Code Here

TOP

Related Classes of org.apache.catalina.Session

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.