Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Apache ZooKeeper 3.7.0 Server Source Code
Apache ZooKeeper is an open-source server which enables highly
reliable distributed coordination.
Apache ZooKeeper Server Source Code files are provided in the source packge (apache-zookeeper-3.7.0.tar.gz). You can download it at Apache ZooKeeper Website.
You can also browse Apache ZooKeeper Server Source Code below:
✍: FYIcenter.com
⏎ org/apache/zookeeper/server/auth/KeyAuthenticationProvider.java
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.zookeeper.server.auth; import static java.nio.charset.StandardCharsets.UTF_8; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException.NoNodeException; import org.apache.zookeeper.data.Id; import org.apache.zookeeper.data.Stat; import org.apache.zookeeper.server.ZKDatabase; import org.apache.zookeeper.server.ZooKeeperServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /* * This class is a sample implementation of being passed the ZooKeeperServer * handle in the constructor, and reading data from zknodes to authenticate. * At a minimum, a real Auth provider would need to override validate() to * e.g. perform certificate validation of auth based a public key. * * See the "Pluggable ZooKeeper authentication" section of the * "Zookeeper Programmer's Guide" for general details of implementing an * authentication plugin. e.g. * http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html#sc_ZooKeeperPluggableAuthentication * * This class looks for a numeric "key" under the /key node. * Authorization is granted if the user passes in as authorization a number * which is a multiple of the key value, i.e. * (auth % key) == 0 * In a real implementation, you might do something like storing a public * key in /key, and using it to verify that auth tokens passed in were signed * by the corresponding private key. * * When the node /key does not exist, any auth token is accepted, so that * bootstrapping may occur. * */ public class KeyAuthenticationProvider extends ServerAuthenticationProvider { private static final Logger LOG = LoggerFactory.getLogger(KeyAuthenticationProvider.class); public String getScheme() { return "key"; } private byte[] getKey(ZooKeeperServer zks) { ZKDatabase db = zks.getZKDatabase(); if (db != null) { try { Stat stat = new Stat(); return db.getData("/key", stat, null); } catch (NoNodeException e) { LOG.error("getData failed", e); } } return null; } private boolean validate(byte[] key, byte[] auth) { // perform arbitrary function (auth is a multiple of key) try { String keyStr = new String(key, UTF_8); String authStr = new String(auth, UTF_8); int keyVal = Integer.parseInt(keyStr); int authVal = Integer.parseInt(authStr); if (keyVal != 0 && ((authVal % keyVal) != 0)) { return false; } } catch (NumberFormatException nfe) { LOG.error("bad formatting", nfe); return false; } return true; } @Override public KeeperException.Code handleAuthentication(ServerObjs serverObjs, byte[] authData) { byte[] key = getKey(serverObjs.getZks()); String authStr = new String(authData, UTF_8); String keyStr = ""; if (key != null) { if (!validate(key, authData)) { keyStr = new String(key, UTF_8); LOG.debug("KeyAuthenticationProvider handleAuthentication ({}, {}) -> FAIL.\n", keyStr, authStr); return KeeperException.Code.AUTHFAILED; } } // default to allow, so the key can be initially written LOG.debug("KeyAuthenticationProvider handleAuthentication -> OK.\n"); // NOTE: keyStr in addAuthInfo() sticks with the created node ACLs. // For transient keys or certificates, this presents a problem. // In that case, replace it with something non-ephemeral (or punt with null). // // BOTH addAuthInfo and an OK return-code are needed for authentication. serverObjs.getCnxn().addAuthInfo(new Id(getScheme(), keyStr)); return KeeperException.Code.OK; } @Override public boolean matches(ServerObjs serverObjs, MatchValues matchValues) { return matchValues.getId().equals(matchValues.getAclExpr()); } @Override public boolean isAuthenticated() { return true; } @Override public boolean isValid(String id) { return true; } }
⏎ org/apache/zookeeper/server/auth/KeyAuthenticationProvider.java
Or download all of them as a single archive file:
File name: zookeeper-server-3.7.0-fyi.zip File size: 871011 bytes Release date: 2021-05-17 Download
⇒ Apache ZooKeeper 3.7.0 Jute Source Code
⇐ Download Apache ZooKeeper 3.7.0 Source Package
2022-11-16, 24739👍, 0💬
Popular Posts:
Apache BCEL Source Code Files are inside the Apache BCEL source package file like bcel-6.5.0-src.zip...
What Is HttpComponents commons-httpclient-3.1.j ar?HttpComponents commons-httpclient-3.1.j aris the ...
How to download and install JDK (Java Development Kit) 5? If you want to write Java applications, yo...
iText is an ideal library for developers looking to enhance web- and other applications with dynamic...
layout.jar is a component in iText Java library to provide layout functionalities. iText Java librar...