Search in sources :

Example 21 with GetPropertyAction

use of sun.security.action.GetPropertyAction in project jdk8u_jdk by JetBrains.

the class FtpURLConnection method connect.

/**
     * Connects to the FTP server and logs in.
     *
     * @throws  FtpLoginException if the login is unsuccessful
     * @throws  FtpProtocolException if an error occurs
     * @throws  UnknownHostException if trying to connect to an unknown host
     */
public synchronized void connect() throws IOException {
    if (connected) {
        return;
    }
    Proxy p = null;
    if (instProxy == null) {
        // no per connection proxy specified
        /**
             * Do we have to use a proxy?
             */
        ProxySelector sel = java.security.AccessController.doPrivileged(new java.security.PrivilegedAction<ProxySelector>() {

            public ProxySelector run() {
                return ProxySelector.getDefault();
            }
        });
        if (sel != null) {
            URI uri = sun.net.www.ParseUtil.toURI(url);
            Iterator<Proxy> it = sel.select(uri).iterator();
            while (it.hasNext()) {
                p = it.next();
                if (p == null || p == Proxy.NO_PROXY || p.type() == Proxy.Type.SOCKS) {
                    break;
                }
                if (p.type() != Proxy.Type.HTTP || !(p.address() instanceof InetSocketAddress)) {
                    sel.connectFailed(uri, p.address(), new IOException("Wrong proxy type"));
                    continue;
                }
                // OK, we have an http proxy
                InetSocketAddress paddr = (InetSocketAddress) p.address();
                try {
                    http = new HttpURLConnection(url, p);
                    http.setDoInput(getDoInput());
                    http.setDoOutput(getDoOutput());
                    if (connectTimeout >= 0) {
                        http.setConnectTimeout(connectTimeout);
                    }
                    if (readTimeout >= 0) {
                        http.setReadTimeout(readTimeout);
                    }
                    http.connect();
                    connected = true;
                    return;
                } catch (IOException ioe) {
                    sel.connectFailed(uri, paddr, ioe);
                    http = null;
                }
            }
        }
    } else {
        // per connection proxy specified
        p = instProxy;
        if (p.type() == Proxy.Type.HTTP) {
            http = new HttpURLConnection(url, instProxy);
            http.setDoInput(getDoInput());
            http.setDoOutput(getDoOutput());
            if (connectTimeout >= 0) {
                http.setConnectTimeout(connectTimeout);
            }
            if (readTimeout >= 0) {
                http.setReadTimeout(readTimeout);
            }
            http.connect();
            connected = true;
            return;
        }
    }
    if (user == null) {
        user = "anonymous";
        String vers = java.security.AccessController.doPrivileged(new GetPropertyAction("java.version"));
        password = java.security.AccessController.doPrivileged(new GetPropertyAction("ftp.protocol.user", "Java" + vers + "@"));
    }
    try {
        ftp = FtpClient.create();
        if (p != null) {
            ftp.setProxy(p);
        }
        setTimeouts();
        if (port != -1) {
            ftp.connect(new InetSocketAddress(host, port));
        } else {
            ftp.connect(new InetSocketAddress(host, FtpClient.defaultPort()));
        }
    } catch (UnknownHostException e) {
        // Just keep throwing for now.
        throw e;
    } catch (FtpProtocolException fe) {
        throw new IOException(fe);
    }
    try {
        ftp.login(user, password == null ? null : password.toCharArray());
    } catch (sun.net.ftp.FtpProtocolException e) {
        ftp.close();
        // Backward compatibility
        throw new sun.net.ftp.FtpLoginException("Invalid username/password");
    }
    connected = true;
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) FtpProtocolException(sun.net.ftp.FtpProtocolException) URI(java.net.URI) ProxySelector(java.net.ProxySelector) FtpProtocolException(sun.net.ftp.FtpProtocolException) Proxy(java.net.Proxy) GetPropertyAction(sun.security.action.GetPropertyAction) HttpURLConnection(sun.net.www.protocol.http.HttpURLConnection)

Example 22 with GetPropertyAction

use of sun.security.action.GetPropertyAction in project jdk8u_jdk by JetBrains.

the class PipeWriter method main.

/**
     * Main program to start the activation system. <br>
     * The usage is as follows: rmid [-port num] [-log dir].
     */
