*This page
applies to **Apigee** and **Apigee hybrid**.*


*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*
![](https://fonts.gstatic.com/s/i/googlematerialicons/help/v13/gm_grey-24dp/1x/gm_help_gm_grey_24dp.png)

## What is a custom JavaCallout security policy?

The [JavaCallout policy](https://docs.cloud.google.com/apigee/docs/api-platform/develop/how-create-java-callout.md.txt) enables
you to customize your API's behavior using Java code. When you implement JavaCallout, Apigee
sets default permissions for the API using
[Java permission policies](https://docs.cloud.google.com/apigee/docs/api-platform/reference/java-permission-reference.md.txt).
In Apigee hybrid, you can change the default
permissions by creating a custom JavaCallout security policy.

> [!NOTE]
> **Note:** Custom JavaCallout security policies are only available in Apigee hybrid. The security policy is scoped to the environment, and there can only be one security policy in an environment.

You can create a custom JavaCallout security policy using a
[resource](https://cloud.google.com/apis/design/resource_names), which is defined in
a resource file of type `securityPolicy`. The resource is configured at the
environment level. The resource file can have any name, but you must add the suffix
`.policy` to the custom java policy file name. For example:
`strict-security.policy`.

The following command adds a resource file named `strict-security.policy`.

```
curl -X POST "https://apigee.googleapis.com/v1/organizations/my-organization/environments/test/resourcefiles?name=CustomJavaSecurityPolicy&type=securityPolicy"
-H "Authorization: Bearer $TOKEN" \
-H "Content-type: multipart/form-data" \
-F file=@/Users/home/strict-security.policy
```
Security policy files support the same syntax as standard Java security policy; see [Default Policy Implementation and Policy File Syntax](https://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html).

<br />

Once you have created a security policy file defining a custom JavaCallout policy, Apigee runtime
can detect the policy and use the custom permissions the policy defines. If no custom JavaCallout
policy is present, Apigee uses the default security policy for custom Java or Python code.

## Security policy file

The following examples show sample content of a security policy file.

The lines below specify the location of the code for a custom JavaCallout policy and grant
all permissions to the directory.

```
Relaxed security policy file for testing
// javacallout code has just read permission in the installed dir and everything below it
  grant codeBase "file:${javacallout.dir}/-"  {
    permission java.security.AllPermission;
}
```

These lines specify the location of the code for a custom Jython/Python Callout
and grant read permissions to the directory.

```
// Jython/Python secure
grant codeBase "file:${jython-secure-jar}" {
    // No logging permissions for secure jar. Hence value of the AllExcept target parameter set to 0
    permission com.apigee.securitypolicy.AllExcept "0", "java.io.FilePermission";
    permission java.io.FilePermission "{T}conf_security-policy_install.dir{/T}/lib/-" , "read";
    // Add JRE read permissions to jython. Existing permissions have two formats to java home. Keep the same.
    permission java.io.FilePermission "${java.home}/-", "read,readLink";
    permission java.io.FilePermission "${JAVA_HOME}/-", "read,readLink";
}
```

## Examples

The following examples show how to perform specific tasks related to
custom JavaCallout security policies.

### Create a custom JavaCallout security policy

The following command creates a custom JavaCallout security policy, defined in the
resource file named `strict-security.policy`.

```
curl -X POST "https://apigee.googleapis.com/v1/organizations/my-organization/environments/test/resourcefiles?name=CustomJavaSecurityPolicy&type=securityPolicy"
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-type: multipart/form-data" \
  -F file=@/Users/home/strict-security.policy
```

### View all security policies

The following command lets you view all existing custom JavaCallout security policies in your
API.

```
curl -X GET "https://apigee.googleapis.com/v1/organizations/my-organization/environments/test/resourcefiles/securityPolicy" \
  -H "Authorization: Bearer $TOKEN"
```

### View the contents of a security policy file

The following command gets the contents of an individual security policy file so you can view it.

```
curl -X GET "https://apigee.googleapis.com/v1/organizations/my-organization/environments/test/resourcefiles/securityPolicy/CustomJavaSecurityPolicy" \
  -H "Authorization: Bearer $TOKEN"
```

### Update a policy scoped to an environment

The following command updates a security policy scoped to an environment.

```
curl -X PUT "https://apigee.googleapis.com/v1/organizations/my-organization/environments/test/resourcefiles/securityPolicy/CustomJavaSecurityPolicy"
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-type: multipart/form-data" \
  -F file=@/Users/home/strict-security-revised.policy
```

### Delete security policy scoped to an environment

The following command deletes a security policy scoped to an environment.

```
curl -X DELETE https://apigee.googleapis.com/v1/organizations/my-organization/environments/test/resourcefiles/securityPolicy/CustomJavaSecurityPolicy \
  -H "Authorization: Bearer $TOKEN"
```

<br />