Example usage for java.security Permission getName

List of usage examples for java.security Permission getName

Introduction

In this page you can find the example usage for java.security Permission getName.

Prototype


public final String getName() 

Source Link

Document

Returns the name of this Permission.

Usage

From source file:com.cloudera.sqoop.util.SubprocessSecurityManager.java

@Override
/**/*from   w w w.j a  v  a  2  s. c  o  m*/
 * Check a particular permission. Checks with this SecurityManager
 * as well as any previously-installed manager.
 *
 * @param perm the Permission to check; must not be null.
 */
public void checkPermission(Permission perm) {
    if (null != this.parentSecurityManager) {
        // Check if the prior SecurityManager would have rejected this.
        parentSecurityManager.checkPermission(perm);
    }

    if (!allowReplacement && perm.getName().equals("setSecurityManager")) {
        throw new SecurityException("Cannot replace security manager");
    }
}

From source file:net.lightbody.bmp.proxy.jetty.util.URLResource.java

/**
 * Returns an File representing the given resource or NULL if this
 * is not possible./*w w  w.j  a  v  a2s  .c  om*/
 */
public File getFile() throws IOException {
    // Try the permission hack
    if (checkConnection()) {
        Permission perm = _connection.getPermission();
        if (perm instanceof java.io.FilePermission)
            return new File(perm.getName());
    }

    // Try the URL file arg
    try {
        return new File(_url.getFile());
    } catch (Exception e) {
        LogSupport.ignore(log, e);
    }

    // Don't know the file
    return null;
}

From source file:org.browsermob.proxy.jetty.util.FileResource.java

FileResource(URL url) throws IOException, URISyntaxException {
    super(url, null);

    try {/* w  w w. java 2 s  . com*/
        // Try standard API to convert URL to file.
        _file = new File(new URI(url.toString()));
    } catch (Exception e) {
        LogSupport.ignore(log, e);
        try {
            // Assume that File.toURL produced unencoded chars. So try
            // encoding them.
            String urls = "file:" + org.browsermob.proxy.jetty.util.URI.encodePath(url.toString().substring(5));
            _file = new File(new URI(urls));
        } catch (Exception e2) {
            LogSupport.ignore(log, e2);

            // Still can't get the file.  Doh! try good old hack!
            checkConnection();
            Permission perm = _connection.getPermission();
            _file = new File(perm == null ? url.getFile() : perm.getName());
        }
    }

    if (_file.isDirectory() && !_urlString.endsWith("/"))
        _urlString = _urlString + "/";
}

From source file:net.lightbody.bmp.proxy.jetty.util.FileResource.java

FileResource(URL url) throws IOException, URISyntaxException {
    super(url, null);

    try {/*from   w w w .  jav a  2s .  c o  m*/
        // Try standard API to convert URL to file.
        _file = new File(new URI(url.toString()));
    } catch (Exception e) {
        LogSupport.ignore(log, e);
        try {
            // Assume that File.toURL produced unencoded chars. So try
            // encoding them.
            String urls = "file:"
                    + net.lightbody.bmp.proxy.jetty.util.URI.encodePath(url.toString().substring(5));
            _file = new File(new URI(urls));
        } catch (Exception e2) {
            LogSupport.ignore(log, e2);

            // Still can't get the file.  Doh! try good old hack!
            checkConnection();
            Permission perm = _connection.getPermission();
            _file = new File(perm == null ? url.getFile() : perm.getName());
        }
    }

    if (_file.isDirectory() && !_urlString.endsWith("/"))
        _urlString = _urlString + "/";
}

From source file:org.openqa.jetty.util.FileResource.java

FileResource(URL url) throws IOException, URISyntaxException {
    super(url, null);

    try {// w  w  w. ja va 2s . c o m
        // Try standard API to convert URL to file.
        _file = new File(new URI(url.toString()));
    } catch (Exception e) {
        LogSupport.ignore(log, e);
        try {
            // Assume that File.toURL produced unencoded chars. So try
            // encoding them.
            String urls = "file:" + org.openqa.jetty.util.URI.encodePath(url.toString().substring(5));
            _file = new File(new URI(urls));
        } catch (Exception e2) {
            LogSupport.ignore(log, e2);

            // Still can't get the file.  Doh! try good old hack!
            checkConnection();
            Permission perm = _connection.getPermission();
            _file = new File(perm == null ? url.getFile() : perm.getName());
        }
    }

    if (_file.isDirectory() && !_urlString.endsWith("/"))
        _urlString = _urlString + "/";
}

