001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 2004-2005 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.jmx.configwizard;
042:
043: import java.io.ByteArrayInputStream;
044: import java.util.Properties;
045:
046: /**
047: * Class used for authenticate table
048: * @author jfdenise
049: */
050: public class RMIAuthenticatedUser {
051:
052: private String name;
053: private String password;
054: private String access = "readonly";// NOI18N
055:
056: /** Creates a new instance of RMIAuthenticatedUser */
057: public RMIAuthenticatedUser() {
058: }
059:
060: private static boolean isValidKey(String key) {
061: if (key == null || key.equals(""))
062: return false;// NOI18N
063:
064: boolean precedingBackslash = false;
065: char[] val = key.toCharArray();
066: int offset = 0;
067: while (offset < val.length) {
068: char c = val[offset];
069: if ((c > 59) && (c < 127)) {
070: if (c == '\\') {
071: char aChar = val[offset++];
072: if (aChar == 'u') {
073: // Read the xxxx
074: int value = 0;
075: for (int i = 0; i < 4; i++) {
076: aChar = val[offset++];
077: switch (aChar) {
078: case '0':
079: case '1':
080: case '2':
081: case '3':
082: case '4':
083: case '5':
084: case '6':
085: case '7':
086: case '8':
087: case '9':
088: case 'a':
089: case 'b':
090: case 'c':
091: case 'd':
092: case 'e':
093: case 'f':
094: case 'A':
095: case 'B':
096: case 'C':
097: case 'D':
098: case 'E':
099: case 'F':
100: break;
101: default:
102: return false;
103: }
104: }
105: }
106: precedingBackslash = !precedingBackslash;
107: } else
108: precedingBackslash = false;
109:
110: offset++;
111: continue;
112: }
113:
114: switch (c) {
115: case ':':
116: case '=':
117: case '#':
118: case ' ':
119: if (!precedingBackslash)
120: return false;
121: }
122: offset++;
123: }
124: return true;
125: }
126:
127: private String cleanPassword() {
128: if (password == null || password.equals(""))
129: return null; // NOI18N
130: return password;
131: }
132:
133: /**
134: * Returns if the authenticate user model is valid : there is no empty password
135: * and no empty role name.
136: * @return <CODE>boolean</CODE> true if the authenticate user model is valid
137: */
138: public boolean isValid() {
139: return (isValidKey(name)) && (cleanPassword() != null);
140: }
141:
142: /**
143: * Returns the :
144: * - role name of this autenticate user if col = 0
145: * - password of this autenticate user if col = 1
146: * - access of this autenticate user if col = 2
147: * @param col <CODE>int</CODE> index of column of the authenticate table
148: * @return <CODE>String</CODE>
149: */
150: public Object getValueAt(int col) {
151: switch (col) {
152: case 0:
153: return name;
154: case 1:
155: return password;
156: case 2:
157: return access;
158: }
159: return null;
160: }
161:
162: /**
163: * Sets the :
164: * - role name of this autenticate user if col = 0
165: * - password of this autenticate user if col = 1
166: * - access of this autenticate user if col = 2
167: * @param value <CODE>Object</CODE> value to set (must be String)
168: * @param col <CODE>int</CODE> index of authenticate table column
169: */
170: public void setValueAt(Object value, int col) {
171: switch (col) {
172: case 0:
173: name = (String) value;
174: break;
175: case 1:
176: password = (String) value;
177: break;
178: case 2:
179: access = (String) value;
180: break;
181: }
182: }
183:
184: /**
185: * Returns the authenticate user name.
186: * @return <CODE>String</CODE> user name
187: */
188: public String getName() {
189: return name;
190: }
191:
192: /**
193: * Returns the authenticate user password.
194: * @return <CODE>String</CODE> user password
195: */
196: public String getPassword() {
197: return password;
198: }
199:
200: /**
201: * Returns the authenticate user access.
202: * @return <CODE>String</CODE> user access
203: */
204: public String getAccess() {
205: return access;
206: }
207:
208: }
|