public static void main(String[] args) {
    boolean stop = false;
    // already.
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }
    try {
        int port = ActivationSystem.SYSTEM_PORT;
        RMIServerSocketFactory ssf = null;
        /*
             * If rmid has an inherited channel (meaning that it was
             * launched from inetd), set the server socket factory to
             * return the inherited server socket.
             **/
        Channel inheritedChannel = AccessController.doPrivileged(new PrivilegedExceptionAction<Channel>() {

            public Channel run() throws IOException {
                return System.inheritedChannel();
            }
        });
        if (inheritedChannel != null && inheritedChannel instanceof ServerSocketChannel) {
            /*
                 * Redirect System.err output to a file.
                 */
            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {

                public Void run() throws IOException {
                    File file = Files.createTempFile("rmid-err", null).toFile();
                    PrintStream errStream = new PrintStream(new FileOutputStream(file));
                    System.setErr(errStream);
                    return null;
                }
            });
            ServerSocket serverSocket = ((ServerSocketChannel) inheritedChannel).socket();
            port = serverSocket.getLocalPort();
            ssf = new ActivationServerSocketFactory(serverSocket);
            System.err.println(new Date());
            System.err.println(getTextResource("rmid.inherited.channel.info") + ": " + inheritedChannel);
        }
        String log = null;
        List<String> childArgs = new ArrayList<>();
        /*
             * Parse arguments
             */
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-port")) {
                if (ssf != null) {
                    bomb(getTextResource("rmid.syntax.port.badarg"));
                }
                if ((i + 1) < args.length) {
                    try {
                        port = Integer.parseInt(args[++i]);
                    } catch (NumberFormatException nfe) {
                        bomb(getTextResource("rmid.syntax.port.badnumber"));
                    }
                } else {
                    bomb(getTextResource("rmid.syntax.port.missing"));
                }
            } else if (args[i].equals("-log")) {
                if ((i + 1) < args.length) {
                    log = args[++i];
                } else {
                    bomb(getTextResource("rmid.syntax.log.missing"));
                }
            } else if (args[i].equals("-stop")) {
                stop = true;
            } else if (args[i].startsWith("-C")) {
                childArgs.add(args[i].substring(2));
            } else {
                bomb(MessageFormat.format(getTextResource("rmid.syntax.illegal.option"), args[i]));
            }
        }
        if (log == null) {
            if (ssf != null) {
                bomb(getTextResource("rmid.syntax.log.required"));
            } else {
                log = "log";
            }
        }
        debugExec = AccessController.doPrivileged(new GetBooleanAction("sun.rmi.server.activation.debugExec"));
        /**
             * Determine class name for activation exec policy (if any).
             */
        String execPolicyClassName = AccessController.doPrivileged(new GetPropertyAction("sun.rmi.activation.execPolicy", null));
        if (execPolicyClassName == null) {
            if (!stop) {
                DefaultExecPolicy.checkConfiguration();
            }
            execPolicyClassName = "default";
        }
        /**
             * Initialize method for activation exec policy.
             */
        if (!execPolicyClassName.equals("none")) {
            if (execPolicyClassName.equals("") || execPolicyClassName.equals("default")) {
                execPolicyClassName = DefaultExecPolicy.class.getName();
            }
            try {
                Class<?> execPolicyClass = getRMIClass(execPolicyClassName);
                execPolicy = execPolicyClass.newInstance();
                execPolicyMethod = execPolicyClass.getMethod("checkExecCommand", ActivationGroupDesc.class, String[].class);
            } catch (Exception e) {
                if (debugExec) {
                    System.err.println(getTextResource("rmid.exec.policy.exception"));
                    e.printStackTrace();
                }
                bomb(getTextResource("rmid.exec.policy.invalid"));
            }
        }
        if (stop == true) {
            final int finalPort = port;
            AccessController.doPrivileged(new PrivilegedAction<Void>() {

                public Void run() {
                    System.setProperty("java.rmi.activation.port", Integer.toString(finalPort));
                    return null;
                }
            });
            ActivationSystem system = ActivationGroup.getSystem();
            system.shutdown();
            System.exit(0);
        }
        /*
             * Fix for 4173960: Create and initialize activation using
             * a static method, startActivation, which will build the
             * Activation state in two ways: if when rmid is run, no
             * log file is found, the ActLogHandler.recover(...)
             * method will create a new Activation instance.
             * Alternatively, if a logfile is available, a serialized
             * instance of activation will be read from the log's
             * snapshot file.  Log updates will be applied to this
             * Activation object until rmid's state has been fully
             * recovered.  In either case, only one instance of
             * Activation is created.
             */
        startActivation(port, ssf, log, childArgs.toArray(new String[childArgs.size()]));
        // prevent activator from exiting
        while (true) {
            try {
                Thread.sleep(Long.MAX_VALUE);
            } catch (InterruptedException e) {
            }
        }
    } catch (Exception e) {
        System.err.println(MessageFormat.format(getTextResource("rmid.unexpected.exception"), e));
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : ArrayList(java.util.ArrayList) ActivationSystem(java.rmi.activation.ActivationSystem) RMIServerSocketFactory(java.rmi.server.RMIServerSocketFactory) ServerSocketChannel(java.nio.channels.ServerSocketChannel) PrintStream(java.io.PrintStream) GetBooleanAction(sun.security.action.GetBooleanAction) Channel(java.nio.channels.Channel) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ServerSocket(java.net.ServerSocket) ConnectIOException(java.rmi.ConnectIOException) IOException(java.io.IOException) Date(java.util.Date) ActivationException(java.rmi.activation.ActivationException) UnknownGroupException(java.rmi.activation.UnknownGroupException) ConnectIOException(java.rmi.ConnectIOException) NotBoundException(java.rmi.NotBoundException) MissingResourceException(java.util.MissingResourceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) AccessControlException(java.security.AccessControlException) UnknownObjectException(java.rmi.activation.UnknownObjectException) NoSuchObjectException(java.rmi.NoSuchObjectException) AccessException(java.rmi.AccessException) SocketException(java.net.SocketException) ConnectException(java.rmi.ConnectException) IOException(java.io.IOException) AlreadyBoundException(java.rmi.AlreadyBoundException) GetPropertyAction(sun.security.action.GetPropertyAction) FileOutputStream(java.io.FileOutputStream) ActivationGroupDesc(java.rmi.activation.ActivationGroupDesc) PolicyFile(sun.security.provider.PolicyFile) File(java.io.File)

Example 23 with GetPropertyAction

use of sun.security.action.GetPropertyAction in project jdk8u_jdk by JetBrains.

the class ReliableLog method getLogClassConstructor.

/**
     * Returns the constructor for the log file if the system property
     * sun.rmi.log.class is non-null and the class specified by the
     * property a) can be loaded, b) is a subclass of LogFile, and c) has a
     * public two-arg constructor (String, String); otherwise returns null.
     **/
private static Constructor<? extends LogFile> getLogClassConstructor() {
    String logClassName = AccessController.doPrivileged(new GetPropertyAction("sun.rmi.log.class"));
    if (logClassName != null) {
        try {
            ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {

                public ClassLoader run() {
                    return ClassLoader.getSystemClassLoader();
                }
            });
            Class<? extends LogFile> cl = loader.loadClass(logClassName).asSubclass(LogFile.class);
            return cl.getConstructor(String.class, String.class);
        } catch (Exception e) {
            System.err.println("Exception occurred:");
            e.printStackTrace();
        }
    }
    return null;
}
Also used : GetPropertyAction(sun.security.action.GetPropertyAction) RMIClassLoader(java.rmi.server.RMIClassLoader)

