org.apache.zookeeper.server.auth.DigestAuthenticationProvider类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(289)

本文整理了Java中org.apache.zookeeper.server.auth.DigestAuthenticationProvider类的一些代码示例,展示了DigestAuthenticationProvider类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DigestAuthenticationProvider类的具体详情如下:
包路径:org.apache.zookeeper.server.auth.DigestAuthenticationProvider
类名称:DigestAuthenticationProvider

DigestAuthenticationProvider介绍

暂无

代码示例

代码示例来源:origin: apache/zookeeper

/** Call with a single argument of user:pass to generate authdata.
   * Authdata output can be used when setting superDigest for example. 
   * @param args single argument of user:pass
   * @throws NoSuchAlgorithmException
   */
  public static void main(String args[]) throws NoSuchAlgorithmException {
    for (int i = 0; i < args.length; i++) {
      System.out.println(args[i] + "->" + generateDigest(args[i]));
    }
  }
}

代码示例来源:origin: apache/zookeeper

public static void initialize() {
  synchronized (ProviderRegistry.class) {
    if (initialized)
      return;
    IPAuthenticationProvider ipp = new IPAuthenticationProvider();
    DigestAuthenticationProvider digp = new DigestAuthenticationProvider();
    authenticationProviders.put(ipp.getScheme(), ipp);
    authenticationProviders.put(digp.getScheme(), digp);
    Enumeration<Object> en = System.getProperties().keys();
    while (en.hasMoreElements()) {
      String k = (String) en.nextElement();
      if (k.startsWith("zookeeper.authProvider.")) {
        String className = System.getProperty(k);
        try {
          Class<?> c = ZooKeeperServer.class.getClassLoader()
              .loadClass(className);
          AuthenticationProvider ap = (AuthenticationProvider) c.getDeclaredConstructor()
              .newInstance();
          authenticationProviders.put(ap.getScheme(), ap);
        } catch (Exception e) {
          LOG.warn("Problems loading " + className,e);
        }
      }
    }
    initialized = true;
  }
}

代码示例来源:origin: apache/zookeeper

static public String generateDigest(String idPassword)
    throws NoSuchAlgorithmException {
  String parts[] = idPassword.split(":", 2);
  byte digest[] = MessageDigest.getInstance("SHA1").digest(
      idPassword.getBytes());
  return parts[0] + ":" + base64Encode(digest);
}

代码示例来源:origin: apache/zookeeper

public KeeperException.Code 
  handleAuthentication(ServerCnxn cnxn, byte[] authData)
{
  String id = new String(authData);
  try {
    String digest = generateDigest(id);
    if (digest.equals(superDigest)) {
      cnxn.addAuthInfo(new Id("super", ""));
    }
    cnxn.addAuthInfo(new Id(getScheme(), digest));
    return KeeperException.Code.OK;
  } catch (NoSuchAlgorithmException e) {
    LOG.error("Missing algorithm",e);
  }
  return KeeperException.Code.AUTHFAILED;
}

代码示例来源:origin: apache/zookeeper

static final private String base64Encode(byte b[]) {
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < b.length;) {
    int pad = 0;
    int v = (b[i++] & 0xff) << 16;
    if (i < b.length) {
      v |= (b[i++] & 0xff) << 8;
    } else {
      pad++;
    }
    if (i < b.length) {
      v |= (b[i++] & 0xff);
    } else {
      pad++;
    }
    sb.append(encode(v >> 18));
    sb.append(encode(v >> 12));
    if (pad < 2) {
      sb.append(encode(v >> 6));
    } else {
      sb.append('=');
    }
    if (pad < 1) {
      sb.append(encode(v));
    } else {
      sb.append('=');
    }
  }
  return sb.toString();
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

public KeeperException.Code 
  handleAuthentication(ServerCnxn cnxn, byte[] authData)
{
  String id = new String(authData);
  try {
    String digest = generateDigest(id);
    if (digest.equals(superDigest)) {
      cnxn.addAuthInfo(new Id("super", ""));
    }
    cnxn.addAuthInfo(new Id(getScheme(), digest));
    return KeeperException.Code.OK;
  } catch (NoSuchAlgorithmException e) {
    LOG.error("Missing algorithm",e);
  }
  return KeeperException.Code.AUTHFAILED;
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

static final private String base64Encode(byte b[]) {
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < b.length;) {
    int pad = 0;
    int v = (b[i++] & 0xff) << 16;
    if (i < b.length) {
      v |= (b[i++] & 0xff) << 8;
    } else {
      pad++;
    }
    if (i < b.length) {
      v |= (b[i++] & 0xff);
    } else {
      pad++;
    }
    sb.append(encode(v >> 18));
    sb.append(encode(v >> 12));
    if (pad < 2) {
      sb.append(encode(v >> 6));
    } else {
      sb.append('=');
    }
    if (pad < 1) {
      sb.append(encode(v));
    } else {
      sb.append('=');
    }
  }
  return sb.toString();
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/** Call with a single argument of user:pass to generate authdata.
   * Authdata output can be used when setting superDigest for example. 
   * @param args single argument of user:pass
   * @throws NoSuchAlgorithmException
   */
  public static void main(String args[]) throws NoSuchAlgorithmException {
    for (int i = 0; i < args.length; i++) {
      System.out.println(args[i] + "->" + generateDigest(args[i]));
    }
  }
}