From source file:org.openqa.selenium.server.FutureFileResource.java

public FutureFileResource(URL url) throws IOException {
    super(url, null);

    try {/*from w ww . ja va 2 s  . com*/
        // Try standard API to convert URL to file.
        _file = new File(new URI(url.toString()));
    } catch (Exception e) {
        LogSupport.ignore(log, e);
        try {
            // Assume that File.toURL produced unencoded chars. So try
            // encoding them.
            String urls = "file:" + org.openqa.jetty.util.URI.encodePath(url.toString().substring(5));
            _file = new File(new URI(urls));
        } catch (Exception e2) {
            LogSupport.ignore(log, e2);

            // Still can't get the file.  Doh! try good old hack!
            checkConnection();
            Permission perm = _connection.getPermission();
            _file = new File(perm == null ? url.getFile() : perm.getName());
        }
    }

    if (_file.isDirectory() && !_urlString.endsWith("/"))
        _urlString = _urlString + "/";
}

From source file:org.lockss.jetty.FilteredDirFileResource.java

public FilteredDirFileResource(URL url, FilenameFilter filter) throws IOException, URISyntaxException {
    super(url, null);
    _filter = filter;/*from www  .j  a v  a 2  s  .c  o m*/

    try {
        // Try standard API to convert URL to file.
        _file = new File(new URI(url.toString()));
    } catch (Exception e) {
        LogSupport.ignore(log, e);
        try {
            // Assume that File.toURL produced unencoded chars. So try
            // encoding them.
            String urls = "file:" + org.mortbay.util.URI.encodePath(url.toString().substring(5));
            _file = new File(new URI(urls));
        } catch (Exception e2) {
            LogSupport.ignore(log, e2);

            // Still can't get the file.  Doh! try good old hack!
            checkConnection();
            Permission perm = _connection.getPermission();
            _file = new File(perm == null ? url.getFile() : perm.getName());
        }
    }
}

From source file:org.pepstock.jem.springbatch.tasks.SpringBatchSecurityManager.java

@Override
public void checkPermission(Permission perm) {
    // checks if someone add a security manager
    if (perm instanceof RuntimePermission && "setSecurityManager".equalsIgnoreCase(perm.getName())) {
        LogAppl.getInstance().emit(NodeMessage.JEMC274E);
        throw new SecurityException(NodeMessage.JEMC274E.toMessage().getMessage());
    }//from  w  w  w  . ja v  a2  s.c o m
    // this check is necessary to avoid that someone
    // set jem properties, accessing outside of GFS
    if (perm instanceof PropertyPermission && "write".equalsIgnoreCase(perm.getActions())
            && perm.getName().startsWith("jem")) {
        LogAppl.getInstance().emit(NodeMessage.JEMC127E);
        throw new SecurityException(NodeMessage.JEMC127E.toMessage().getMessage());
    }
    // checks is administrator. if true return.
    if (isAdministrator() || isInternalAction()) {
        return;
    }
    // checks the file access
    // calling the right method, in according
    // with the action of permission
    if (perm instanceof FilePermission) {
        if ("read".equalsIgnoreCase(perm.getActions())) {
            checkRead(perm.getName());
        } else if ("write".equalsIgnoreCase(perm.getActions())) {
            checkWrite(perm.getName());
        } else if ("delete".equalsIgnoreCase(perm.getActions())) {
            checkDelete(perm.getName());
        } else {
            checkRead(perm.getName());
        }
    } else if (perm instanceof SocketPermission) {
        // checks the RMI access.
        // checks to RMI is not allowed if you're not a admin
        SocketPermission sperm = (SocketPermission) perm;
        int port = Parser.parseInt(StringUtils.substringAfter(sperm.getName(), ":"), Integer.MAX_VALUE);
        int portRmi = Parser.parseInt(System.getProperty(RmiKeys.JEM_RMI_PORT), Integer.MIN_VALUE);
        // if is going to RMI port and
        // is not executing JEM code and is not grantor
        if (port == portRmi && !isInternalAction() && !isGrantor()) {
            // extracts host name
            String hostname = StringUtils.substringBefore(sperm.getName(), ":");
            try {
                // gets hostname and localhost 
                String resolved = InetAddress.getByName(hostname).getHostAddress();
                String localhost = InetAddress.getLocalHost().getHostAddress();
                // if they are equals and the user
                // desn't have the internal service permission
                // EXCEPTION!!
                if (resolved.equalsIgnoreCase(localhost)
                        && !checkBatchPermission(Permissions.INTERNAL_SERVICES)) {
                    LogAppl.getInstance().emit(NodeMessage.JEMC128E);
                    throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage());
                }
            } catch (UnknownHostException e) {
                // if there is an error on resolving the hostname
                LogAppl.getInstance().emit(NodeMessage.JEMC128E);
                throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage(), e);
            }
        }
    }
}

