Java 8 SocketPermission - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SocketPermission class.

This code example shows how to use the following methods:
        permissions.add(new PropertyPermission("*", "read"));
        permissions.add(new RuntimePermission("queuePrintJob"));
        permissions.add(new RuntimePermission("loadLibrary"));
        permissions.add(new FilePermission("*", "read"));
        permissions.add(new FilePermission("*", "write"));
        permissions.add(new SocketPermission("*", "connect"));
        DEFAULT_PERMISSIONS = permissions;
    } 
 
    public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
        final ModuleSpecification attachment = phaseContext.getDeploymentUnit().getAttachment(Attachments.MODULE_SPECIFICATION);
        if (attachment == null) {
            return; 
        } 
        if(!enabled) {
            return; 
        } 
        if (!EjbDeploymentMarker.isEjbDeployment(phaseContext.getDeploymentUnit())) {
            return; 
        } 
7
CodeRank
This code example shows how to use the following methods:newPermissionCollection
 
  public FirewallingSecurityManager() 
  { 
    parent = System.getSecurityManager();
 
    final SocketPermission localHost = new SocketPermission(LOCALHOST, PERMISSION_VALUE);
    final SocketPermission localHostRaw = new SocketPermission(LOCALHOST_IP, PERMISSION_VALUE);
    final SocketPermission localHostFqn = new SocketPermission(LOCALHOST_LOCALDOMAIN, PERMISSION_VALUE);
    permissionCollection = localHost.newPermissionCollection();
    permissionCollection.add(localHost);
    permissionCollection.add(localHostRaw);
    permissionCollection.add(localHostFqn);
  } 
 
  /** 
   * Throws a <code>SecurityException</code> if the requested 
   * access, specified by the given permission, is not permitted based 
   * on the security policy currently in effect. 
   * <p/> 
   * This method calls <code>AccessController.checkPermission</code> 
6
CodeRank
This code example shows how to use the following methods:
    private void initStaticPolicy(PermissionCollection perms) {
 
        perms.add(new java.security.SecurityPermission("getPolicy"));
        perms.add(new java.security.SecurityPermission("setPolicy"));
        perms.add(new java.lang.RuntimePermission("stopThread"));
        perms.add(new java.net.SocketPermission("localhost:1024-", "listen"));
        perms.add(new PropertyPermission("java.version","read"));
        perms.add(new PropertyPermission("java.vendor","read"));
        perms.add(new PropertyPermission("java.vendor.url","read"));
        perms.add(new PropertyPermission("java.class.version","read"));
        perms.add(new PropertyPermission("os.name","read"));
        perms.add(new PropertyPermission("os.version","read"));
        perms.add(new PropertyPermission("os.arch","read"));
        perms.add(new PropertyPermission("file.separator","read"));
        perms.add(new PropertyPermission("path.separator","read"));
        perms.add(new PropertyPermission("line.separator","read"));
        perms.add(new PropertyPermission("java.specification.version", "read"));
        perms.add(new PropertyPermission("java.specification.vendor", "read"));
        perms.add(new PropertyPermission("java.specification.name", "read"));
        perms.add(new PropertyPermission("java.vm.specification.version", "read"));
6
CodeRank
This code example shows how to use the following methods:sleep
    public static void main(String[] args) throws Exception {
 
        TestLibrary.suggestSecurityManager(null); 
 
        Permissions perms = new Permissions();
        perms.add(new SocketPermission("*:1024-", "listen"));
        AccessControlContext acc =
            new AccessControlContext(new ProtectionDomain[] {
                new ProtectionDomain(
                    new CodeSource(null, (Certificate[]) null), perms) });
 
        Remote impl = new DGCImplInsulation();;
 
        try { 
            Remote stub = (Remote) java.security.AccessController.doPrivileged(
                new ExportAction(impl));
            System.err.println("exported remote object; local stub: " + stub);
 
            MarshalledObject mobj = new MarshalledObject(stub);
            stub = (Remote) mobj.get();

6
CodeRank
This code example shows how to use the following methods:newPermissionCollection
 
  public FirewallingSecurityManager() 
  { 
    parent = System.getSecurityManager();
 
    final SocketPermission localHost = new SocketPermission(LOCALHOST, PERMISSION_VALUE);
    final SocketPermission localHostRaw = new SocketPermission(LOCALHOST_IP, PERMISSION_VALUE);
    final SocketPermission localHostFqn = new SocketPermission(LOCALHOST_LOCALDOMAIN, PERMISSION_VALUE);
    permissionCollection = localHost.newPermissionCollection();
    permissionCollection.add(localHost);
    permissionCollection.add(localHostRaw);
    permissionCollection.add(localHostFqn);
  } 
 
  /** 
   * Throws a <code>SecurityException</code> if the requested 
   * access, specified by the given permission, is not permitted based 
   * on the security policy currently in effect. 
   * <p/> 
   * This method calls <code>AccessController.checkPermission</code> 
5
CodeRank
This code example shows how to use the following methods:
     */ 
    @SuppressWarnings("nls") 
    public void test_checkPermissionLjava_security_PermissionLjava_lang_Object() { 
        // enable all but one check 
        mutableSM.addPermission(new AllPermission());
        Permission denyp = new SocketPermission("localhost:1024-",
                "accept, connect, listen"); 
        mutableSM.denyPermission(denyp);
        ProtectionDomain pDomain = this.getClass().getProtectionDomain();
        ProtectionDomain[] pd = { pDomain };
        AccessControlContext acc = new AccessControlContext(pd);
        try { 
            mutableSM.checkPermission(denyp, acc);
            fail("This should throw a SecurityException.");
        } catch (SecurityException e) {
            // expected 
        } 
    } 
 
    /** 
5
CodeRank
This code example shows how to use the following methods:
    private void initStaticPolicy(PermissionCollection perms) {
 
        perms.add(new java.security.SecurityPermission("getPolicy"));
        perms.add(new java.security.SecurityPermission("setPolicy"));
        perms.add(new java.lang.RuntimePermission("stopThread"));
        perms.add(new java.net.SocketPermission("localhost:1024-", "listen"));
        perms.add(new PropertyPermission("java.version","read"));
        perms.add(new PropertyPermission("java.vendor","read"));
        perms.add(new PropertyPermission("java.vendor.url","read"));
        perms.add(new PropertyPermission("java.class.version","read"));
        perms.add(new PropertyPermission("os.name","read"));
        perms.add(new PropertyPermission("os.version","read"));
        perms.add(new PropertyPermission("os.arch","read"));
        perms.add(new PropertyPermission("file.separator","read"));
        perms.add(new PropertyPermission("path.separator","read"));
        perms.add(new PropertyPermission("line.separator","read"));
        perms.add(new PropertyPermission("java.specification.version", "read"));
        perms.add(new PropertyPermission("java.specification.vendor", "read"));
        perms.add(new PropertyPermission("java.specification.name", "read"));
        perms.add(new PropertyPermission("java.vm.specification.version", "read"));
5
CodeRank
This code example shows how to use the following methods:
public class ActionSpace { 
 
    public static void main(String[]args) throws Exception { 
        try { 
            SocketPermission sp = 
                new SocketPermission("*", "connect , accept"); 
        } catch (Exception e) { 
            throw new Exception("should not have caught an exception"); 
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:
public class NoAction { 
 
    public static void main(String[] args) throws Exception {
        SocketPermission sp = null;
        try { 
            sp = new SocketPermission("localhost", "");
            throw new Exception("Expected IllegalArgumentException not "
                                + "thrown"); 
        } catch (IllegalArgumentException iae) {
            System.out.println("Expected IllegalArgumentException thrown");
        } 
 
        try { 
            sp = new SocketPermission("localhost", null);
            throw new Exception("Expected NullPointerException not "
                                + "thrown"); 
        } catch (NullPointerException npe) {
            System.out.println("Expected NullPointerException thrown");
        } 
    } 
5
CodeRank
This code example shows how to use the following methods:
			initHostsAndPorts(networkPart, SOCKET_PERMISSION_CONNECT);
		} 
	} 
 
	protected void initHostsAndPorts(String networkPart, String action) {
		SocketPermission socketPermission = new SocketPermission(
			networkPart, action);
 
		_permissions.add(socketPermission);
	} 
 
	protected void initListenPorts() { 
		String[] listenParts = getPropertyArray(
			"security-manager-sockets-listen"); 
 
		for (String listenPart : listenParts) {
			initListenPorts(listenPart);
		} 
	} 
 
5
CodeRank
See Code Examples for Java 8 SocketPermission Methods: