Class OctetUtils


  • public final class OctetUtils
    extends Object
    This class centralizes much of the conversion code that is repeated throughout many attributes that have the same model implementations. The criteria for addition here is use by two or more Attribute subclasses. All attributes have different conceptual entities that they carry. But many of those entities have the same type or set of types. In the lists below are grouped all of the currently defined attribute implementations by the internal object type that they contain save for the last list which contains those that all have their own custom models. This class, OctetUtils, provides code that does the bulk of the work for those classes that have the same underlying model types. The following attributes all contain a String value that can vary from one byte to as much as can be held in the maximum on-the-wire attribute value length, MAX_ATTRIBUTE_VALUE_LENGTH, as defined in the Attribute class:
     com.sun.identity.authentication.modules.radius.client.CallbackIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallbackNumberAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CHAPChallengeAttribute
     com.sun.identity.authentication.modules.radius.client.FilterIdAttribute
     com.sun.identity.authentication.modules.radius.client.FramedAppleTalkZoneAttribute
     com.sun.identity.authentication.modules.radius.client.FramedRouteAttribute
     com.sun.identity.authentication.modules.radius.client.LoginLATGroupAttribute
     com.sun.identity.authentication.modules.radius.client.LoginLATNodeAttribute
     com.sun.identity.authentication.modules.radius.client.LoginLATPortAttribute
     com.sun.identity.authentication.modules.radius.client.LoginLATServiceAttribute
     com.sun.identity.authentication.modules.radius.client.NASClassAttribute
     com.sun.identity.authentication.modules.radius.client.NASIdentifierAttribute
     com.sun.identity.authentication.modules.radius.client.ProxyStateAttribute
     ReplyMessageAttribute
     StateAttribute
     UserNameAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     com.sun.identity.authentication.modules.radius.client.CallerStationIdAttribute
     
    The following attributes contain a four byte integer value:
     com.sun.identity.authentication.modules.radius.client.FramedAppleTalkLinkAttribute
     com.sun.identity.authentication.modules.radius.client.FramedAppleTalkNetworkAttribute
     com.sun.identity.authentication.modules.radius.client.FramedCompressionAttribute
     com.sun.identity.authentication.modules.radius.client.FramedMTUAttribute
     com.sun.identity.authentication.modules.radius.client.FramedProtocolAttribute
     com.sun.identity.authentication.modules.radius.client.FramedRoutingAttribute
     com.sun.identity.authentication.modules.radius.client.IdleTimeoutAttribute
     com.sun.identity.authentication.modules.radius.client.LoginIPHostAttribute
     com.sun.identity.authentication.modules.radius.client.LoginServiceAttribute
     com.sun.identity.authentication.modules.radius.client.LoginTCPPortAttribute
     com.sun.identity.authentication.modules.radius.client.NASPortAttribute
     com.sun.identity.authentication.modules.radius.client.NASPortTypeAttribute
     com.sun.identity.authentication.modules.radius.client.PortLimitAttribute
     com.sun.identity.authentication.modules.radius.client.ServiceTypeAttribute
     com.sun.identity.authentication.modules.radius.client.SessionTimeoutAttribute
     com.sun.identity.authentication.modules.radius.client.TerminationActionAttribute
     
    The following classes contain a four byte array value:
     com.sun.identity.authentication.modules.radius.client.FramedIPAddressAttribute
     com.sun.identity.authentication.modules.radius.client.FramedIPNetmaskAttribute
     com.sun.identity.authentication.modules.radius.client.FramedIPXNetworkAttribute
     
    The following classes have unique models described and hence have their own unique code that can't be shared among other attribute classes:
     com.sun.identity.authentication.modules.radius.client.CHAPPasswordAttribute
      - class contains a single byte integer value followed by 16 bytes of text characters.
    
     UserPasswordAttribute
      - has an encrypted string of characters.
    
     com.sun.identity.authentication.modules.radius.client.NASIPAddressAttribute
      - has a four octets on the wire but uses an InetAddress object internally.
    
     com.sun.identity.authentication.modules.radius.client.VendorSpecificAttribute
      - has a four byte integer followed by the remaining space containing textual characters.
     
    Created by boydmr on 6/16/15.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int toIntVal​(byte[] octets)
      Extracts the integer value from the octets of an attribute known to hold a single integer value.
      static byte[] toOctets​(AttributeType type, int intValue)
      Crafts the on-the-wire octet array conforming to the format of section 3 of RFC 2865 with the single contained value being an integer.
      static byte[] toOctets​(AttributeType type, int msb, int msb2, int msb3, int msb4)
      Crafts the on-the-wire octet array conforming to the format of section 3 of RFC 2865 with the contained value being a four byte array such as an IPV4 network address or mask.
      static byte[] toOctets​(AttributeType type, String str)
      Crafts the on-the-wire octet array conforming to the format of section 3 of RFC 2865 with the value being a string possibly truncated to fit into the maximum of 253 characters allowed for values.
    • Method Detail

      • toOctets

        public static final byte[] toOctets​(AttributeType type,
                                            String str)
        Crafts the on-the-wire octet array conforming to the format of section 3 of RFC 2865 with the value being a string possibly truncated to fit into the maximum of 253 characters allowed for values.
        Parameters:
        type - the type of the attribute
        str - the value of the attribute
        Returns:
        the on-the-wire byte representation
      • toOctets

        public static final byte[] toOctets​(AttributeType type,
                                            int intValue)
        Crafts the on-the-wire octet array conforming to the format of section 3 of RFC 2865 with the single contained value being an integer.
        Parameters:
        type - the type of the attribute
        intValue - the value of the attribute
        Returns:
        the on-the-wire byte representation
      • toOctets

        public static final byte[] toOctets​(AttributeType type,
                                            int msb,
                                            int msb2,
                                            int msb3,
                                            int msb4)
        Crafts the on-the-wire octet array conforming to the format of section 3 of RFC 2865 with the contained value being a four byte array such as an IPV4 network address or mask.
        Parameters:
        type - the type of the attribute
        msb - the most significant byte
        msb2 - the 2nd most significant byte
        msb3 - the 3rd most significant byte
        msb4 - the 4th most significant byte
        Returns:
        the on-the-wire octets for an attribute with four bytes of content.
      • toIntVal

        public static final int toIntVal​(byte[] octets)
        Extracts the integer value from the octets of an attribute known to hold a single integer value.
        Parameters:
        octets - the on-the-wire bytes for the attribute
        Returns:
        intValue the value of the attribute