Package com.google.enterprise.connector.spi

Examples of com.google.enterprise.connector.spi.AuthenticationResponse


  }

  public void testGroupLookup_only() throws Exception {
    groupSetUp();

    AuthenticationResponse result =
        authentManager.authenticate(new SimpleAuthenticationIdentity(
            DmInitialize.DM_LOGIN_OK1, null));
    assertTrue(result.isValid());
    Collection<?> groups = result.getGroups();
    assertEquals(ImmutableList.of("grp1", "grp2", "grp3", "dm_world"),
        toStrings(groups));
  }
View Full Code Here


  }

  public void testGroupLookup_badUser() throws Exception {
    groupSetUp();

    AuthenticationResponse result =
        authentManager.authenticate(new SimpleAuthenticationIdentity(
            DmInitialize.DM_LOGIN_KO, null));
    assertFalse(result.isValid());
  }
View Full Code Here

  }

  public void testGroupLookup_authentication() throws Exception {
    groupSetUp();

    AuthenticationResponse result =
        authentManager.authenticate(new SimpleAuthenticationIdentity(
            DmInitialize.DM_LOGIN_OK1, DmInitialize.DM_PWD_OK1));
    assertTrue(result.isValid());
    Collection<?> groups = result.getGroups();
    assertEquals(ImmutableList.of("grp1", "grp2", "grp3", "dm_world"),
        toStrings(groups));
  }
View Full Code Here

  }

  public void testGroupLookup_onlyWorld() throws Exception {
    groupSetUp();

    AuthenticationResponse result =
        authentManager.authenticate(new SimpleAuthenticationIdentity(
            DmInitialize.DM_LOGIN_OK2, DmInitialize.DM_PWD_OK2));
    assertTrue(result.isValid());
    Collection<?> groups = result.getGroups();
    assertEquals(ImmutableList.of("dm_world"), toStrings(groups));
  }
View Full Code Here

   * Helper method tests group lookup only and verifies that the given
   * groups (along with dm_world) are returned for the user.
   */
  private void testGroupLookup(String user, String domain,
      String... expectedGroups) throws Exception {
    AuthenticationResponse result = authentManager.authenticate(
        new SimpleAuthenticationIdentity(user, null, domain));
    assertTrue(result.isValid());
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    assertEquals(builder.add(expectedGroups).add("dm_world").build(),
        toStrings(result.getGroups()));
  }
View Full Code Here

  }

  /** Helper method tests group lookup only and verifies that it fails. */
  private void testGroupLookupFail(String user, String domain)
      throws Exception {
    AuthenticationResponse result = authentManager.authenticate(
        new SimpleAuthenticationIdentity(user, null, domain));
    assertFalse(result.isValid());
  }
View Full Code Here

  private void testParentDomainFail(String user, String domain)
      throws Exception {
    insertUser("aceuser", "ldapuser", "LDAP",
        "CN=LDAP User,dc=ace,dc=example,dc=com");

    AuthenticationResponse result = authentManager.authenticate(
        new SimpleAuthenticationIdentity(user, null, domain));
    assertFalse(result.isValid());
  }
