public class NetworkSecurityPolicy extends Object
isPlaintextAccessAllowed() method in this
class to check whether plaintext is allowed for accessing a process.
An application can declare its network security settings in a security configuration file without modifying the code.
Calling methods in this class has the following advantages:
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static NetworkSecurityPolicy |
getInstance() |
Obtains the
NetworkSecurityPolicy instance for this process. |
boolean |
isPlaintextAccessAllowed() |
Checks whether plaintext is allowed for all network communications with this process.
|
boolean |
isPlaintextAccessAllowed(String hostname) |
Checks whether plaintext is allowed for the communication between this process and a specified hostname.
|
public static NetworkSecurityPolicy getInstance()
NetworkSecurityPolicy instance for this process.
You can obtain the NetworkSecurityPolicy instance in singleton pattern,
but cannot create such an instance using the new method.
NetworkSecurityPolicy instance for this process.public boolean isPlaintextAccessAllowed()
If plaintext is not allowed, the platform's components (such as HTTP and FTP stacks) will refuse plaintext HTTP requests from this process.
Theoretically, a network security policy is needed whenever possible. However, not all
components support the network security policy. An example is the java.net.Socket API,
which is unable to determine whether the network traffic is plaintext. Generally, most network traffic from
applications is handled by higher-level network stacks or components that support the network security policy.
true if plaintext is allowed for all network communications with this process;
returns false otherwise.public boolean isPlaintextAccessAllowed(String hostname)
hostname - Indicates the specified hostname.true if plaintext is allowed for the communication between this process
and the specified hostname; returns false otherwise.