org.opcfoundation.ua.utils
Class EndpointUtil

java.lang.Object
  extended by org.opcfoundation.ua.utils.EndpointUtil

public class EndpointUtil
extends Object

Discovery client enumerates endpoints. Current version supports only opc.tcp protocol.


Constructor Summary
EndpointUtil()
           
 
Method Summary
static boolean containsSecureUserTokenPolicy(UserTokenPolicy[] userIdentityTokens)
          containsSecureUserTokenPolicy.
static UserIdentityToken createAnonymousIdentityToken(EndpointDescription ep)
          Create anonymous user identity token
static UserIdentityToken createIssuedIdentityToken(EndpointDescription ep, byte[] senderNonce, byte[] issuedIdentityToken)
          Create user identity token based on an issued token
static UserIdentityToken createUserNameIdentityToken(EndpointDescription ep, byte[] senderNonce, String username, String password)
          Create user identity token based on username and password
static X509IdentityToken createX509IdentityToken(EndpointDescription ep, byte[] serverNonce, Cert certificate, PrivateKey key, SignatureData signatureData)
          createX509IdentityToken.
static String getHostname()
          Figure out some random hostname for this computer
static Set<InetAddress> getInetAddresses()
          Get all Internet addresses of this computer.
static Set<InetAddress> getInetAddresses(boolean enableIPv6)
          Get all Internet addresses of this computer.
static Set<String> getInetAddressNames()
          Get all internet address names of this computer.
static String inetAddressToName(InetAddress addr)
          inetAddressToName.
static void reverse(Object array)
          Reverse elements of an array
static EndpointDescription select(EndpointDescription[] endpoints)
          Select an endpoint that is supported by the stack and has the highest security level.
static EndpointDescription[] select(EndpointDescription[] searchSet, int minKeySize, int maxKeySize)
          select.
static EndpointDescription select(EndpointDescription[] endpoints, String url)
          select.
static EndpointDescription[] select(EndpointDescription[] searchSet, String url, String protocol, MessageSecurityMode mode, SecurityPolicy policy, byte[] serverCertificate)
          Filter endpoints by various criteria
static EndpointDescription[] selectByMessageSecurityMode(EndpointDescription[] searchSet, MessageSecurityMode mode)
          Selects all endpoints that conform to given message security mode
static EndpointDescription[] selectByProtocol(EndpointDescription[] searchSet, String protocol)
          Selects all endpoints that conform to given protcol
static EndpointDescription[] selectBySecurityPolicy(EndpointDescription[] searchSet, SecurityPolicy policy)
          Selects all endpoints that conform to given message security mode
static EndpointDescription[] selectByUrl(EndpointDescription[] searchSet, String url)
          Selects all endpoints with the given url.
static EndpointDescription selectEndpoint(EndpointDescription[] endpoints)
          Select the most suitable endpoint.
static EndpointDescription[] sortBySecurityLevel(EndpointDescription[] set)
          Sorts endpoints by their security level.
static List<SocketAddress> toSocketAddresses(String endpointUrl)
          Convert endpoint url to socket addresses.
static List<SocketAddress> toSocketAddresses(String endpointUrl, boolean enableIPv6)
          Convert endpoint url to socket addresses.
static boolean urlEqualsHostIgnoreCase(String endpointUrl, String url)
          Check if the endpointUrl matches the url, except for the hostname part.
static boolean urlEqualsHostIgnoreCase(URI uri, URI requestedUri)
          Check if the endpointUrl matches the url, except for the hostname part.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EndpointUtil

public EndpointUtil()
Method Detail

select

public static EndpointDescription select(EndpointDescription[] endpoints,
                                         String url)
                                  throws ServiceResultException

select.

Parameters:
endpoints - an array of EndpointDescription objects.
url - a String object.
Returns:
a EndpointDescription object.
Throws:
ServiceResultException - if any.

select

public static EndpointDescription select(EndpointDescription[] endpoints)
                                  throws ServiceResultException
