ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject ranger git commit: RANGER-1849 - Remove PasswordGenerator and FileStoreUtil
Date Fri, 08 Dec 2017 12:48:09 GMT
Repository: ranger
Updated Branches:
  refs/heads/master e8afb9faa -> b8c70c41b


RANGER-1849 - Remove PasswordGenerator and FileStoreUtil

Signed-off-by: Colm O hEigeartaigh <coheigea@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/b8c70c41
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/b8c70c41
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/b8c70c41

Branch: refs/heads/master
Commit: b8c70c41b9728f9abb22b8cde66cc09ee8dc0845
Parents: e8afb9f
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Nov 16 12:17:09 2017 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Dec 8 12:40:49 2017 +0000

----------------------------------------------------------------------
 .../ranger/plugin/store/file/FileStoreUtil.java | 314 -------------------
 .../ranger/utils/install/PasswordGenerator.java | 141 ---------
 2 files changed, 455 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ranger/blob/b8c70c41/agents-common/src/main/java/org/apache/ranger/plugin/store/file/FileStoreUtil.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/store/file/FileStoreUtil.java
b/agents-common/src/main/java/org/apache/ranger/plugin/store/file/FileStoreUtil.java
deleted file mode 100644
index 3f408d7..0000000
--- a/agents-common/src/main/java/org/apache/ranger/plugin/store/file/FileStoreUtil.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * 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.ranger.plugin.store.file;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.FSDataInputStream;
-import org.apache.hadoop.fs.FSDataOutputStream;
-import org.apache.hadoop.fs.FileStatus;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.fs.PathFilter;
-import org.apache.ranger.plugin.model.RangerPolicy;
-import org.apache.ranger.plugin.model.RangerService;
-import org.apache.ranger.plugin.model.RangerServiceDef;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-public class FileStoreUtil {
-	private static final Log LOG = LogFactory.getLog(FileStoreUtil.class);
-
-	private Gson   gsonBuilder;
-	private String dataDir;
-
-	private static final String FILE_SUFFIX_JSON        = ".json";
-
-	public void initStore(String dataDir) {
-		this.dataDir = dataDir;
-
-		try {
-			gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().create();
-		} catch(Throwable excp) {
-			LOG.fatal("FileStoreUtil.init(): failed to create GsonBuilder object", excp);
-		}
-	}
-	
-	public String getDataDir() {
-		return dataDir;
-	}
-
-	public String getDataFile(String filePrefix, Long id) {
-		String filePath = dataDir + Path.SEPARATOR + filePrefix + id + FILE_SUFFIX_JSON;
-
-		return filePath;
-	}
-
-	public String getDataFile(String filePrefix, Long parentId, Long objectId) {
-		String filePath = dataDir + Path.SEPARATOR + filePrefix + parentId + "-" + objectId + FILE_SUFFIX_JSON;
-
-		return filePath;
-	}
-
-	public <T> T loadFromResource(String resource, Class<T> cls) throws Exception
{
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.loadFromResource(" + resource + ")");
-		}
-
-		InputStream inStream = this.getClass().getResourceAsStream(resource);
-
-		T ret = loadFromStream(inStream, cls);
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.loadFromResource(" + resource + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	public <T> T loadFromStream(InputStream inStream, Class<T> cls) throws Exception
{
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.loadFromStream()");
-		}
-
-		InputStreamReader reader = new InputStreamReader(inStream);
-
-		T ret = gsonBuilder.fromJson(reader, cls);
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.loadFromStream(): " + ret);
-		}
-
-		return ret;
-	}
-
-	public <T> T loadFromFile(Path filePath, Class<T> cls) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.loadFromFile(" + filePath + ")");
-		}
-
-		T                 ret    = null;
-		InputStreamReader reader = null;
-
-		try {
-			FileSystem        fileSystem = getFileSystem(filePath);
-			FSDataInputStream inStream   = fileSystem.open(filePath);
-
-			ret = loadFromStream(inStream, cls);
-		} finally {
-			close(reader);
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.loadFromFile(" + filePath + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	public <T> List<T> loadFromDir(Path dirPath, final String filePrefix, Class<T>
cls) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.loadFromDir()");
-		}
-
-		List<T> ret = new ArrayList<>();
-
-		try {
-			FileSystem fileSystem = getFileSystem(dirPath);
-
-			if(fileSystem.exists(dirPath) && fileSystem.isDirectory(dirPath)) {
-				PathFilter filter = new PathFilter() {
-					@Override
-					public boolean accept(Path path) {
-						return path.getName().startsWith(filePrefix) &&
-							   path.getName().endsWith(FILE_SUFFIX_JSON);
-					}
-				};
-
-				FileStatus[] sdFiles = fileSystem.listStatus(dirPath, filter);
-
-				if(sdFiles != null) {
-					for(FileStatus sdFile : sdFiles) {
-						T obj = loadFromFile(sdFile.getPath(), cls);
-
-						if(obj != null) {
-							ret.add(obj);
-						}
-					}
-				}
-			} else {
-				LOG.error(dirPath + ": does not exists or not a directory");
-			}
-		} catch(IOException excp) {
-			LOG.warn("error loading service-def in directory " + dirPath, excp);
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.loadFromDir(): count=" + (ret == null ? 0 : ret.size()));
-		}
-
-		return ret;
-	}
-
-	public <T> T saveToFile(T obj, Path filePath, boolean overWrite) throws Exception
{
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.saveToFile(" + filePath + ")");
-		}
-
-		OutputStreamWriter writer = null;
-
-		try {
-			FileSystem         fileSystem = getFileSystem(filePath);
-			FSDataOutputStream outStream  = fileSystem.create(filePath, overWrite);
-
-			writer = new OutputStreamWriter(outStream);
-
-			gsonBuilder.toJson(obj, writer);
-		} finally {
-			close(writer);
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.saveToFile(" + filePath + "): " + obj);
-		}
-
-		return obj;
-	}
-
-	public boolean deleteFile(Path filePath) throws Exception {
-		LOG.debug("==> FileStoreUtil.deleteFile(" + filePath + ")");
-
-		FileSystem fileSystem = getFileSystem(filePath);
-
-		boolean ret = false;
-
-		if(fileSystem.exists(filePath)) {
-			ret = fileSystem.delete(filePath, false);
-		} else {
-			ret = true; // nothing to delete
-		}
-
-		LOG.debug("<== FileStoreUtil.deleteFile(" + filePath + "): " + ret);
-
-		return ret;
-	}
-
-	public boolean renamePath(Path oldPath, Path newPath) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.renamePath(" + oldPath + "," + newPath + ")");
-		}
-
-		FileSystem fileSystem = getFileSystem(oldPath);
-
-		boolean ret = false;
-
-		if(fileSystem.exists(oldPath)) {
-			if(! fileSystem.exists(newPath)) {
-				ret = fileSystem.rename(oldPath, newPath);
-			} else {
-				LOG.warn("target of rename '" + newPath + "' already exists");
-			}
-		}
-
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.renamePath(" + oldPath + "," + newPath + "): " + ret);
-		}
-
-		return ret;
-	}
-
-	public RangerServiceDef saveToFile(RangerServiceDef serviceDef, String filePrefix, boolean
overWrite) throws Exception {
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> FileStoreUtil.saveToFile(" + serviceDef + "," + overWrite + ")");
-		}
-
-		Path filePath = new Path(getDataFile(filePrefix, serviceDef.getId()));
-
-		RangerServiceDef ret = saveToFile(serviceDef, filePath, overWrite);
-		
-		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== FileStoreUtil.saveToFile(" + serviceDef + "," + overWrite + "): ");
-		}
-
-		return ret;
-	}
-
-	public RangerService saveToFile(RangerService service, String filePrefix,boolean overWrite)
throws Exception {
-		Path filePath = new Path(getDataFile(filePrefix, service.getId()));
-
-		RangerService ret = saveToFile(service, filePath, overWrite);
-		
-		return ret;
-	}
-
-	public RangerPolicy saveToFile(RangerPolicy policy, String filePrefix, long serviceId, boolean
overWrite) throws Exception {
-		Path filePath = new Path(getDataFile(filePrefix, serviceId, policy.getId()));
-
-		RangerPolicy ret = saveToFile(policy, filePath, overWrite);
-
-		return ret;
-	}
-
-	public FileSystem getFileSystem(Path filePath) throws Exception {
-		Configuration conf        = new Configuration();
-		FileSystem    fileSystem  = filePath.getFileSystem(conf);
-		
-		return fileSystem;
-	}
-
-	protected void close(FileSystem fs) {
-		if(fs != null) {
-			try {
-				fs.close();
-			} catch(IOException excp) {
-				// ignore
-			}
-		}
-	}
-
-	protected void close(InputStreamReader reader) {
-		if(reader != null) {
-			try {
-				reader.close();
-			} catch(IOException excp) {
-				// ignore
-			}
-		}
-	}
-
-	protected void close(OutputStreamWriter writer) {
-		if(writer != null) {
-			try {
-				writer.close();
-			} catch(IOException excp) {
-				// ignore
-			}
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/ranger/blob/b8c70c41/agents-installer/src/main/java/org/apache/ranger/utils/install/PasswordGenerator.java
----------------------------------------------------------------------
diff --git a/agents-installer/src/main/java/org/apache/ranger/utils/install/PasswordGenerator.java
b/agents-installer/src/main/java/org/apache/ranger/utils/install/PasswordGenerator.java
deleted file mode 100644
index a829957..0000000
--- a/agents-installer/src/main/java/org/apache/ranger/utils/install/PasswordGenerator.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.ranger.utils.install;
-
-import java.security.SecureRandom;
-import java.util.ArrayList;
-
-public class PasswordGenerator {
-
-	
-	private int minimumPasswordLength = 8;
-	
-	private int maximumPasswordLength = 12;
-	
-	private boolean isExpectedNumberic = true;
-	
-	private boolean isExpectedBothCase = true;
-	
-	private static final ArrayList<Character> alphaLetters = new ArrayList<Character>();
-
-	private static final ArrayList<Character> alphaUpperLetters = new ArrayList<Character>();
-
-	private static final ArrayList<Character> numericLetters = new ArrayList<Character>();
-	
-	
-	static {
-		for(int x = 'a'; x <= 'z' ; x++) {
-			char v = (char)x;
-			alphaLetters.add(Character.toLowerCase(v));
-			alphaUpperLetters.add(Character.toUpperCase(v));
-		}
-		for(int i = 0; i < 10 ; i++) {
-			numericLetters.add(Character.forDigit(i,10));
- 		}
-	}
-	
-
-	
-	public static void main(String[] args) {
-		PasswordGenerator pg = new PasswordGenerator();
-		System.out.println(pg.generatorPassword());
-	}
-	
-	
-	private int getPasswordLength() {
-		int ret = 0;
-		
-		if (minimumPasswordLength == maximumPasswordLength) {
-			ret = minimumPasswordLength;
-		}
-		else {
-			
-			int diff = Math.abs(maximumPasswordLength - minimumPasswordLength) + 1;
-                        ret = minimumPasswordLength + new SecureRandom().nextInt(diff);
-		}
-		return (ret);
-	}
-	
-	
-	public String generatorPassword() {
-	
-		String password = null;
-		
-		ArrayList<Character> all = new ArrayList<Character>();
-		
-		all.addAll(alphaLetters);
-		all.addAll(alphaUpperLetters);
-		all.addAll(numericLetters);
- 				
-		int len = getPasswordLength();
-		
-		SecureRandom random = new SecureRandom();
-		
-		int setSz = all.size();
-		
-		do
-		{
-			StringBuilder sb = new StringBuilder();
-			
-			for(int i = 0; i < len ; i++) {
-				int index = random.nextInt(setSz);
-				Character c = all.get(index);
-				while ((i == 0) && Character.isDigit(c)) {
-					index = random.nextInt(setSz);
-					c = all.get(index);
-				}
-				sb.append(all.get(index));
-			}
-			password = sb.toString();
-		} while (! isValidPassword(password));
-		
-		
-		return password;
-		
-	}
-	
-	private boolean isValidPassword(String pass) {
-		boolean ret = true;
-		
-		if (isExpectedNumberic || isExpectedBothCase) {
-			boolean lowerCaseFound = false;
-			boolean digitFound = false;
-			boolean upperCaseFound = false;
-			for(char c : pass.toCharArray()) {
-				if (!digitFound && Character.isDigit(c)) {
-					digitFound = true;
-				}
-				else if (!lowerCaseFound && Character.isLowerCase(c)) {
-					lowerCaseFound = true;
-				}
-				else if (!upperCaseFound && Character.isUpperCase(c) ) {
-					upperCaseFound = true;
-				}
-			}
-			
-			if (isExpectedNumberic && !digitFound) {
-				ret = false ;
-			}
-			
-			if (isExpectedBothCase && (!lowerCaseFound || !upperCaseFound)) {
-				ret = false;
-			}
-		}
-		
-		return ret;
-	}
-}


Mime
View raw message