代码示例来源:origin: org.apache.hadoop/zookeeper

public KeeperException.Code 
  handleAuthentication(ServerCnxn cnxn, byte[] authData)
{
  String id = new String(authData);
  try {
    String digest = generateDigest(id);
    if (digest.equals(superDigest)) {
      cnxn.getAuthInfo().add(new Id("super", ""));
    }
    cnxn.getAuthInfo().add(new Id(getScheme(), digest));
    return KeeperException.Code.OK;
  } catch (NoSuchAlgorithmException e) {
    LOG.error("Missing algorithm",e);
  }
  return KeeperException.Code.AUTHFAILED;
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

public static void initialize() {
  synchronized (ProviderRegistry.class) {
    if (initialized)
      return;
    IPAuthenticationProvider ipp = new IPAuthenticationProvider();
    DigestAuthenticationProvider digp = new DigestAuthenticationProvider();
    authenticationProviders.put(ipp.getScheme(), ipp);
    authenticationProviders.put(digp.getScheme(), digp);
    Enumeration<Object> en = System.getProperties().keys();
    while (en.hasMoreElements()) {
      String k = (String) en.nextElement();
      if (k.startsWith("zookeeper.authProvider.")) {
        String className = System.getProperty(k);
        try {
          Class<?> c = ZooKeeperServer.class.getClassLoader()
              .loadClass(className);
          AuthenticationProvider ap = (AuthenticationProvider) c
              .getDeclaredConstructor().newInstance();
          authenticationProviders.put(ap.getScheme(), ap);
        } catch (Exception e) {
          LOG.warn("Problems loading " + className,e);
        }
      }
    }
    initialized = true;
  }
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

static public String generateDigest(String idPassword)
    throws NoSuchAlgorithmException {
  String parts[] = idPassword.split(":", 2);
  byte digest[] = MessageDigest.getInstance("SHA1").digest(
      idPassword.getBytes());
  return parts[0] + ":" + base64Encode(digest);
}

代码示例来源:origin: org.apache.hadoop/zookeeper

static final private String base64Encode(byte b[]) {
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < b.length;) {
    int pad = 0;
    int v = (b[i++] & 0xff) << 16;
    if (i < b.length) {
      v |= (b[i++] & 0xff) << 8;
    } else {
      pad++;
    }
    if (i < b.length) {
      v |= (b[i++] & 0xff);
    } else {
      pad++;
    }
    sb.append(encode(v >> 18));
    sb.append(encode(v >> 12));
    if (pad < 2) {
      sb.append(encode(v >> 6));
    } else {
      sb.append('=');
    }
    if (pad < 1) {
      sb.append(encode(v));
    } else {
      sb.append('=');
    }
  }
  return sb.toString();
}

代码示例来源:origin: apache/zookeeper

@BeforeClass
public static void setupStatic() throws Exception {
  oldAuthProvider = System.setProperty("zookeeper.authProvider.1","org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
  File tmpDir = createTmpDir();
  File saslConfFile = new File(tmpDir, "jaas.conf");
  FileWriter fwriter = new FileWriter(saslConfFile);
  fwriter.write("" +
      "Server {\n" +
      "          org.apache.zookeeper.server.auth.DigestLoginModule required\n" +
      "          user_super_duper=\"test\";\n" +
      "};\n" +
      "Client {\n" +
      "       org.apache.zookeeper.server.auth.DigestLoginModule required\n" +
      "       username=\"super_duper\"\n" +
      "       password=\"test\";\n" +
      "};" + "\n");
  fwriter.close();
  oldLoginConfig = System.setProperty("java.security.auth.login.config",saslConfFile.getAbsolutePath());
  oldSuperUser = System.setProperty("zookeeper.superUser","super_duper");
  otherDigestUser = new Id ("digest", DigestAuthenticationProvider.generateDigest("jack:jack"));
}

代码示例来源:origin: org.apache.hadoop/zookeeper

public static void initialize() {
  synchronized (ProviderRegistry.class) {
    if (initialized)
      return;
    IPAuthenticationProvider ipp = new IPAuthenticationProvider();
    DigestAuthenticationProvider digp = new DigestAuthenticationProvider();
    authenticationProviders.put(ipp.getScheme(), ipp);
    authenticationProviders.put(digp.getScheme(), digp);
    Enumeration<Object> en = System.getProperties().keys();
    while (en.hasMoreElements()) {
      String k = (String) en.nextElement();
      if (k.startsWith("zookeeper.authProvider.")) {
        String className = System.getProperty(k);
        try {
          Class<?> c = ZooKeeperServer.class.getClassLoader()
              .loadClass(className);
          AuthenticationProvider ap = (AuthenticationProvider) c
              .newInstance();
          authenticationProviders.put(ap.getScheme(), ap);
        } catch (Exception e) {
          LOG.warn("Problems loading " + className,e);
        }
      }
    }
    initialized = true;
  }
}

代码示例来源:origin: org.apache.hadoop/zookeeper

static public String generateDigest(String idPassword)
    throws NoSuchAlgorithmException {
  String parts[] = idPassword.split(":", 2);
  byte digest[] = MessageDigest.getInstance("SHA1").digest(
      idPassword.getBytes());
  return parts[0] + ":" + base64Encode(digest);
}

代码示例来源:origin: org.apache.hadoop/zookeeper

/** Call with a single argument of user:pass to generate authdata.
   * Authdata output can be used when setting superDigest for example. 
   * @param args single argument of user:pass
   * @throws NoSuchAlgorithmException
   */
  public static void main(String args[]) throws NoSuchAlgorithmException {
    for (int i = 0; i < args.length; i++) {
      System.out.println(args[i] + "->" + generateDigest(args[i]));
    }
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager

/**
 * Get ZooKeeper Curator manager, creating and starting if not exists.
 * @param config Configuration for the ZooKeeper curator.
 * @return ZooKeeper Curator manager.
 * @throws IOException If it cannot create the manager.
 */
public ZKCuratorManager createAndStartZKManager(Configuration
  config) throws IOException {
 ZKCuratorManager manager = new ZKCuratorManager(config);
 // Get authentication
 List<AuthInfo> authInfos = new ArrayList<>();
 if (HAUtil.isHAEnabled(config) && HAUtil.getConfValueForRMInstance(
   YarnConfiguration.ZK_RM_STATE_STORE_ROOT_NODE_ACL, config) == null) {
  String zkRootNodeUsername = HAUtil.getConfValueForRMInstance(
    YarnConfiguration.RM_ADDRESS,
    YarnConfiguration.DEFAULT_RM_ADDRESS, config);
  String defaultFencingAuth =
    zkRootNodeUsername + ":" + zkRootNodePassword;
  byte[] defaultFencingAuthData =
    defaultFencingAuth.getBytes(Charset.forName("UTF-8"));
  String scheme = new DigestAuthenticationProvider().getScheme();
  AuthInfo authInfo = new AuthInfo(scheme, defaultFencingAuthData);
  authInfos.add(authInfo);
 }
 manager.start(authInfos);
 return manager;
}

代码示例来源:origin: org.apache.hadoop/hadoop-yarn-registry

/**
 * Generate a base-64 encoded digest of the idPasswordPair pair
 * @param idPasswordPair id:password
 * @return a string that can be used for authentication
 */
public String digest(String idPasswordPair) throws IOException {
 if (StringUtils.isEmpty(idPasswordPair) || !isValid(idPasswordPair)) {
  throw new IOException("Invalid id:password");
 }
 try {
  return DigestAuthenticationProvider.generateDigest(idPasswordPair);
 } catch (NoSuchAlgorithmException e) {
  // unlikely since it is standard to the JVM, but maybe JCE restrictions
  // could trigger it
  throw new IOException(e.toString(), e);
 }
}

代码示例来源:origin: io.hops/hadoop-yarn-registry

/**
 * Generate a base-64 encoded digest of the idPasswordPair pair
 * @param idPasswordPair id:password
 * @return a string that can be used for authentication
 */
public String digest(String idPasswordPair) throws IOException {
 if (StringUtils.isEmpty(idPasswordPair) || !isValid(idPasswordPair)) {
  throw new IOException("Invalid id:password");
 }
 try {
  return DigestAuthenticationProvider.generateDigest(idPasswordPair);
 } catch (NoSuchAlgorithmException e) {
  // unlikely since it is standard to the JVM, but maybe JCE restrictions
  // could trigger it
  throw new IOException(e.toString(), e);
 }
}

代码示例来源:origin: dmart28/gcplot

public void init() throws Exception {
  LOG.info("ZC: init()");
  client = new ZooKeeper(host + ":" + port, sessionTimeout, event -> watchers.forEach(w -> {
    try {
      w.process(event);
    } catch (Throwable t) {
      LOG.error(t.getMessage(), t);
    }
  }));
  client.addAuthInfo("digest", (uid + ":" + secret).getBytes());
  secretDigest = DigestAuthenticationProvider.generateDigest(uid + ":" + secret);
  acls = Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id("digest", secretDigest)));
}

相关文章