Select an endpoint that is supported by the stack and has the highest security level.

Parameters:
endpoints - an array of EndpointDescription objects.
Returns:
encrypted endpoint
Throws:
ServiceResultException - error

select

public static EndpointDescription[] select(EndpointDescription[] searchSet,
                                           String url,
                                           String protocol,
                                           MessageSecurityMode mode,
                                           SecurityPolicy policy,
                                           byte[] serverCertificate)
Filter endpoints by various criteria

Parameters:
searchSet - set of endpoints
url - filter by url (inclusive, case insensitive) or null
protocol - filter by protocol (inclusive) or null
mode - filter by mode or null
policy - filter by policy or null
serverCertificate - an array of byte.
Returns:
filtered endpoints

select

public static EndpointDescription[] select(EndpointDescription[] searchSet,
                                           int minKeySize,
                                           int maxKeySize)

select.

Parameters:
searchSet - an array of EndpointDescription objects.
minKeySize - a int.
maxKeySize - a int.
Returns:
an array of EndpointDescription objects.

selectByProtocol

public static EndpointDescription[] selectByProtocol(EndpointDescription[] searchSet,
                                                     String protocol)
Selects all endpoints that conform to given protcol

Parameters:
searchSet - an array of EndpointDescription objects.
protocol - a String object.
Returns:
A subset of searchSet whose elements use given protocol

selectByMessageSecurityMode

public static EndpointDescription[] selectByMessageSecurityMode(EndpointDescription[] searchSet,
                                                                MessageSecurityMode mode)
Selects all endpoints that conform to given message security mode

Parameters:
searchSet - an array of EndpointDescription objects.
mode - a MessageSecurityMode object.
Returns:
A subset of searchSet whose elements use given message security mode

selectBySecurityPolicy

public static EndpointDescription[] selectBySecurityPolicy(EndpointDescription[] searchSet,
                                                           SecurityPolicy policy)
Selects all endpoints that conform to given message security mode

Parameters:
searchSet - an array of EndpointDescription objects.
policy - a SecurityPolicy object.
Returns:
A subset of searchSet whose elements use given message security mode

selectByUrl

public static EndpointDescription[] selectByUrl(EndpointDescription[] searchSet,
                                                String url)
Selects all endpoints with the given url. Compare is case-insensitive.

Parameters:
searchSet - an array of urls
url - a String object.
Returns:
A subset of searchSet whose elements use given message security mode

sortBySecurityLevel

public static EndpointDescription[] sortBySecurityLevel(EndpointDescription[] set)
Sorts endpoints by their security level. The highest security level last.

Parameters:
set - set of endpoints
Returns:
sorted array of endpoints

selectEndpoint

public static EndpointDescription selectEndpoint(EndpointDescription[] endpoints)
Select the most suitable endpoint.

Selection uses the following precedence: 1) Protocol must be opc.tcp (as http is not implemented) 2) Security uses sign and encrypt 3) Select highest security level (determined by the server) 4) Prefer hostname over localhost

Parameters:
endpoints - an array of EndpointDescription objects.
Returns:
compatible endpoint or null

reverse

public static void reverse(Object array)
Reverse elements of an array

Parameters:
array - a Object object.

createUserNameIdentityToken

public static UserIdentityToken createUserNameIdentityToken(EndpointDescription ep,
                                                            byte[] senderNonce,
                                                            String username,
                                                            String password)
                                                     throws ServiceResultException
Create user identity token based on username and password

Parameters:
ep - a EndpointDescription object.
username - a String object.
password - a String object.
senderNonce - an array of byte.
Returns:
user identity token
Throws:
ServiceResultException - if endpoint or the stack doesn't support UserName token policy

createIssuedIdentityToken

public static UserIdentityToken createIssuedIdentityToken(EndpointDescription ep,
                                                          byte[] senderNonce,
                                                          byte[] issuedIdentityToken)
                                                   throws ServiceResultException
Create user identity token based on an issued token

