flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ches...@apache.org
Subject [2/6] flink git commit: [FLINK-5160] SecurityUtils use OperatingSystem.getCurrentOperatingSystem()
Date Fri, 06 Jan 2017 15:43:46 GMT
[FLINK-5160] SecurityUtils use OperatingSystem.getCurrentOperatingSystem()


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

Branch: refs/heads/release-1.2
Commit: 65a32e74175c026f04ab058ee2ace8c9e7012d76
Parents: 700cbd4
Author: zentol <chesnay@apache.org>
Authored: Thu Jan 5 15:39:25 2017 +0100
Committer: zentol <chesnay@apache.org>
Committed: Fri Jan 6 12:54:45 2017 +0100

----------------------------------------------------------------------
 .../org/apache/flink/util/OperatingSystem.java  | 25 +++++++++++++
 .../runtime/security/SecurityUtilsTest.java     | 37 ++++++++++++--------
 2 files changed, 48 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/65a32e74/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
----------------------------------------------------------------------
diff --git a/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java b/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
index 4dc3abb..7c477cc 100644
--- a/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
+++ b/flink-core/src/main/java/org/apache/flink/util/OperatingSystem.java
@@ -30,6 +30,7 @@ public enum OperatingSystem {
 	WINDOWS,
 	MAC_OS,
 	FREE_BSD,
+	SOLARIS,
 	UNKNOWN;
 	
 	// ------------------------------------------------------------------------
@@ -83,6 +84,16 @@ public enum OperatingSystem {
 	public static boolean isFreeBSD() {
 		return getCurrentOperatingSystem() == FREE_BSD;
 	}
+
+	/**
+	 * Checks whether the operating system this JVM runs on is Solaris.
+	 *
+	 * @return <code>true</code> if the operating system this JVM runs on is
+	 *         Solaris, <code>false</code> otherwise
+	 */
+	public static boolean isSolaris() {
+		return getCurrentOperatingSystem() == SOLARIS;
+	}
 	
 	/**
 	 * The enum constant for the operating system.
@@ -110,6 +121,10 @@ public enum OperatingSystem {
 		if (osName.startsWith(FREEBSD_OS_PREFIX)) {
 			return FREE_BSD;
 		}
+		String osNameLowerCase = osName.toLowerCase();
+		if (osNameLowerCase.contains(SOLARIS_OS_INFIX_1) || osNameLowerCase.contains(SOLARIS_OS_INFIX_2))
{
+			return SOLARIS;
+		}
 		
 		return UNKNOWN;
 	}
@@ -142,4 +157,14 @@ public enum OperatingSystem {
 	 * The expected prefix for FreeBSD.
 	 */
 	private static final String FREEBSD_OS_PREFIX = "FreeBSD";
+
+	/**
+	 * One expected infix for Solaris.
+	 */
+	private static final String SOLARIS_OS_INFIX_1 = "sunos";
+
+	/**
+	 * One expected infix for Solaris.
+	 */
+	private static final String SOLARIS_OS_INFIX_2 = "solaris";
 }

http://git-wip-us.apache.org/repos/asf/flink/blob/65a32e74/flink-runtime/src/test/java/org/apache/flink/runtime/security/SecurityUtilsTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/security/SecurityUtilsTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/security/SecurityUtilsTest.java
index e7da404..2648a7a 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/security/SecurityUtilsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/security/SecurityUtilsTest.java
@@ -18,6 +18,7 @@
 package org.apache.flink.runtime.security;
 
 import org.apache.flink.configuration.Configuration;
+import org.apache.flink.util.OperatingSystem;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.junit.AfterClass;
 import org.junit.Assert;
@@ -77,21 +78,29 @@ public class SecurityUtilsTest {
 
 	private String getOSUserName() throws Exception {
 		String userName = "";
-		String osName = System.getProperty( "os.name" ).toLowerCase();
-		String className = null;
-		String methodName = null;
+		OperatingSystem os = OperatingSystem.getCurrentOperatingSystem();
+		String className;
+		String methodName;
 
-		if( osName.contains( "windows" ) ){
-			className = "com.sun.security.auth.module.NTSystem";
-			methodName = "getName";
-		}
-		else if( osName.contains( "linux" ) || osName.contains( "mac" )  ){
-			className = "com.sun.security.auth.module.UnixSystem";
-			methodName = "getUsername";
-		}
-		else if( osName.contains( "solaris" ) || osName.contains( "sunos" ) ){
-			className = "com.sun.security.auth.module.SolarisSystem";
-			methodName = "getUsername";
+		switch(os) {
+			case LINUX:
+			case MAC_OS:
+				className = "com.sun.security.auth.module.UnixSystem";
+				methodName = "getUsername";
+				break;
+			case WINDOWS:
+				className = "com.sun.security.auth.module.NTSystem";
+				methodName = "getName";
+				break;
+			case SOLARIS:
+				className = "com.sun.security.auth.module.SolarisSystem";
+				methodName = "getUsername";
+				break;
+			case FREE_BSD:
+			case UNKNOWN:
+			default:
+				className = null;
+				methodName = null;
 		}
 
 		if( className != null ){


Mime
View raw message