Package org.orgama.shared.auth.model

Examples of org.orgama.shared.auth.model.AuthSession


   * @return
   */
  @Override
  public AuthSession create(AuthUser user, AuthInitialization AuthInit) {
   
    AuthSession result = new AuthSession();
    Date expirationDate = new Date((new Date()).getTime() +
        1000L * 3600L * 24L * 30L);
   
    result.setUserId(user.getUserId());
    result.setAuthServiceName(user.getAuthServiceName());
    result.setExpirationDate(expirationDate);
    result.setServiceSpecificSessionId(
        AuthInit.getServiceSpecificSessionId());
   
    boolean success = false;
   
    for (int i = 0; i < 10; i++) {
      result.setSessionId(createSessionIdString());
      try {
        Ofy.save().entity(result);
        success = true;
        break;
      }
      catch(Exception ex) {
        Logger.warn("Error saving auth session", ex);
        //happens on duplicate session id (not often)
      }
    }
   
    if (!success) {
      throw new AuthException("Failed to create auth session");
    }
   
    HttpSession session = sessionProvider.get();
    ICookieHandler cookieHandler = cookieHandlerProvider.get();
    session.setAttribute(serverSideConstants.getAuthSessionKey(), result);
    cookieHandler.setValue(serverSideConstants.getSessionCookieName(),
        result.getSessionId(), expirationDate);
   
    return result;
  }
View Full Code Here


  /**
   * Close the current session
   */
  @Override
  public void closeCurrent() {
    AuthSession session = get();
    if (session != null) {
      close(session);
    }
  }
View Full Code Here

    assertNull(asp.get());
    String tempSessionId = "Hello";

    {
      AuthSession tempSession = new AuthSession();
      tempSession.setSessionId(tempSessionId);
      tempSession.setExpirationDate(new Date(
          new Date().getTime() + 1000000));
      cookieHandler.setValue(constants.getSessionCookieName(),
          tempSessionId);
      httpSession.setAttribute(
          constants.getAuthSessionKey(), tempSession);
    }

    //Verify that getting the auth session from the http session returns
    //an equivalent object.  Because the http session serializes, the
    //pointers will not be the same
    AuthSession authSession = asp.get();
    assertNotNull(authSession);
    assertEquals(tempSessionId, authSession.getSessionId());

  }
View Full Code Here

  public void testGettingAnAuthSessionFromDatastore() {
    assertNull(asp.get());
    String tempSessionId = "YoYoYo";

    {
      AuthSession tempSession = new AuthSession();
      tempSession.setSessionId(tempSessionId);
      tempSession.setExpirationDate(new Date(
          new Date().getTime() + 1000000));
      Ofy.save().entity(tempSession).now();
      cookieHandler.setValue(constants.getSessionCookieName(),
          tempSessionId);
    }

    //Verify that getting the auth session from the http session returns
    //an equivalent object.  Because the http session serializes, the
    //pointers will not be the same
    AuthSession authSession = asp.get();
    assertNotNull(authSession);
    assertEquals(tempSessionId, authSession.getSessionId());

    //Reset the auth session provider so that it will not just return the
    //same sessions.  and remove the session from the datastore.  This will
    //test whether the same session once retrieved from the datastore can
    //be retrieved again from the session.
    Ofy.delete().entity(authSession).now();

    AuthSession authSessionFromHttpSession = asp.get();
    assertNotNull(authSessionFromHttpSession);
    assertNotSame(authSession, authSessionFromHttpSession);
    assertEquals(tempSessionId, authSessionFromHttpSession.getSessionId());

  }
View Full Code Here

    assertNull(asp.get());
    String tempSessionId = "Hello";

    {
      AuthSession tempSession = new AuthSession();
      tempSession.setSessionId(tempSessionId);
      tempSession.setExpirationDate(new Date(
          new Date().getTime() - 1000000));
      cookieHandler.setValue(constants.getSessionCookieName(),
          tempSessionId);
      httpSession.setAttribute(
          constants.getAuthSessionKey(), tempSession);
View Full Code Here

    assertNull(asp.get());
    String tempSessionId = "Helllfldfld";

    {
      AuthSession tempSession = new AuthSession();
      tempSession.setSessionId(tempSessionId);
      tempSession.setExpirationDate(
          new Date(new Date().getTime() - 1000000));

      cookieHandler.setValue(constants.getSessionCookieName(),
          tempSessionId);
      Ofy.save().entity(tempSession).now();
View Full Code Here

    assertNull(asp.get());
    String tempSessionId = "asdfasdfasdf";

    {
      AuthSession tempSession = new AuthSession();
      tempSession.setSessionId(tempSessionId);
      tempSession.setExpirationDate(
          new Date(new Date().getTime() - 1000000));

      cookieHandler.setValue(constants.getSessionCookieName(),
          tempSessionId);
      //Don't save the auth session in the datastore, so the session id
View Full Code Here

    assertNull(asp.get());
    String tempSessionId = "ThisIsRight";
    String wrongSessionId = "ThisIsWrong";

    {
      AuthSession tempSession = new AuthSession();
      tempSession.setSessionId(tempSessionId);
      tempSession.setExpirationDate(
          new Date(new Date().getTime() + 1000000));

      cookieHandler.setValue(constants.getSessionCookieName(),
          wrongSessionId);
      httpSession.setAttribute(constants.getAuthSessionKey(),
View Full Code Here

   */
  public CompleteAuthState bootstrap() {
    CompleteAuthState result = new CompleteAuthState();
   
    try {
      AuthSession authSession = null;
     
      // Try to get the existing auth session.  While bootstrapping,
      // errors in this step will lead to resetting of the auth process
      try {
        authSession = authSessionService.get();
      }
      catch(AuthException ax) {
        Logger.error("Authentication error while trying to get auth " +
            "session.  Reseting auth system in clean state", ax);
        authSystemCleanerProvider.get().clean();
      }
     
      if (authSession != null) {
        result.setAuthState(AuthState.authenticated);
        result.setAuthServiceName(authSession.getAuthServiceName());
        return result;
      }
     
      //Reaching this step means there was no existing auth session. 
      //In stead get the auth initialization
View Full Code Here

   
    String sessionId = "asdfasdfasdfasdfa";
   
    {
      AuthInitialization ai = authInitializationProvider.get();
      AuthSession as = new AuthSession();

      as.setExpirationDate(new Date(new Date().getTime() + 1000000));
      as.setSessionId(sessionId);
      as.setUserId(1);

      Ofy.save().entity(as).now();
     
      cookieHandler.setValue(constants.getSessionCookieName(), sessionId);
     
View Full Code Here

TOP

Related Classes of org.orgama.shared.auth.model.AuthSession

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.