usr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/AuthAttrObj.java
changeset 847 a8e124b894b8
equal deleted inserted replaced
846:0a2af4721353 847:a8e124b894b8
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panels.usermgr.client.swing;
       
    27 
       
    28 import java.lang.*;
       
    29 import java.io.*;
       
    30 import java.util.*;
       
    31 
       
    32 /**
       
    33  * SMC code adapted for Visual Panels
       
    34  *
       
    35  * Description:
       
    36  * The AuthAttrObj class encapsulates the set of authorizations currently
       
    37  * set for the specified user.
       
    38  *
       
    39  * @return    none.
       
    40  */
       
    41 
       
    42 public class AuthAttrObj extends ExtAttrObj implements Cloneable {
       
    43 
       
    44     // Private attributes back stopped by persistent storage
       
    45     private String authName = null;	// The authorization name
       
    46     private String [] shortDesc = null; // Short description (32 chars)
       
    47     private String [] longDesc = null;	// Long description, not localized
       
    48     private boolean visible = true;
       
    49 
       
    50     // The following is the list of attribute keys that are supported.
       
    51 
       
    52     public static final String SOLARIS_AUTH_HELP = "help";
       
    53     public static final String SOLARIS_ALL = "*";
       
    54     public static final String SOLARIS_DOT = ".";
       
    55     public static final String SOLARIS_GRANT = "grant";
       
    56     public static final String SOLARIS_SLASH = "/";
       
    57 
       
    58 
       
    59     /**
       
    60      *	Null constructor.
       
    61      *
       
    62      */
       
    63     public AuthAttrObj() {
       
    64 
       
    65 	super();
       
    66 
       
    67     }
       
    68 
       
    69     /**
       
    70      * This constructor takes the authorization name.
       
    71      *
       
    72      */
       
    73     public AuthAttrObj(String authName) {
       
    74 
       
    75 	super();
       
    76 	this.authName = authName;
       
    77 
       
    78     }
       
    79 
       
    80 
       
    81     // Public methods
       
    82 
       
    83     /**
       
    84      * Return a copy of this object.
       
    85      *
       
    86      * @return	A new copy of this object
       
    87      *
       
    88      */
       
    89     public Object clone() {
       
    90 
       
    91 	AuthAttrObj newobj = new AuthAttrObj(this.authName);
       
    92 	newobj.setShortDesc(this.shortDesc);
       
    93 	newobj.setLongDesc(this.longDesc);
       
    94 
       
    95 	super.clone(newobj);
       
    96 	return (newobj);
       
    97 
       
    98     }
       
    99 
       
   100     /**
       
   101      * Check if this instance matches another AuthAttrObj instance.
       
   102      * The other instance matches this instance if it has the
       
   103      * same authorization name.
       
   104      *
       
   105      * @param  otherAttr  The other AuthAttrObj instance
       
   106      *
       
   107      * @returnTrue if the other instance matches this one
       
   108      *
       
   109      */
       
   110     public boolean matches(AuthAttrObj otherAttr) {
       
   111 
       
   112 	boolean bool = false;
       
   113 	try {
       
   114 	    if (this.authName.equals(otherAttr.getAuthName()))
       
   115 		bool = true;
       
   116 	} catch (Exception ex) {
       
   117 	}
       
   118 	return (bool);
       
   119 
       
   120     }
       
   121 
       
   122     /**
       
   123      * Return the authorization name.
       
   124      *
       
   125      * @return The authorization name
       
   126      *
       
   127      */
       
   128     public String getAuthName() {
       
   129 
       
   130 	return (this.authName);
       
   131 
       
   132     }
       
   133 
       
   134     /**
       
   135      * Return the authorization name.
       
   136      *
       
   137      * @return The authorization name
       
   138      *
       
   139      */
       
   140     public String getName() {
       
   141 
       
   142 	int i = authName.indexOf(SOLARIS_SLASH);
       
   143 	String nameStr;
       
   144 
       
   145 	if (i >= 0) {
       
   146 	    nameStr = authName.substring(i+1);
       
   147 	    if (nameStr.equals(SOLARIS_ALL)) {
       
   148 		nameStr = "All";
       
   149 	    }
       
   150 	} else {
       
   151 	    nameStr = authName;
       
   152 	}
       
   153 
       
   154 	return (nameStr);
       
   155 
       
   156     }
       
   157 
       
   158     /**
       
   159      * Set the authorization name.
       
   160      *
       
   161      * @param	The authorization name
       
   162      *
       
   163      */
       
   164     public void setAuthName(String authName) {
       
   165 
       
   166 	this.authName = authName;
       
   167 
       
   168     }
       
   169 
       
   170     /**
       
   171      * Return a copy of this object.
       
   172      *
       
   173      * @return	A new copy of this object
       
   174      *
       
   175      */
       
   176     public String getShortDesc() {
       
   177 
       
   178 	if (this.shortDesc == null)
       
   179 	    return (null);
       
   180 	else
       
   181 	    return (this.shortDesc[0]);
       
   182 
       
   183     }
       
   184 
       
   185     /**
       
   186      * Return an array of short descriptions for the authorization.
       
   187      *
       
   188      * @return	An array of short descriptions
       
   189      *
       
   190      */
       
   191     public String [] getShortDescs() {
       
   192 
       
   193 	if (this.shortDesc == null)
       
   194 	    return (null);
       
   195 	else
       
   196 	    return (this.shortDesc);
       
   197 
       
   198     }
       
   199 
       
   200     /**
       
   201      * Set the short description for this authorizations.
       
   202      * Any existing descriptions are replaced.
       
   203      *
       
   204      * @param	The short description
       
   205      *
       
   206      */
       
   207     public void setShortDesc(String shortDesc) {
       
   208 
       
   209 	if (this.shortDesc == null)
       
   210 	    this.shortDesc = new String [1];
       
   211 	this.shortDesc[0] = shortDesc;
       
   212 
       
   213     }
       
   214 
       
   215     /**
       
   216      * Set an array of short descriptions for the authorization.
       
   217      * Any existing descriptions are replaced.
       
   218      *
       
   219      * @param	The authorization name
       
   220      *
       
   221      */
       
   222     public void setShortDesc(String [] shortDesc) {
       
   223 
       
   224 	this.shortDesc = shortDesc;
       
   225 
       
   226     }
       
   227 
       
   228     /**
       
   229      * Return a localized short description.
       
   230      *
       
   231      * @return	A localized short description
       
   232      *
       
   233      */
       
   234     public String getShortDesc(Locale locale) {
       
   235 
       
   236 	if (this.shortDesc == null)
       
   237 	    return null;
       
   238 	else
       
   239 	    return (this.shortDesc[0]);
       
   240 
       
   241     }
       
   242 
       
   243     /**
       
   244      * Return the relative pathname of the authorization help file
       
   245      * on the management server.
       
   246      *
       
   247      * @return	A help file pathname
       
   248      *
       
   249      */
       
   250     public String getHelpFileName() {
       
   251 
       
   252 	Vector v = this.getAttribute(SOLARIS_AUTH_HELP);
       
   253 	if ((v != null) && (v.size() > 0))
       
   254 	    return ((String) v.elementAt(0));
       
   255 	else
       
   256 	    return (null);
       
   257     }
       
   258 
       
   259     /**
       
   260      * Set the relative pathname of the authorization help file
       
   261      * on the management server.  Any existing help file pathnames
       
   262      * are replaced.
       
   263      *
       
   264      * @param	A help file pathname
       
   265      *
       
   266      */
       
   267     public void setHelpFileName(String helpFile) {
       
   268 
       
   269 	this.setAttribute(SOLARIS_AUTH_HELP, helpFile);
       
   270 
       
   271     }
       
   272 
       
   273     /**
       
   274     /**
       
   275      * Return the relative pathname of the authorization help file
       
   276      * on the management server.
       
   277     /**
       
   278      * Return the relative pathname of the authorization help file
       
   279      * on the management server.
       
   280      *
       
   281      * @return	A help file pathname
       
   282      *
       
   283      */
       
   284     public String getLongDescId() {
       
   285 
       
   286 	Vector v = this.getAttribute(SOLARIS_AUTH_HELP);
       
   287 	if ((v != null) && (v.size() > 0))
       
   288 	    return ((String) v.elementAt(0));
       
   289 	else
       
   290 	    return (null);
       
   291     }
       
   292 
       
   293     /**
       
   294      * Return the relative pathnames of the authorization help files
       
   295      * on the management server.
       
   296      *
       
   297      * @return	An array of help file pathnames
       
   298      *
       
   299      *
       
   300      */
       
   301     public String [] getLongDescIds() {
       
   302 
       
   303 	return (this.getAttributeArray(SOLARIS_AUTH_HELP));
       
   304 
       
   305     }
       
   306 
       
   307     /**
       
   308      * Return the relative pathnames of the authorization help files
       
   309      * on the management server.
       
   310      *
       
   311      * @return	A vector of help file pathnames
       
   312      *
       
   313      */
       
   314     public Vector getLongDescIdsVector() {
       
   315 
       
   316 	return (this.getAttribute(SOLARIS_AUTH_HELP));
       
   317 
       
   318     }
       
   319 
       
   320     /**
       
   321      * Set the relative pathname of the authorization help file
       
   322      * on the management server.  Any existing help file pathnames
       
   323      * are replaced.
       
   324      *
       
   325      * @param	A help file pathname
       
   326      *
       
   327      */
       
   328     public void setLongDescId(String longDescHelp) {
       
   329 
       
   330 	this.setAttribute(SOLARIS_AUTH_HELP, longDescHelp);
       
   331 
       
   332     }
       
   333 
       
   334     /**
       
   335      * Set the relative pathnames of the authorization help files
       
   336      * on the management server.  Any existing help file pathnames
       
   337      * are replaced.
       
   338      *
       
   339      * @param	An array of help file pathnames
       
   340      *
       
   341      */
       
   342     public void setLongDescId(String [] longDescIdArray) {
       
   343 
       
   344 	this.setAttribute(SOLARIS_AUTH_HELP, longDescIdArray);
       
   345 
       
   346     }
       
   347 
       
   348     /**
       
   349      * Set the relative pathnames of the authorization help files
       
   350      * on the management server.  Any existing help file pathnames
       
   351      * are replaced.
       
   352      *
       
   353      * @param	A vector of help file pathnames
       
   354      *
       
   355      */
       
   356     public void setLongDescIdVector(Vector names) {
       
   357 
       
   358 	this.setAttribute(SOLARIS_AUTH_HELP, names);
       
   359 
       
   360     }
       
   361 
       
   362     /**
       
   363      * Return a long description for the authorization.
       
   364      *
       
   365      * @return	A long description
       
   366      *
       
   367      */
       
   368     public String getLongDesc() {
       
   369 
       
   370 	if (this.longDesc == null)
       
   371 	    return null;
       
   372 	else
       
   373 	    return (this.longDesc[0]);
       
   374 
       
   375     }
       
   376 
       
   377     /**
       
   378      * Return an array of long descriptions for the authorization.
       
   379      *
       
   380      * @return	An array of long descriptions
       
   381      *
       
   382      */
       
   383     public String [] getLongDescs() {
       
   384 
       
   385 	if (this.longDesc == null)
       
   386 	    return null;
       
   387 	else
       
   388 	    return (this.longDesc);
       
   389 
       
   390     }
       
   391 
       
   392     /**
       
   393      * Return a localized long description for the authorization.
       
   394      *
       
   395      * @return	A localized long description
       
   396      *
       
   397      */
       
   398     public String getLongDesc(Locale locale) {
       
   399 
       
   400 	if (this.longDesc == null)
       
   401 	    return null;
       
   402 	else
       
   403 	    return (this.longDesc[0]);
       
   404 
       
   405     }
       
   406 
       
   407     /**
       
   408      * @param	A long description
       
   409      *
       
   410      */
       
   411     public void setLongDesc(String longDesc) {
       
   412 
       
   413 	if (this.longDesc == null)
       
   414 	    this.longDesc = new String[1];
       
   415 	this.longDesc[0] = longDesc;
       
   416 
       
   417     }
       
   418 
       
   419     /**
       
   420      * Set the long descriptions for the authorization.
       
   421      * Any existing log descriptions are replaced.
       
   422      *
       
   423      * @param	An array of long descriptions
       
   424      *
       
   425      */
       
   426     public void setLongDesc(String [] longDesc) {
       
   427 
       
   428 	this.longDesc = longDesc;
       
   429 
       
   430     }
       
   431 
       
   432     /**
       
   433      * Set the long descriptions for the authorization.
       
   434      * Any existing log descriptions are replaced.
       
   435      *
       
   436      * @param	An array of long descriptions
       
   437      *
       
   438      */
       
   439     public boolean isVisible() {
       
   440 
       
   441 	return (visible);
       
   442     }
       
   443 
       
   444     /**
       
   445      * Set the long descriptions for the authorization.
       
   446      * Any existing log descriptions are replaced.
       
   447      *
       
   448      * @param	An array of long descriptions
       
   449      *
       
   450      */
       
   451     public void setVisible(boolean visibility) {
       
   452 
       
   453 	visible = visibility;
       
   454     }
       
   455 }