Example 24 with GetPropertyAction

use of sun.security.action.GetPropertyAction in project jdk8u_jdk by JetBrains.

the class XToolkit method initSecurityWarning.

static void initSecurityWarning() {
    // Enable warning only for internal builds
    String runtime = AccessController.doPrivileged(new GetPropertyAction("java.runtime.version"));
    securityWarningEnabled = (runtime != null && runtime.contains("internal"));
}
Also used : GetPropertyAction(sun.security.action.GetPropertyAction)

Example 25 with GetPropertyAction

use of sun.security.action.GetPropertyAction in project jdk8u_jdk by JetBrains.

the class Util method atBugLevel.

static boolean atBugLevel(String bl) {
    // package-private
    if (bugLevel == null) {
        if (!sun.misc.VM.isBooted())
            return false;
        String value = AccessController.doPrivileged(new GetPropertyAction("sun.nio.ch.bugLevel"));
        bugLevel = (value != null) ? value : "";
    }
    return bugLevel.equals(bl);
}
Also used : GetPropertyAction(sun.security.action.GetPropertyAction)

Aggregations

GetPropertyAction (sun.security.action.GetPropertyAction)26 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Graphics (java.awt.Graphics)1 Rectangle (java.awt.Rectangle)1 Toolkit (java.awt.Toolkit)1 CMMException (java.awt.color.CMMException)1 ContainerEvent (java.awt.event.ContainerEvent)1 ContainerListener (java.awt.event.ContainerListener)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetSocketAddress (java.net.InetSocketAddress)1 Proxy (java.net.Proxy)1 ProxySelector (java.net.ProxySelector)1 ServerSocket (java.net.ServerSocket)1 SocketException (java.net.SocketException)1 URI (java.net.URI)1