當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestSecurityTokenResponse類代碼示例

本文整理匯總了Java中org.opensaml.soap.wsfed.RequestSecurityTokenResponse的典型用法代碼示例。如果您正苦於以下問題:Java RequestSecurityTokenResponse類的具體用法?Java RequestSecurityTokenResponse怎麽用?Java RequestSecurityTokenResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RequestSecurityTokenResponse類屬於org.opensaml.soap.wsfed包,在下文中一共展示了RequestSecurityTokenResponse類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseTokenFromString

import org.opensaml.soap.wsfed.RequestSecurityTokenResponse; //導入依賴的package包/類
/**
 * parseTokenFromString converts a raw wresult and extracts it into an assertion.
 *
 * @param wresult the raw token returned by the IdP
 * @return an assertion
 */
public Assertion parseTokenFromString(final String wresult) {
    try (final InputStream in = new ByteArrayInputStream(wresult.getBytes("UTF-8"))) {

        final Document document = configBean.getParserPool().parse(in);
        final Element metadataRoot = document.getDocumentElement();
        final UnmarshallerFactory unmarshallerFactory = configBean.getUnmarshallerFactory();
        final Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);
        if (unmarshaller == null) {
            throw new IllegalArgumentException("Unmarshaller for the metadata root element cannot be determined");
        }

        final RequestSecurityTokenResponse rsToken = (RequestSecurityTokenResponse) unmarshaller.unmarshall(metadataRoot);

        //Get our SAML token
        final List<RequestedSecurityToken> rst = rsToken.getRequestedSecurityToken();
        final Assertion assertion = (Assertion) rst.get(0).getSecurityTokens().get(0);

        if (assertion == null) {
            LOGGER.debug("Assertion is null");
        } else {
            LOGGER.debug("Assertion: {}", assertion);
        }
        return assertion;
    } catch (final Exception ex) {
        LOGGER.warn(ex.getMessage());
        return null;
    }
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:35,代碼來源:WsFederationHelper.java

示例2: parseTokenFromString

import org.opensaml.soap.wsfed.RequestSecurityTokenResponse; //導入依賴的package包/類
/**
 * parseTokenFromString converts a raw wresult and extracts it into an assertion.
 *
 * @param wresult the raw token returned by the IdP
 * @param config  the config
 * @return an assertion
 */
