📄 securitytokenorreference.java
字号:
package edu.virginia.cs.wst;import javax.xml.namespace.QName;import org.apache.ws.security.WSSecurityException;import org.apache.ws.security.message.token.BinarySecurity;import org.apache.ws.security.message.token.SecurityTokenReference;import org.apache.ws.security.message.token.UsernameToken;import org.w3c.dom.Document;import org.w3c.dom.Element;import edu.virginia.cs.wst.exception.ElementParsingException;import edu.virginia.cs.wst.exception.InvalidSecurityTokenReference;import edu.virginia.cs.wst.exception.TrustException;/** * @author ddelvecc * * A class to hold either a security token of some kind (UsernameToken, BinarySecurityToken, etc.) * or a SecurityTokenReference. */public class SecurityTokenOrReference { protected Document doc = null; protected SecurityTokenReference reference = null; protected UsernameToken usernameToken = null; protected BinarySecurity binarySecurityToken = null; protected boolean isReference; public boolean isReference() { return reference != null; } public boolean isToken() { return reference == null; } public SecurityTokenOrReference(Element element) throws ElementParsingException { QName el = new QName(element.getNamespaceURI(), element.getLocalName()); try { if(el.equals(SecurityTokenReference.TOKEN)) this.reference = new SecurityTokenReference(element); if(el.equals(UsernameToken.TOKEN)) this.usernameToken = new UsernameToken(element); if(el.equals(BinarySecurity.TOKEN)) this.binarySecurityToken = new BinarySecurity(element); doc = element.getOwnerDocument(); } catch (WSSecurityException e) { throw new ElementParsingException("WSSecurityException while trying to create a SecurityTokenOrReference object from an XML Element: " + e.getMessage()); } } public SecurityTokenOrReference(Element element, Document doc) throws ElementParsingException { this(element); this.doc = doc; } public SecurityTokenOrReference(SecurityTokenReference reference) { this.reference = reference; } public SecurityTokenOrReference(UsernameToken securityToken) { this.usernameToken = securityToken; } public SecurityTokenOrReference(BinarySecurity securityToken) { this.binarySecurityToken = securityToken; } public void setDocument(Document doc) { this.doc = doc; } public Element getElement() { if(reference != null) return reference.getElement(); else return getTokenElement(); } private Element getTokenElement() { if(usernameToken != null) return usernameToken.getElement(); if(binarySecurityToken != null) return binarySecurityToken.getElement(); return null; } public Object getTokenOrReference() throws TrustException { if(reference != null) return reference; return resolveToken(); } public Object resolveToken() throws TrustException { if(usernameToken != null) return usernameToken; if(binarySecurityToken != null) return binarySecurityToken; if(reference != null) { try { Element tokenElement = reference.getTokenElement(doc, null); if(tokenElement != null) { QName el = new QName(tokenElement.getNamespaceURI(), tokenElement.getLocalName()); try { if(el.equals(UsernameToken.TOKEN)) return new UsernameToken(tokenElement); if(el.equals(BinarySecurity.TOKEN)) return new BinarySecurity(tokenElement); } catch (WSSecurityException e) { throw new ElementParsingException("WSSecurityException while trying to create a SecurityToken object from a SecurityTokenReference: " + e.getMessage()); } } } catch (WSSecurityException e) { throw new InvalidSecurityTokenReference("WSSecurityException while trying to dereference a <SecurityTokenReference>: " + e.getMessage()); } } return null; } public SecurityTokenReference getReference() { return reference; } public UsernameToken getUsernameToken() { return usernameToken; } public BinarySecurity getBinarySecurity() { return binarySecurityToken; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -