Class SecurityPolicyExamples

java.lang.Object
net.jrodolfo.java_evolution.java02.security.SecurityPolicyExamples

public class SecurityPolicyExamples extends Object
Demonstrates the Java 2 security-policy model with ordinary permission objects.

Java 2 generalized security around code sources, protection domains, permissions, and policy grants. This example models those concepts directly without installing a SecurityManager or loading a policy file, because Security Manager based enforcement is deprecated and disabled in modern Java.

  • Constructor Details

    • SecurityPolicyExamples

      public SecurityPolicyExamples()
  • Method Details

    • trustedCodeSource

      public CodeSource trustedCodeSource() throws MalformedURLException
      Creates a synthetic code source representing where code came from.
      Returns:
      a code source for a trusted application location
      Throws:
      MalformedURLException - if the synthetic URI cannot be converted to a URL
    • domainWithConnectPermission

      public ProtectionDomain domainWithConnectPermission() throws MalformedURLException
      Creates a protection domain with one explicit permission grant.
      Returns:
      a protection domain that can connect to one service endpoint
      Throws:
      MalformedURLException - if the synthetic code source cannot be created
    • canConnectToApi

      public boolean canConnectToApi() throws MalformedURLException
      Checks whether the domain implies the granted connect permission.
      Returns:
      true because the permission collection grants connect access
      Throws:
      MalformedURLException - if the synthetic code source cannot be created
    • cannotListenOnApiPort

      public boolean cannotListenOnApiPort() throws MalformedURLException
      Checks whether the same domain implies a different, ungranted action.
      Returns:
      false because listen access was not granted
      Throws:
      MalformedURLException - if the synthetic code source cannot be created
    • grantedPermissions

      public PermissionCollection grantedPermissions() throws MalformedURLException
      Exposes the static permission collection used by the protection domain.
      Returns:
      the static permission collection
      Throws:
      MalformedURLException - if the synthetic code source cannot be created
    • modelSummary

      public String modelSummary()
      Explains the core Java 2 security model in one sentence.
      Returns:
      a short model summary
    • modernBoundary

      public String modernBoundary()
      Explains the modern boundary of this example.
      Returns:
      a short boundary explanation