Package com.google.enterprise.connector.spi

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


    try {
      List<HashMap<String, Object>> users = db.select(query, sqlIdentity);
      if (users.size() == 0) {
        LOGGER.warning("User not found in the database ["
            + username + "] domain [" + domain + "]");
        return new AuthenticationResponse(false, "", null);
      } else if (users.size() > 1) {
        StringBuffer sb = new StringBuffer("Multiple users found in the "
            + "database matching [" + domain + "]\\[" + username + "]: ");
        for (HashMap<String, Object> u : users) {
          sb.append("[").append(u.get("dn")).append("] ");
        }
        LOGGER.warning(sb.toString());
        return new AuthenticationResponse(false, "", null);
      }
      HashMap<String, Object>user = users.get(0);
      List<Principal> groups =
          getAllGroupsForTheUser((Number) user.get(AdConstants.DB_ENTITYID));
      if (password != null && !authenticateUser(
              (String) user.get(AdConstants.DB_DNSROOT),
              (String) user.get(AdConstants.DB_NETBIOSNAME)
                  + AdConstants.BACKSLASH
                  + (String) user.get(AdConstants.DB_SAMACCOUNTNAME),
              password)) {
        return new AuthenticationResponse(false, "", null);
      }
      if (LOGGER.isLoggable(Level.INFO)) {
        StringBuffer sb = new StringBuffer("Resolved ").append(groups.size())
            .append(" AD group(s) for user [").append(username).append("]")
            .append(" domain [").append(domain).append("]: ");
        for (Principal group : groups) {
          sb.append("[").append(group.getName()).append("] ");
        }
        LOGGER.info(sb.toString());
      }
      if (identity instanceof MutableIdentity) {
        MutableIdentity mutable = (MutableIdentity) identity;
        mutable.setDomain((String) user.get(AdConstants.DB_NETBIOSNAME));
        mutable.setUsername((String) user.get(AdConstants.DB_SAMACCOUNTNAME));
        LOGGER.fine("New identity: [" + domain + "\\" + username
            + "] Active Directory: [" + identity.getDomain()
            + "\\" + identity.getUsername() + "]");
      }
      LOGGER.log(Level.INFO, "Elapsed time for Active Directory authentication "
          + "of user [{0}\\{1}] = [{2}ms]"new Object[] {domain, username,
            System.currentTimeMillis() - startAuthN});
      return new AuthenticationResponse(true, "", groups);
    } catch (SQLException e) {
      LOGGER.log(Level.WARNING,
          "Failed to retrieve information about user from database ["
          + username + "] domain [" + domain + "].", e);
      return new AuthenticationResponse(false, "", null);
    }
  }
View Full Code Here


    Session s = con.login();
    s.getTraversalManager().startTraversal();
    AuthenticationManager am = s.getAuthenticationManager();
    String username = TestConfiguration.d1principal.split("\\\\")[1];
    AuthenticationResponse response = am.authenticate(
        new SimpleAuthenticationIdentity(username));
    assertNotNull(response);

    Collection<Principal> principals = getGroups(response);
    assertNotNull(principals);
View Full Code Here

      // Ask for attributes to ensure that the server is
      // contacted. JNDI allows lazy initialization of
      // contexts, so we have to use it, not just create
      // it.
      ctx.getAttributes("");
      return new AuthenticationResponse(true, null);
    } catch (NamingException e) {
      LOGGER.warning("Authentication failed for " +
          identity.getUsername() + "; " + e.toString());
      return new AuthenticationResponse(false, null);
    }
  }
View Full Code Here

    public AuthenticationResponse authenticate(AuthenticationIdentity identity)
            throws RepositoryLoginException, RepositoryException {
        if (LOGGER.isLoggable(Level.FINE))
            LOGGER.fine("AUTHENTICATE: " + identity.getUsername());

        AuthenticationResponse response = null;
        for (AuthenticationManager authn : authenticationManagers) {
            try {
                if (LOGGER.isLoggable(Level.FINER))
                    LOGGER.finer("Trying authentication manager " + authn);
                response = authn.authenticate(identity);
                if (response.isValid())
                    break;
            }
            catch (RepositoryException e) {
                LOGGER.warning("Authentication failed for " +
                    identity.getUsername() + "; " + e.getMessage());
                response = new AuthenticationResponse(false, null);
            }
        }
        return response;
    }
