Code example for SocketPermission

0
    @SuppressWarnings("nls") 
    public void test_checkConnectLjava_lang_String_int_Ljava_lang_Object() { 
        // enable all but one check 
        mutableSM.addPermission(new AllPermission());
        mutableSM.denyPermission(new SocketPermission("localhost:1024-",
                "accept, connect, listen")); 
        ProtectionDomain pDomain = this.getClass().getProtectionDomain();
        ProtectionDomain[] pd = { pDomain };
        AccessControlContext acc = new AccessControlContext(pd);
        try { 
            mutableSM.checkConnect("localhost", 1024, acc);
            fail("This should throw a SecurityException.");
        } catch (SecurityException e) {
            // expected 
        } 
    } 
 
    /** 
     * @tests {@link java.lang.SecurityManager#checkExec(String)} 
     */ 
    @SuppressWarnings("nls")