Parameters:
ep - a EndpointDescription object.
senderNonce - an array of byte.
issuedIdentityToken - an array of byte.
Returns:
user identity token
Throws:
ServiceResultException - if endpoint or the stack doesn't support UserName token policy

getInetAddresses

public static Set<InetAddress> getInetAddresses()
                                         throws SocketException
Get all Internet addresses of this computer. Excludes IPv6 addresses.

Returns:
all Internet addresses of this computer.
Throws:
SocketException - if any.

getInetAddresses

public static Set<InetAddress> getInetAddresses(boolean enableIPv6)
                                         throws SocketException
Get all Internet addresses of this computer.

Parameters:
enableIPv6 - Set true to enable IPv6 addressing. Requires Java 7 or later on Windows platforms.
Returns:
all Internet addresses of this computer
Throws:
SocketException - if any.

getHostname

public static String getHostname()
                          throws SocketException
Figure out some random hostname for this computer

Returns:
a String object.
Throws:
SocketException - if any.

getInetAddressNames

public static Set<String> getInetAddressNames()
                                       throws SocketException
Get all internet address names of this computer.

Returns:
all internet address names of this computer in URL compatible format
Throws:
SocketException - if any.

inetAddressToName

public static String inetAddressToName(InetAddress addr)

inetAddressToName.

Parameters:
addr - a InetAddress object.
Returns:
a String object.

toSocketAddresses

public static List<SocketAddress> toSocketAddresses(String endpointUrl)
                                             throws IllegalArgumentException
Convert endpoint url to socket addresses.

Parameters:
endpointUrl - a String object.
Returns:
a collection of bind addresses
Throws:
IllegalArgumentException - endpointUrl is problematic some way

toSocketAddresses

public static List<SocketAddress> toSocketAddresses(String endpointUrl,
                                                    boolean enableIPv6)
                                             throws IllegalArgumentException
Convert endpoint url to socket addresses.

Parameters:
endpointUrl - a String object.
enableIPv6 - Set true to enable IPv6 addressing. Requires Java 7 or later on Windows platforms.
Returns:
a collection of bind addresses
Throws:
IllegalArgumentException - endpointUrl is problematic some way

createAnonymousIdentityToken

public static UserIdentityToken createAnonymousIdentityToken(EndpointDescription ep)
                                                      throws ServiceResultException
Create anonymous user identity token

Parameters:
ep - a EndpointDescription object.
Returns:
user identity token
Throws:
ServiceResultException - if endpoint or the stack doesn't support Anonymous token policy

createX509IdentityToken

public static X509IdentityToken createX509IdentityToken(EndpointDescription ep,
                                                        byte[] serverNonce,
                                                        Cert certificate,
                                                        PrivateKey key,
                                                        SignatureData signatureData)
                                                 throws ServiceResultException

createX509IdentityToken.

Parameters:
ep - a EndpointDescription object.
serverNonce - an array of byte.
certificate - a Cert object.
key - a PrivateKey object.
signatureData - a SignatureData object.
Returns:
a X509IdentityToken object.
Throws:
ServiceResultException - if any.

urlEqualsHostIgnoreCase

public static boolean urlEqualsHostIgnoreCase(URI uri,
                                              URI requestedUri)
Check if the endpointUrl matches the url, except for the hostname part.

Parameters:
uri - a URI object.
requestedUri - a URI object.
Returns:
a boolean.

urlEqualsHostIgnoreCase

public static boolean urlEqualsHostIgnoreCase(String endpointUrl,
                                              String url)
Check if the endpointUrl matches the url, except for the hostname part.

Parameters:
endpointUrl - a String object.
url - a String object.
Returns:
a boolean.

containsSecureUserTokenPolicy

public static boolean containsSecureUserTokenPolicy(UserTokenPolicy[] userIdentityTokens)

containsSecureUserTokenPolicy.

Parameters:
userIdentityTokens - an array of UserTokenPolicy objects.
Returns:
a boolean.


Copyright © 2018. All rights reserved.