View Full Code Here

  //groups against AD only if necessary
  private AuthenticationResponse authenticateAgainstActiveDirectory(
      final AuthenticationIdentity identity) throws RepositoryLoginException,
      RepositoryException {
    long startAuthN = System.currentTimeMillis();
    AuthenticationResponse adAuthResult =
        adGroupsAuthenticationManager.authenticate(identity);
    if (!adAuthResult.isValid()) {
      return adAuthResult;
    }

    long startSharePoint = System.currentTimeMillis();
    @SuppressWarnings("unchecked")
    Collection<Principal> adGroups =
        (Collection<Principal>) adAuthResult.getGroups();
    String strUserName =
        addUserNameFormatForTheSearchUser(identity.getUsername(), identity.getDomain());
    Set<Principal> spGroups = sharepointClientContext
        .getUserDataStoreDAO().getSharePointGroupsForSearchUserAndLdapGroups(
            sharepointClientContext.getGoogleLocalNamespace(), adGroups,
            strUserName);

    Collection<Principal> groups = new ArrayList<Principal>();
    groups.addAll(adGroups);
    groups.addAll(spGroups);
    LOGGER.log(Level.INFO, "Authentication Duration [{0}] : Total = [{1}ms] "
        + "SharePoint = [{2}ms] AD = [{3}ms]", new Object[] {strUserName,
          (System.currentTimeMillis() - startAuthN),
          (System.currentTimeMillis() - startSharePoint),
          (startSharePoint - startAuthN)});

    return new AuthenticationResponse(
        adAuthResult.isValid(), adAuthResult.getData(), groups);
  }
View Full Code Here

          return getAllGroupsForTheUser(user);
        } else {
          // Handle the cases when connector should just return true
          // indicating successfull authN
          LOGGER.config("No group resolution has been attempted as connector is not set to feed ACL");
          return new AuthenticationResponse(true, "", null);
        }
      }
    } else {
      LOGGER.config("AuthN was not attempted as password is empty and groups are being returned.");
      return getAllGroupsForTheUser(user);
    }
    LOGGER.log(Level.WARNING, "Authentication failed for " + user);
    return new AuthenticationResponse(false, "", null);
  }
View Full Code Here

      // Should return true if there is at least one group returned by
      // LDAP service.
      LOGGER.log(Level.INFO, "Group resolution returned following groups "
          + "for the search user: {0}\n{1}",
          new Object[] { searchUser, allSearchUserGroups.toString() });
      return new AuthenticationResponse(true, "", allSearchUserGroups);
    } else {
      LOGGER.info("Group resolution returned no groups for the search user: "
          + searchUser);
      // Should return true with null groups.
      return new AuthenticationResponse(true, "", null);
    }
  }
View Full Code Here

      Logger.getLogger(AdGroupsConnectorTest.class.getName());

  private void runUsernameTest(String comment, AuthenticationManager am,
      String username, String domain, String password)
      throws Exception {
    AuthenticationResponse response;

    response = am.authenticate(
        new SimpleAuthenticationIdentity(username));
    assertTrue(comment + ": Username, no domain, no password",
        response.isValid());

    response = am.authenticate(new SimpleAuthenticationIdentity(
        username, null));
    assertTrue(comment + ": Username, no domain, null password",
        response.isValid());

    response = am.authenticate(new SimpleAuthenticationIdentity(
        username, ""));
    assertFalse(comment + ": Username, no domain, empty password",
        response.isValid());

    response = am.authenticate(
        new SimpleAuthenticationIdentity(username, null, domain));
    assertTrue(comment + ": Username, domain, null password",
        response.isValid());

    response = am.authenticate(new SimpleAuthenticationIdentity(
            username, "", domain));
    assertFalse(comment + ": Username, domain, empty password",
        response.isValid());

    response = am.authenticate(new SimpleAuthenticationIdentity(
        username, password, domain));
    assertTrue(comment + ": Username, domain, password",
        response.isValid());

    response = am.authenticate(new SimpleAuthenticationIdentity(
        username, password + "makeinvalid"));
    assertFalse(comment + ": Username, no domain, incorrect password",
        response.isValid());

    response = am.authenticate(new SimpleAuthenticationIdentity(
        username, password + "makeinvalid", domain));
    assertFalse(comment + ": Username, domain, incorrect password",
        response.isValid());
  }
View Full Code Here

      con.setDataSource(dbType, TestConfiguration.dbs.get(dbType));
      Session s = con.login();
      s.getTraversalManager().startTraversal();
      AuthenticationManager am = s.getAuthenticationManager();

      AuthenticationResponse response = am.authenticate(
          new SimpleAuthenticationIdentity(
              "non-existing user", "wrong password", "wrong domain"));
      assertFalse("Non existing user fails authn", response.isValid());
      assertNull("No groups resolved for non-existing user",
          response.getGroups());

      String[] principal =
          TestConfiguration.d1principal.split("\\\\");
      String domain = principal[0];
      String username = principal[1];
View Full Code Here

      // recrawl the active directory
      s.getTraversalManager().resumeTraversal("");

      // get groups for the created user
      AuthenticationResponse response = s.getAuthenticationManager()
          .authenticate(new SimpleAuthenticationIdentity(user.sAMAccountName));

      @SuppressWarnings("unchecked") Collection<Principal> principals =
          (Collection<Principal>) response.getGroups();
      assertNotNull(principals);
      assertTrue(principals.size() > 0);

      String groupname = ad.getnETBIOSName() + "\\" + group.sAMAccountName;
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.