1 package org.libvirt; 2 3 import org.libvirt.jna.Libvirt; 4 import com.sun.jna.Native; 5 6 /** 7 * Represents a security label used for mandatory access control. 8 * 9 * @see Domain#getSecurityLabel 10 */ 11 public final class SecurityLabel { 12 private final String label; 13 private final boolean enforced; 14 private static final byte NUL = 0; 15 SecurityLabel(final Libvirt.SecurityLabel seclabel)16 SecurityLabel(final Libvirt.SecurityLabel seclabel) { 17 label = Native.toString(seclabel.label, "UTF-8"); 18 enforced = seclabel.enforcing == 1; 19 } 20 21 /** 22 * Returns the label of this SecurityLabel. 23 * 24 * @return the security label string 25 */ getLabel()26 public String getLabel() { 27 return label; 28 } 29 30 /** 31 * Returns true if the security policy is being enforced. 32 * 33 * @return true if the policy is enforced, false otherwise 34 */ isEnforced()35 public boolean isEnforced() { 36 return enforced; 37 } 38 39 @Override toString()40 public String toString() { 41 return new StringBuilder() 42 .append("(label=") 43 .append(label) 44 .append(", enforced=") 45 .append(enforced) 46 .append(")") 47 .toString(); 48 } 49 } 50