From source file:org.pepstock.jem.jbpm.tasks.JBpmBatchSecurityManager.java

@Override
public void checkPermission(Permission perm) {
    // checks if someone add a security manager
    // if yes, exception
    if (perm instanceof RuntimePermission && "setSecurityManager".equalsIgnoreCase(perm.getName())) {
        LogAppl.getInstance().emit(NodeMessage.JEMC274E);
        throw new SecurityException(NodeMessage.JEMC274E.toMessage().getMessage());
    }//  ww w.j  a  v  a2  s  .  c o m

    // this check is necessary to avoid that someone
    // set jem properties, accessing outside of GFS
    if (perm instanceof PropertyPermission && "write".equalsIgnoreCase(perm.getActions())
            && perm.getName().startsWith("jem")) {
        LogAppl.getInstance().emit(NodeMessage.JEMC127E);
        throw new SecurityException(NodeMessage.JEMC127E.toMessage().getMessage());
    }
    // checks is administrator. if true return.
    // checks if we are inside a code no custom but of JEM
    // necessary to be executed (internalAction)
    if (isAdministrator() || isInternalAction()) {
        return;
    }
    // checks the file access
    if (perm instanceof FilePermission) {
        if ("read".equalsIgnoreCase(perm.getActions())) {
            checkRead(perm.getName());
        } else if ("write".equalsIgnoreCase(perm.getActions())) {
            checkWrite(perm.getName());
        } else if ("delete".equalsIgnoreCase(perm.getActions())) {
            checkDelete(perm.getName());
        } else {
            checkRead(perm.getName());
        }
    } else if (perm instanceof SocketPermission) {
        // checks the RMI access.
        // accessing to RMI locally, you could creates some inconsistent situation
        // for JEM and this is not secured
        // checks to RMI is not allowed if you're not a admin
        SocketPermission sperm = (SocketPermission) perm;
        int port = Parser.parseInt(StringUtils.substringAfter(sperm.getName(), ":"), Integer.MAX_VALUE);
        int portRmi = Parser.parseInt(System.getProperty(RmiKeys.JEM_RMI_PORT), Integer.MIN_VALUE);
        // checks if it's going to RMI port
        if (port == portRmi && !isInternalAction() && !isGrantor()) {
            String hostname = StringUtils.substringBefore(sperm.getName(), ":");
            try {
                String resolved = InetAddress.getByName(hostname).getHostAddress();
                String localhost = InetAddress.getLocalHost().getHostAddress();
                // if you're accessing to RMI port
                // and locally, an exception will be launched
                // if you don't have the INTERNAL services authorization.
                if (resolved.equalsIgnoreCase(localhost)
                        && !checkBatchPermission(Permissions.INTERNAL_SERVICES)) {
                    LogAppl.getInstance().emit(NodeMessage.JEMC128E);
                    throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage());
                }
            } catch (UnknownHostException e) {
                LogAppl.getInstance().emit(NodeMessage.JEMC128E);
                throw new SecurityException(NodeMessage.JEMC128E.toMessage().getMessage(), e);
            }
        }
    }
}

From source file:org.jboss.dashboard.security.PermissionDescriptor.java

public void setPermission(Permission perm) {
    permissionClass = null;/*from w w w  .j  av  a2  s  . c  o  m*/
    permissionResource = null;
    permissionActions = null;

    if (perm != null) {
        permissionClass = perm.getClass().getName();
        permissionResource = perm.getName();
        permissionActions = perm.getActions();
    }
}