use of java.security.AccessControlException in project hive by apache.
the class Hadoop23Shims method wrapAccessException.
/**
* If there is an AccessException buried somewhere in the chain of failures, wrap the original
* exception in an AccessException. Othewise just return the original exception.
*/
private static Exception wrapAccessException(Exception err) {
final int maxDepth = 20;
Throwable curErr = err;
for (int idx = 0; curErr != null && idx < maxDepth; ++idx) {
// Hadoop versions may still see this exception .. have to reference by name.
if (curErr instanceof org.apache.hadoop.security.AccessControlException || curErr.getClass().getName().equals("org.apache.hadoop.fs.permission.AccessControlException")) {
Exception newErr = new AccessControlException(curErr.getMessage());
newErr.initCause(err);
return newErr;
}
curErr = curErr.getCause();
}
return err;
}
use of java.security.AccessControlException in project Payara by payara.
the class SSLUtils method checkPermission.
public static void checkPermission(String key) {
try {
// Checking a random permission to check if it is server.
if (Util.isEmbeddedServer() || Util.getDefaultHabitat() == null || Util.getInstance().isACC() || Util.getInstance().isNotServerOrACC()) {
return;
}
Permission perm = new RuntimePermission("SSLPassword");
AccessController.checkPermission(perm);
} catch (AccessControlException e) {
String message = e.getMessage();
Permission perm = new PropertyPermission(key, "read");
if (message != null) {
message = message.replace(e.getPermission().toString(), perm.toString());
}
throw new AccessControlException(message, perm);
}
}
use of java.security.AccessControlException in project Payara by payara.
the class SecuritySupportImpl method checkPermission.
public void checkPermission(String key) {
try {
// Checking a random permission to check if it is server.
if (isEmbeddedServer() || habitat == null || isACC() || isNotServerORACC()) {
return;
}
Permission perm = new RuntimePermission("SSLPassword");
AccessController.checkPermission(perm);
} catch (AccessControlException e) {
String message = e.getMessage();
Permission perm = new PropertyPermission(key, "read");
if (message != null) {
message = message.replace(e.getPermission().toString(), perm.toString());
}
throw new AccessControlException(message, perm);
}
}
use of java.security.AccessControlException in project Payara by payara.
the class StandardServer method await.
/**
* Wait until a proper shutdown command is received, then return.
*/
public void await() {
// Set up a server socket to wait on
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1"));
} catch (IOException e) {
String msg = MessageFormat.format(rb.getString(LogFacade.STANDARD_SERVER_AWAIT_CREATE_EXCEPTION), port);
log.log(Level.SEVERE, msg, e);
System.exit(1);
}
// Loop waiting for a connection and a valid command
while (true) {
// Wait for the next connection
Socket socket = null;
InputStream stream = null;
try {
socket = serverSocket.accept();
// Ten seconds
socket.setSoTimeout(10 * 1000);
stream = socket.getInputStream();
} catch (AccessControlException ace) {
String msg = MessageFormat.format(rb.getString(LogFacade.STANDARD_SERVER_ACCEPT_SECURITY_EXCEPTION), ace.getMessage());
log.log(Level.WARNING, msg, ace);
continue;
} catch (IOException e) {
String msg = MessageFormat.format(rb.getString(LogFacade.STANDARD_SERVER_AWAIT_ACCEPT_EXCEPTION), e.toString());
log.log(Level.SEVERE, msg, e);
System.exit(1);
}
// Read a set of characters from the socket
StringBuilder command = new StringBuilder();
// Cut off to avoid DoS attack
int expected = 1024;
while (expected < shutdown.length()) {
if (random == null) {
random = new SecureRandom();
}
expected += random.nextInt(1024);
}
while (expected > 0) {
int ch = -1;
try {
ch = stream.read();
} catch (IOException e) {
String msg = MessageFormat.format(rb.getString(LogFacade.STANDARD_SERVER_AWAIT_READ_EXCEPTION), e.toString());
log.log(Level.WARNING, msg, e);
ch = -1;
}
if (// Control character or EOF terminates loop
ch < 32)
break;
command.append((char) ch);
expected--;
}
// Close the socket now that we are done with it
try {
socket.close();
} catch (IOException e) {
// Ignore
}
// Match against our command string
boolean match = command.toString().equals(shutdown);
if (match) {
break;
} else {
log.log(Level.WARNING, LogFacade.STANDARD_SERVER_AWAIT_INVALID_COMMAND_RECEIVED_EXCEPTION, command.toString());
}
}
// Close the server socket and return
try {
serverSocket.close();
} catch (IOException e) {
// Ignore
}
}
Aggregations