📄 identityproviderutil.java
字号:
/* * Copyright 2005,2006 WSO2, Inc. http://www.wso2.org * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.wso2.solutions.identity.sts;import java.net.URI;import java.net.URISyntaxException;import javax.xml.namespace.QName;import org.apache.axiom.om.OMElement;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.rahas.RahasData;import org.wso2.solutions.identity.IdentityConstants;import org.wso2.solutions.identity.IdentityProviderConstants;import org.wso2.solutions.identity.IdentityProviderException;public class IdentityProviderUtil { private static Log log = LogFactory.getLog(IdentityProviderUtil.class); public static OMElement createRequestedDisplayToken(OMElement parent, IdentityProviderData data) { return createOMElement(parent, IdentityConstants.NS, IdentityProviderConstants.LocalNames.REQUESTED_DISPLAY_TOKEN, IdentityConstants.PREFIX); } public static OMElement createDisplayToken(OMElement parent, IdentityProviderData data) { OMElement displayElem = createOMElement(parent, IdentityConstants.NS, IdentityProviderConstants.LocalNames.DISPLAY_TOKEN, IdentityConstants.PREFIX); return displayElem; } public static OMElement createDisplayClaim(OMElement parent, String displayTag, String displayValue, String uri) { OMElement claimElem = createOMElement(parent, IdentityConstants.NS, IdentityProviderConstants.LocalNames.DISPLAY_CLAIM, IdentityConstants.PREFIX); claimElem.addAttribute("Uri", uri, null); OMElement tagElem = createOMElement(claimElem, IdentityConstants.NS, IdentityProviderConstants.LocalNames.DISPLAY_TAG, IdentityConstants.PREFIX); tagElem.setText(displayTag); OMElement valElem = createOMElement(claimElem, IdentityConstants.NS, IdentityProviderConstants.LocalNames.DISPLAY_VALUE, IdentityConstants.PREFIX); valElem.setText(displayValue); return claimElem; } public static OMElement createOpenIdToken(OMElement parent, IdentityProviderData data) { return createOMElement(parent, IdentityConstants.OpenId.OPENID_URL, IdentityProviderConstants.LocalNames.OPEN_ID_TOKEN, IdentityConstants.OpenId.PREFIX); } private static OMElement createOMElement(OMElement parent, String ns, String ln, String prefix) { return parent.getOMFactory().createOMElement(new QName(ns, ln, prefix), parent); } /** * Obtain the applies to host name from the WS-Trust request. * @param data Data from WS-Trust request. * @return applies to host name if found. * @throws IdentityProviderException */ public static String getAppliesToHostName(RahasData data) throws IdentityProviderException { // If there's no applies to then we don't have to encrypt if (data.getAppliesToEpr() == null) { return null; } String relyingPartyURI = data.getAppliesToAddress(); if (relyingPartyURI == null) { // Addressing policy not used in the policy relyingPartyURI = data.getAppliesToEpr().getText(); if (relyingPartyURI == null) { throw new IdentityProviderException( "cannotFindRelyingParty"); } } URI uri = null; try { //To get the host name extracted uri = new URI(relyingPartyURI); } catch (URISyntaxException e) { throw new IdentityProviderException("invalidUri", new String[] { relyingPartyURI }, e); } return uri.getHost(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -