The following equals, dominates, and strictlyDominates methods are used to compare labels, and correspond to the blequal(), bldominate(), and blstrictdom() routines. The inRange method is used to determine whether a label is within a specified label range, and corresponds to the blinrange() routine. In these methods, a label refers to a classification and a set of compartments in a sensitivity label or in a clearance label. For more information, see Comparing Labels and the blcompare(3TSOL) man page.
The dominates method compares two labels to determine whether one label dominates the other.
The following example code shows how you can make the comparison. The CNF : INTERNAL label is being compared to check its dominance over the PUBLIC label.
SensitivityLabel sl = SolarisLabel.getSensitivityLabel("CNF : INTERNAL"); boolean isDominant = sl.dominates(SolarisLabel.getSensitivityLabel("PUBLIC")); |
The equals method compares two labels to determine whether they are equal.
The following example code shows how you can make the comparison:
SensitivityLabel sl = SolarisLabel.getSensitivityLabel("CNF : INTERNAL"); boolean isSame = sl.equals(SolarisLabel.getSensitivityLabel("PUBLIC")); |
The inRange method determines whether the specified label is within the range. This method belongs to the Range class.
The following code fragment shows how you can verify that a file is within a user's clearance range:
import solarismac.*; import java.io.*; public class Example1 { public static void main (String args[]) { try { Range range; range = Range.getUserRange("jweeks"); SensitivityLabel fsl = SolarisLabel.getFileLabel(new File("/etc/passwd")); boolean isInRange; isInRange = Range.inRange(fsl); if (isInRange) System.out.println("File is within user's range"); else System.out.println("File is not within user's range"); } catch (Exception e) { e.PrintStackTrace(); } } } |
The strictlyDominates method compares two labels to determine whether one label strictly dominates the other. When a label strictly dominates another, it dominates the other label, but is not equal to the other label.
The following example code shows how you can make the comparison. The CNF : INTERNAL label is being compared to check its strict dominance over the PUBLIC label.
SensitivityLabel sl = SolarisLabel.getSensitivityLabel("CNF : INTERNAL"); boolean isStrictlyDominant = sl.strictlyDominates(SolarisLabel.getSensitivityLabel("PUBLIC")); |
For more information about label relationships, see Label Relationships.
The getMaximum and getMinimum methods are used to determine the least upper bound and the greatest lower bound of the specified label range, respectively. These methods mirror the functionality of the blmaximum() and blminimum() routines. For more information, see Comparing Labels and the blminmax(3TSOL) man page.
For instance, use the getMaximum method to determine the label to use when creating a new labeled object that combines information from two other labeled objects. The label of the new object will dominate both of the original labeled objects. Each method is defined by the ClearanceLabel and SensitivityLabel subclasses.
The getMaximum method creates a new clearance label object that is the lowest label that can dominate two label objects you specify. The resulting object is the least upper bound of the range. getMaximum returns an object in the internal form of the clearance label.
The getMinimum method creates a new clearance label object that is the highest label that is dominated by two labels you specify. The resulting object is the greatest lower bound of the range. getMinimum returns an object in the internal form of the clearance label.
The getMaximum method creates a new sensitivity label object that is the lowest label that can dominate two label objects you specify. The resulting object is the least upper bound of the range. getMaximum returns an object in the internal form of the sensitivity label.
The getMinimum method creates a new sensitivity label object that is the highest label that is dominated by two labels you specify. The resulting object is the greatest lower bound of the range. getMinimum returns an object in the internal form of the sensitivity label.
The following table shows label input and output from the getMaximum and getMinimum methods.
Table 9–1 Using the getMinimum and getMaximum Methods
Input Labels |
getMinimum Output |
getMaximum Output |
---|---|---|
SECRET A B TOP SECRET A B SA SB CC |
SECRET A B |
TOP SECRET A B SA SB CC |
SECRET A B TOP SECRET A SA CC |
SECRET A |
TOP SECRET A B SA CC |
SECRET A B TOP SECRET |
SECRET |
TOP SECRET A B |
SECRET A TOP SECRET B |
SECRET |
TOP SECRET A B |