View Full Code Here

      User user =
          connectorSession.getUserGroupManager().getUserByGsaName(gsaName);
      if (user == null) {
        LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
            gsaName + " user is not authenticated");
        return new AuthenticationResponse(false, null);
      }
      LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
          user.getNotesName() + " user is authenticated");

      // Find the user in Notes.
      NotesSession notesSession = connectorSession.createNotesSession();
      NotesDatabase notesDirectory = null;
      NotesView notesUsersView = null;
      NotesDocument notesUserDoc = null;
      boolean hasValidPassword = false;
      try {
        notesDirectory = notesSession.getDatabase(
            connectorSession.getServer(), connectorSession.getDirectory());
        notesUsersView = notesDirectory.getView(NCCONST.DIRVIEW_USERS);
        notesUserDoc =
            notesUsersView.getDocumentByKey(user.getNotesName(), true);
        if (notesUserDoc == null) {
          LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
              "Username not found in Notes directory");
          return new AuthenticationResponse(false, null);
        }
        if (id.getPassword() != null) {
          String hashedPassword =
              notesUserDoc.getItemValueString("HTTPPassword");
          hasValidPassword =
              notesSession.verifyPassword(id.getPassword(), hashedPassword);
        }
      } finally {
        Util.recycle(notesUserDoc);
        Util.recycle(notesUsersView);
        Util.recycle(notesDirectory);
        connectorSession.closeNotesSession(notesSession);
      }

      Collection<String> groupsAndRoles = user.getGroupsAndRoles();
      Collection<String> prefixedGroups = GsaUtil.getGsaGroups(
          groupsAndRoles, connectorSession.getGsaGroupPrefix());
      Collection<Principal> principalGroups = null;
      if (prefixedGroups.size() != 0) {
        principalGroups = new ArrayList<Principal>(prefixedGroups.size());
        for (String group : prefixedGroups) {
          Principal principal = new Principal(PrincipalType.UNQUALIFIED,
              connectorSession.getConnector().getLocalNamespace(),
              group, CaseSensitivityType.EVERYTHING_CASE_INSENSITIVE);
          principalGroups.add(principal);
        }
      }
      String idLog = getIdentityLog(gsaName, user.getNotesName(),
          groupsAndRoles, prefixedGroups);
      if (id.getPassword() != null) {
        if (hasValidPassword) {
          LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
              "User succesfully authenticated: " + idLog);
          return new AuthenticationResponse(true, null, principalGroups);
        } else {
          LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
              "User failed authentication: " + idLog);
          return new AuthenticationResponse(false, null, principalGroups);
        }
      } else {
        LOGGER.logp(Level.FINE, CLASS_NAME, METHOD,
            "No password; returning groups only: " + idLog);
        // Although we don't actually know that the entity that
        // submitted this username has a valid password, we have
        // to return true because the GSA will refute the
        // identity otherwise. This situation occurs when the GSA
        // uses another authentication mechanism and uses the
        // connector for group resolution only.
        LOGGER.fine("principalgroups: " + principalGroups);
        return new AuthenticationResponse(true, null, principalGroups);
      }
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, CLASS_NAME, e);
    } finally {
      LOGGER.exiting(CLASS_NAME, METHOD);
    }
    return new AuthenticationResponse(false, null);
  }
View Full Code Here

    try {
      IUser user = uc.authenticate(username, id.getPassword());
      List<Principal> principalGroups = FileUtil.getPrincipals(
          PrincipalType.UNKNOWN, globalNamespace, user.getGroupNames(),
          CaseSensitivityType.EVERYTHING_CASE_INSENSITIVE);
      return new AuthenticationResponse(true, "", principalGroups);
    } catch (Throwable e) {
      logger.log(Level.WARNING, "Authentication failed for user "
          + username, e);
      return new AuthenticationResponse(false, "");
    }
  }
View Full Code Here

    FileAuthenticationManager fatm = (FileAuthenticationManager) fs.getAuthenticationManager();

    //    Check FileAuthenticationManager
    SimpleAuthenticationIdentity fai = new SimpleAuthenticationIdentity(
        TestConnection.username, TestConnection.password);
    AuthenticationResponse ar = fatm.authenticate(fai);
    assertEquals(true, ar.isValid());
    assertTrue(ar.getGroups().size() > 0);

    //    Check FileAuthenticationManager for a wrong user
    SimpleAuthenticationIdentity faiWrong = new SimpleAuthenticationIdentity(TestConnection.username, TestConnection.wrongPassword);
    AuthenticationResponse arWrong = fatm.authenticate(faiWrong);
    assertEquals(false, arWrong.isValid());
  }
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.spi.AuthenticationResponse

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.