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 1997-2006 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:
042: package org.netbeans.modules.identity.profile.api.configurator.impl.dynamic;
043:
044: import java.lang.reflect.Method;
045: import org.netbeans.modules.identity.profile.api.configurator.SecurityMechanism;
046:
047: /**
048: * Implementation class for the SecurityMechanism interface.
049: *
050: * Created on June 10, 2006, 10:48 PM
051: *
052: * @author ptliu
053: */
054: class SecurityMechanismImpl implements SecurityMechanism {
055:
056: private static final String USERNAME_TOKEN = "UserNameToken"; //NOI18N
057:
058: private static final String AM_GET_URI_METHOD = "getURI"; //NOI18N
059:
060: private static final String AM_GET_NAME_METHOD = "getName"; //NOI18N
061:
062: private static final String AM_IS_TA_LOOKUP_REQUIRED_METHOD = "isTALookupRequired"; //NOI18N
063:
064: private static final String AM_IS_TA_REGISTRATION_REQUIRED_METHOD = "isTARegistrationRequired"; //NOI18N
065:
066: private static final String LIBERTY_PREFIX = "Liberty"; //NOI18N
067:
068: private Object proxied;
069: private Class clazz;
070: private String uri;
071: private String name;
072: private Boolean isTALookupRequired;
073: private Boolean isTARegistrationRequired;
074:
075: /**
076: * Creates a new instance of SecurityMechanismImpl
077: */
078: public SecurityMechanismImpl(Object proxied) {
079: this .proxied = proxied;
080: this .clazz = proxied.getClass();
081: }
082:
083: public String getURI() {
084: if (uri == null) {
085: try {
086: Method method = clazz.getMethod(AM_GET_URI_METHOD);
087: uri = (String) method.invoke(proxied);
088: } catch (Exception ex) {
089: ex.printStackTrace();
090: }
091: }
092: return uri;
093: }
094:
095: public String getName() {
096: if (name == null) {
097: try {
098: Method method = clazz.getMethod(AM_GET_NAME_METHOD);
099: name = (String) method.invoke(proxied);
100: } catch (Exception ex) {
101: ex.printStackTrace();
102: }
103: }
104:
105: return name;
106: }
107:
108: public boolean isTARegistrationRequired() {
109: if (isTARegistrationRequired == null) {
110: try {
111: Method method = clazz
112: .getMethod(AM_IS_TA_REGISTRATION_REQUIRED_METHOD);
113: isTARegistrationRequired = (Boolean) method
114: .invoke(proxied);
115: } catch (Exception ex) {
116: isTARegistrationRequired = Boolean.FALSE;
117: }
118: }
119: return isTARegistrationRequired;
120: }
121:
122: public boolean isTALookupRequired() {
123: if (isTALookupRequired == null) {
124: try {
125: Method method = clazz
126: .getMethod(AM_IS_TA_LOOKUP_REQUIRED_METHOD);
127: isTALookupRequired = (Boolean) method.invoke(proxied);
128: } catch (Exception ex) {
129: isTALookupRequired = Boolean.FALSE;
130: }
131: }
132: return isTALookupRequired;
133: }
134:
135: public boolean isPasswordCredentialRequired() {
136: return getName().startsWith(USERNAME_TOKEN);
137: }
138:
139: public boolean isLiberty() {
140: return getName().startsWith(LIBERTY_PREFIX);
141: }
142:
143: public String toString() {
144: return getName();
145: }
146:
147: public boolean equals(Object obj) {
148: if (obj instanceof SecurityMechanismImpl) {
149: if (getURI().equals(((SecurityMechanismImpl) obj).getURI()))
150: return true;
151: }
152:
153: return false;
154: }
155:
156: public int hashCode() {
157: return getURI().hashCode();
158: }
159: }
|