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 Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * GenericToken.java
039: *
040: * Created on February 15, 2006, 2:06 PM
041: */
042:
043: package com.sun.xml.ws.security.trust;
044:
045: import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
046: import java.util.UUID;
047:
048: import com.sun.xml.ws.security.Token;
049:
050: import org.w3c.dom.Element;
051:
052: import java.util.logging.Level;
053: import java.util.logging.Logger;
054: import com.sun.xml.ws.security.trust.logging.LogDomainConstants;
055: import com.sun.xml.ws.security.trust.logging.LogStringsMessages;
056:
057: /**
058: *
059: * @author Jiandong Guo
060: */
061: public class GenericToken implements Token {
062:
063: private static final Logger log = Logger.getLogger(
064: LogDomainConstants.TRUST_IMPL_DOMAIN,
065: LogDomainConstants.TRUST_IMPL_DOMAIN_BUNDLE);
066:
067: private Element token;
068:
069: //private JAXBElement tokenEle;
070:
071: private String tokenType;
072: private SecurityHeaderElement she = null;
073: private String id;
074:
075: /** Creates a new instance of GenericToken */
076: public GenericToken(Element token) {
077: this .token = token;
078: id = token.getAttributeNS(null, "AssertionID");
079: if (id == null || id.length() == 0) {
080: id = token.getAttributeNS(null, "ID");
081: }
082: if (id == null || id.length() == 0) {
083: id = token.getAttributeNS(null, "Id");
084: }
085: if (id == null || id.length() == 0) {
086: id = UUID.randomUUID().toString();
087: }
088: }
089:
090: public GenericToken(Element token, String tokenType) {
091: this (token);
092:
093: this .tokenType = tokenType;
094: }
095:
096: public GenericToken(SecurityHeaderElement headerElement) {
097: this .she = headerElement;
098: }
099:
100: public String getType() {
101: if (tokenType != null) {
102: if (log.isLoggable(Level.FINE)) {
103: log.log(Level.FINE, LogStringsMessages
104: .WST_1001_TOKEN_TYPE(tokenType));
105: }
106: return tokenType;
107: }
108: return WSTrustConstants.OPAQUE_TYPE;
109: }
110:
111: public Object getTokenValue() {
112: return this .token;
113: }
114:
115: public SecurityHeaderElement getElement() {
116: return this .she;
117: }
118:
119: public String getId() {
120: return id;
121: }
122:
123: public void setId(final String id) {
124: this.id = id;
125: }
126: }
|