Example #1
0
  public void initialize() {
    log.debug("testing=" + isTesting());

    if (identity.isLoggedIn()) {
      log.debug("authenticated");
      // raiseLoginSuccessfulEvent();
      // return "authenticated";
    }

    if (isTesting()) {
      identity.logout();
      log.debug("not-authenticated");
      // return "testing";
    }

    /*
    if (username == null) {
    	ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    	HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    	username = request.getHeader("ARIES_USER");
    }
    */

    if (username == null) {
      log.debug("not-authenticated");
      // return "not-authenticated";
    }

    //		try {
    //			credentials.setUsername(username);
    //			credentials.setInitialized(true);
    //			SimplePrincipal principal = new SimplePrincipal(username);
    //			identity.acceptExternallyAuthenticatedPrincipal(principal);
    //			rememberMe.setEnabled(true);
    //		} catch (Exception e) {
    //			log.error("Error", e);
    //			return "";
    //		}

    log.info("logged in user: "******"logged in user: "******"Super-user: "******"authenticated");
    // raiseLoginSuccessfulEvent();
    // return "authenticated";
  }
  @Test
  public void testLoginComponent() throws Exception {
    Identity identity = Identity.instance();

    assertFalse(identity.isLoggedIn());
    identity.setUsername("gavin");
    identity.setPassword("foobar");
    identity.login();

    User user = (User) Component.getInstance("user");
    assertEquals("Gavin King", user.getName());
    assertEquals("gavin", user.getUsername());
    assertEquals("foobar", user.getPassword());
    assertTrue(identity.isLoggedIn());
    identity.logout();
    assertFalse(identity.isLoggedIn());
    identity.setUsername("gavin");
    identity.setPassword("tiger");
    identity.login();
    assertFalse(identity.isLoggedIn());
  }
  @Test
  public void testLogin() throws Exception {
    Identity identity = Identity.instance();

    assertFalse(identity.isLoggedIn());

    identity.setUsername("gavin");
    identity.setPassword("foobar");
    identity.login();

    User user = (User) Component.getInstance("user");
    assertEquals("Gavin King", user.getName());
    assertEquals("gavin", user.getUsername());
    assertEquals("foobar", user.getPassword());
    assertFalse(Manager.instance().isLongRunningConversation());
    assertTrue(identity.isLoggedIn());

    identity.logout();
    assertTrue(Session.instance().isInvalid());

    assertFalse(identity.isLoggedIn());
  }