Oracle Solaris Trusted Extensions Developer's Guide

Translating Between Labels and Strings

The SolarisLabel abstract class includes methods for translating between labels and strings, which are inherited by its subclasses.

These methods translate the internal representation of a label (m_label_t) to String objects.

You can use the toInternal method to translate a label into a string that hides the classification name. This format is suitable for storing labels in public objects.

The running Java virtual machine must dominate the label to be translated, or it must have the sys_trans_label privilege. See the label_to_str(3TSOL) man page.

Some of the label values are based on data in the label_encodings file.

The following methods mimic the label_to_str() routine. See the label_to_str(3TSOL) man page.

public final java.lang.String toColor()

This method returns the color of the SolarisLabel object. The value is suitable for use by HTML.

public final java.lang.String toInternal()

This method returns the internal representation of the label that is safe for storing in a public object. An internal conversion can later be parsed to its same value. This is the same as using the toString method.

These two methods differ in the way that they handle errors. If the toInternal method encounters an error, it returns a java.io.IOException. However, if the toString method encounters an error, it returns a null.

public java.lang.String toString()

This method returns the internal hexadecimal version of the label in string form, which is the same as using the toInternal method.

These two methods differ in the way that they handle errors. If the toString method encounters an error, it returns a null. However, if the toInternal method encounters an error, it returns a java.io.IOException.

public java.lang.String toText()

This method returns a human-readable text string of the SolarisLabel object.

public java.lang.String toTextLong()

This method returns the long human-readable text string of the SolarisLabel object.

public java.lang.String toTextShort()

This method returns the short human-readable text string of the SolarisLabel object.

The following methods perform label translations that are suitable for creating multilevel printer banner pages. These methods mimic some of the functionality of the label_to_str() routine. See the label_to_str(3TSOL) and m_label(3TSOL) man pages.

public java.lang.String toCaveats()

This method returns a human-readable text string that is suitable for the caveats section of the banner page.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toChannels()

This method returns a human-readable text string that is suitable for the handling channels section of the banner page.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toFooter()

This method returns a human-readable text string that is appropriate for use as the sensitivity label. This sensitivity label appears at the bottom of banner and trailing pages.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toHeader()

This method returns a human-readable text string that is appropriate for use as the sensitivity label. This sensitivity label appears at the top of banner and trailing pages.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.

public java.lang.String toProtectAs()

This method returns a human-readable text string that is suitable for the page downgrade section of the banner page.

This method is only available for SensitivityLabel objects, not for ClearanceLabel objects.


Example 9–1 Using the Java Bindings to Create a Banner Page

The following example code shows how to use the Java bindings to create a banner page similar to the one described in Obtaining Printer Banner Information.


import solarismac.*;
import java.io.*;

/*
 * Banner page example
 */
public class PrintTest1
{

   public static void main (String args[]) {

      try {

         // Pick a valid label using the label_encodings.example
         SensitivityLabel sl = SolarisLabel.getSensitivityLabel("TOP SECRET A B SA");

         // "Protect as classification"
         System.out.println(sl.toHeader());
         System.out.println();

         // "Protect as classification plus compartments"
         System.out.println("This output must be protected as:");
         System.out.println(sl.toProtectAs());
         System.out.println("unless manually reviewed and downgraded.");
         System.out.println();

         // Handling instructions specified in PRINTER BANNERS
         System.out.println(sl.toCaveats());
         System.out.println();

         // Handling instructions specified in CHANNELS
         System.out.println(sl.toChannels());
         System.out.println();

         // "Protect as classification"
         System.out.println(sl.toFooter());
         System.out.println();

      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

For a process label of TOP SECRET A B SA, the text output might be the following:


		TOP SECRET

This output must be protected as:

TOP SECRET A B SA

unless manually reviewed and downgraded.

   (FULL SA NAME)
   HANDLE VIA (CH B)/(CH A) CHANNELS JOINTLY

		TOP SECRET

Methods such as toText, toInternal, and toColor do not translate from a string to a label. To translate a string to a sensitivity label or to a clearance label, you must call the getSensitivityLabel or getClearanceLabel static factories, respectively. The following static factories mimic the str_to_label() routine. See the str_to_label(3TSOL) and m_label(3TSOL) man pages.

public static ClearanceLabel getClearanceLabel(java.lang.String label)

This static factory creates a clearance label from the specified string. The following examples create new clearance labels based on a label name and the internal hexadecimal name of a label:


ClearanceLabel cl = SolarisLabel.getClearanceLabel("PUBLIC");
ClearanceLabel cl = SolarisLabel.getClearanceLabel("0x0002-08-08");
public static SensitivityLabel getSensitivityLabel(java.lang.String label)

This static factory creates a sensitivity label from the specified string. The following examples create new sensitivity labels based on a label name and the internal hexadecimal name of a label:


SensitivityLabel sl = SolarisLabel.getSensitivityLabel("PUBLIC");
SensitivityLabel sl = SolarisLabel.getSensitivityLabel("0x0002-08-08");