blob: 1cbcd122b6f7568129e3f69efb5eb29e6707b5ec [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>Source code</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="source: package: org.apache.hadoop.hbase.util, class: LauncherSecurityManager">
<meta name="generator" content="javadoc/SourceToHTMLConverter">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body class="source-page">
<main role="main">
<div class="source-container">
<pre><span class="source-line-no">001</span><span id="line-1">/*</span>
<span class="source-line-no">002</span><span id="line-2"> * Licensed to the Apache Software Foundation (ASF) under one</span>
<span class="source-line-no">003</span><span id="line-3"> * or more contributor license agreements. See the NOTICE file</span>
<span class="source-line-no">004</span><span id="line-4"> * distributed with this work for additional information</span>
<span class="source-line-no">005</span><span id="line-5"> * regarding copyright ownership. The ASF licenses this file</span>
<span class="source-line-no">006</span><span id="line-6"> * to you under the Apache License, Version 2.0 (the</span>
<span class="source-line-no">007</span><span id="line-7"> * "License"); you may not use this file except in compliance</span>
<span class="source-line-no">008</span><span id="line-8"> * with the License. You may obtain a copy of the License at</span>
<span class="source-line-no">009</span><span id="line-9"> *</span>
<span class="source-line-no">010</span><span id="line-10"> * http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="source-line-no">011</span><span id="line-11"> *</span>
<span class="source-line-no">012</span><span id="line-12"> * Unless required by applicable law or agreed to in writing, software</span>
<span class="source-line-no">013</span><span id="line-13"> * distributed under the License is distributed on an "AS IS" BASIS,</span>
<span class="source-line-no">014</span><span id="line-14"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="source-line-no">015</span><span id="line-15"> * See the License for the specific language governing permissions and</span>
<span class="source-line-no">016</span><span id="line-16"> * limitations under the License.</span>
<span class="source-line-no">017</span><span id="line-17"> */</span>
<span class="source-line-no">018</span><span id="line-18">package org.apache.hadoop.hbase.util;</span>
<span class="source-line-no">019</span><span id="line-19"></span>
<span class="source-line-no">020</span><span id="line-20">import java.security.Permission;</span>
<span class="source-line-no">021</span><span id="line-21"></span>
<span class="source-line-no">022</span><span id="line-22">/**</span>
<span class="source-line-no">023</span><span id="line-23"> * class for masquerading System.exit(int). Use for test main method with System.exit(int ) usage:</span>
<span class="source-line-no">024</span><span id="line-24"> * new LauncherSecurityManager(); try { CellCounter.main(args); fail("should be exception"); } catch</span>
<span class="source-line-no">025</span><span id="line-25"> * (SecurityException e) { assert(.,e.getExitCode()); }</span>
<span class="source-line-no">026</span><span id="line-26"> */</span>
<span class="source-line-no">027</span><span id="line-27">public class LauncherSecurityManager extends SecurityManager {</span>
<span class="source-line-no">028</span><span id="line-28"></span>
<span class="source-line-no">029</span><span id="line-29"> private int exitCode;</span>
<span class="source-line-no">030</span><span id="line-30"> private SecurityManager securityManager;</span>
<span class="source-line-no">031</span><span id="line-31"></span>
<span class="source-line-no">032</span><span id="line-32"> public LauncherSecurityManager() {</span>
<span class="source-line-no">033</span><span id="line-33"> reset();</span>
<span class="source-line-no">034</span><span id="line-34"> }</span>
<span class="source-line-no">035</span><span id="line-35"></span>
<span class="source-line-no">036</span><span id="line-36"> @Override</span>
<span class="source-line-no">037</span><span id="line-37"> public void checkPermission(Permission perm, Object context) {</span>
<span class="source-line-no">038</span><span id="line-38"> if (securityManager != null) {</span>
<span class="source-line-no">039</span><span id="line-39"> // check everything with the original SecurityManager</span>
<span class="source-line-no">040</span><span id="line-40"> securityManager.checkPermission(perm, context);</span>
<span class="source-line-no">041</span><span id="line-41"> }</span>
<span class="source-line-no">042</span><span id="line-42"> }</span>
<span class="source-line-no">043</span><span id="line-43"></span>
<span class="source-line-no">044</span><span id="line-44"> @Override</span>
<span class="source-line-no">045</span><span id="line-45"> public void checkPermission(Permission perm) {</span>
<span class="source-line-no">046</span><span id="line-46"> if (securityManager != null) {</span>
<span class="source-line-no">047</span><span id="line-47"> // check everything with the original SecurityManager</span>
<span class="source-line-no">048</span><span id="line-48"> securityManager.checkPermission(perm);</span>
<span class="source-line-no">049</span><span id="line-49"> }</span>
<span class="source-line-no">050</span><span id="line-50"> }</span>
<span class="source-line-no">051</span><span id="line-51"></span>
<span class="source-line-no">052</span><span id="line-52"> @Override</span>
<span class="source-line-no">053</span><span id="line-53"> public void checkExit(int status) throws SecurityException {</span>
<span class="source-line-no">054</span><span id="line-54"> exitCode = status;</span>
<span class="source-line-no">055</span><span id="line-55"> throw new SecurityException("Intercepted System.exit(" + status + ")");</span>
<span class="source-line-no">056</span><span id="line-56"> }</span>
<span class="source-line-no">057</span><span id="line-57"></span>
<span class="source-line-no">058</span><span id="line-58"> public int getExitCode() {</span>
<span class="source-line-no">059</span><span id="line-59"> return exitCode;</span>
<span class="source-line-no">060</span><span id="line-60"> }</span>
<span class="source-line-no">061</span><span id="line-61"></span>
<span class="source-line-no">062</span><span id="line-62"> public void reset() {</span>
<span class="source-line-no">063</span><span id="line-63"> exitCode = 0;</span>
<span class="source-line-no">064</span><span id="line-64"> }</span>
<span class="source-line-no">065</span><span id="line-65"></span>
<span class="source-line-no">066</span><span id="line-66">}</span>
</pre>
</div>
</main>
</body>
</html>