public Assertion parseTokenFromString(final String wresult, final WsFederationConfiguration config) {
    try (InputStream in = new ByteArrayInputStream(wresult.getBytes("UTF-8"))) {
        final Document document = configBean.getParserPool().parse(in);
        final Element metadataRoot = document.getDocumentElement();
        final UnmarshallerFactory unmarshallerFactory = configBean.getUnmarshallerFactory();
        final Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);
        if (unmarshaller == null) {
            throw new IllegalArgumentException("Unmarshaller for the metadata root element cannot be determined");
        }

        final RequestSecurityTokenResponse rsToken = (RequestSecurityTokenResponse) unmarshaller.unmarshall(metadataRoot);
        if (rsToken == null || rsToken.getRequestedSecurityToken() == null) {
            throw new IllegalArgumentException("Request security token response is null");
        }
        //Get our SAML token
        final List<RequestedSecurityToken> rst = rsToken.getRequestedSecurityToken();
        if (rst.isEmpty()) {
            throw new IllegalArgumentException("No requested security token response is provided in the response");
        }
        final RequestedSecurityToken reqToken = rst.get(0);
        if (reqToken.getSecurityTokens() == null || reqToken.getSecurityTokens().isEmpty()) {
            throw new IllegalArgumentException("Requested security token response is not carrying any security tokens");
        }

        Assertion assertion = null;

        XMLObject securityToken = reqToken.getSecurityTokens().get(0);
        if (securityToken != null) {
            if (securityToken instanceof EncryptedData) {
                final EncryptedData encryptedData = EncryptedData.class.cast(securityToken);
                securityToken = buildAssertionDecrypter(config).decryptData(encryptedData);
            }
        }
        if (securityToken instanceof Assertion) {
            assertion = Assertion.class.cast(securityToken);
        }

        if (assertion == null) {
            throw new IllegalArgumentException("Assertion is null");
        }
        LOGGER.debug("Assertion: {}", assertion);
        return assertion;
    } catch (final Exception ex) {
        LOGGER.warn(ex.getMessage());
        return null;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:55,代碼來源:WsFederationHelper.java

示例3: parseTokenFromString

import org.opensaml.soap.wsfed.RequestSecurityTokenResponse; //導入依賴的package包/類
/**
 * parseTokenFromString converts a raw wresult and extracts it into an assertion.
 *
 * @param wresult the raw token returned by the IdP
 * @param config  the config
 * @return an assertion
 */
public Assertion parseTokenFromString(final String wresult, final WsFederationConfiguration config) {
    LOGGER.debug("Result token received from ADFS is [{}]", wresult);

    try (InputStream in = new ByteArrayInputStream(wresult.getBytes(StandardCharsets.UTF_8))) {

        LOGGER.debug("Parsing token into a document");
        final Document document = configBean.getParserPool().parse(in);
        final Element metadataRoot = document.getDocumentElement();
        final UnmarshallerFactory unmarshallerFactory = configBean.getUnmarshallerFactory();
        final Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(metadataRoot);
        if (unmarshaller == null) {
            throw new IllegalArgumentException("Unmarshaller for the metadata root element cannot be determined");
        }

        LOGGER.debug("Unmarshalling the document into a security token response");
        final RequestSecurityTokenResponse rsToken = (RequestSecurityTokenResponse) unmarshaller.unmarshall(metadataRoot);

        if (rsToken == null || rsToken.getRequestedSecurityToken() == null) {
            throw new IllegalArgumentException("Request security token response is null");
        }
        //Get our SAML token
        LOGGER.debug("Locating list of requested security tokens");
        final List<RequestedSecurityToken> rst = rsToken.getRequestedSecurityToken();

        if (rst.isEmpty()) {
            throw new IllegalArgumentException("No requested security token response is provided in the response");
        }

        LOGGER.debug("Locating the first occurrence of a requested security token in the list");
        final RequestedSecurityToken reqToken = rst.get(0);
        if (reqToken.getSecurityTokens() == null || reqToken.getSecurityTokens().isEmpty()) {
            throw new IllegalArgumentException("Requested security token response is not carrying any security tokens");
        }

        Assertion assertion = null;

        LOGGER.debug("Locating the first occurrence of a security token from the requested security token");
        XMLObject securityToken = reqToken.getSecurityTokens().get(0);

        if (securityToken instanceof EncryptedData) {
            try {
                LOGGER.debug("Security token is encrypted. Attempting to decrypt to extract the assertion");
                final EncryptedData encryptedData = EncryptedData.class.cast(securityToken);
                final Decrypter decrypter = buildAssertionDecrypter(config);
                LOGGER.debug("Built an instance of [{}]", decrypter.getClass().getName());
                securityToken = decrypter.decryptData(encryptedData);
            } catch (final Exception e) {
                throw new IllegalArgumentException("Unable to decrypt security token", e);
            }
        }

        if (securityToken instanceof Assertion) {
            LOGGER.debug("Security token is an assertion.");
            assertion = Assertion.class.cast(securityToken);
        }
        if (assertion == null) {
            throw new IllegalArgumentException("Could not extract or decrypt an assertion based on the security token provided");
        }
        LOGGER.debug("Extracted assertion successfully: [{}]", assertion);
        return assertion;
    } catch (final Exception ex) {
        LOGGER.warn(ex.getMessage());
        return null;
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:73,代碼來源:WsFederationHelper.java


注:本文中的org.opensaml.soap.wsfed.RequestSecurityTokenResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。