Search in sources :

Example 66 with AccessControlException

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;
}
Also used : AccessControlException(java.security.AccessControlException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AccessControlException(java.security.AccessControlException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 67 with AccessControlException

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);
    }
}
Also used : PropertyPermission(java.util.PropertyPermission) PropertyPermission(java.util.PropertyPermission) Permission(java.security.Permission) AccessControlException(java.security.AccessControlException)

Example 68 with AccessControlException

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);
    }
}
Also used : PropertyPermission(java.util.PropertyPermission) PropertyPermission(java.util.PropertyPermission) Permission(java.security.Permission) AccessControlException(java.security.AccessControlException)

Example 69 with AccessControlException

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
    }
}
Also used : InputStream(java.io.InputStream) AccessControlException(java.security.AccessControlException) SecureRandom(java.security.SecureRandom) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Aggregations

AccessControlException (java.security.AccessControlException)69 IOException (java.io.IOException)24 Test (org.junit.Test)12 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)10 Permission (java.security.Permission)8 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)8 InputStream (java.io.InputStream)7 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)7 File (java.io.File)5 PropertyPermission (java.util.PropertyPermission)5 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)5 FileNotFoundException (java.io.FileNotFoundException)4 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 HashSet (java.util.HashSet)4 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)4 ServerSocket (java.net.ServerSocket)3 Socket (java.net.Socket)3 URISyntaxException (java.net.URISyntaxException)3 UnsafeCharArrayWriter (jetbrick.template.utils.UnsafeCharArrayWriter)3 FileSystem (org.apache.hadoop.fs.FileSystem)3