Search in sources :

Example 1 with InvalidActivityException

use of javax.activity.InvalidActivityException in project tdi-studio-se by Talend.

the class OnlineAuthenticationPolicy method initialize.

private void initialize(String url, String wsdl) throws URISyntaxException, InvalidActivityException {
    final String PolicyNodeContentRegexPatern = "(?i)(<wsp:All.*?>)(.+?)(</wsp:All>)";
    final String LiveIdentityProviderTrustRegexPatern = "(?i)(<ms-xrm:LiveTrust.*?>)(.+?)(</ms-xrm:LiveTrust>)";
    final String OrgIdentityProviderTrustRegexPatern = "(?i)(<ms-xrm:OrgTrust.*?>)(.+?)(</ms-xrm:OrgTrust>)";
    final String IssuerContainerRegexPater = "(?i)(<Issuer.*?>)(.+?)(</Issuer>)";
    final String AppliesToRegexPattern = "(?i)(<ms-xrm:AppliesTo.*?>)(.+?)(</ms-xrm:AppliesTo>)";
    final String LivePolicyRegexPattern = "(?i)(<ms-xrm:LivePolicy.*?>)(.+?)(</ms-xrm:LivePolicy>)";
    final String LiveIdReferenceIssuerUriNodeNameRegexPattern = "(?i)(<LiveIssuer.*?>)(.+?)(</LiveIssuer>)";
    final String OrgIdReferenceIssuerUriNodeNameRegexPattern = "(?i)(<OrgIdIssuer.*?>)(.+?)(</OrgIdIssuer>)";
    final String AddressIssuerUriNodeNameRegexPattern = "(?i)(<Address.*?>)(.+?)(</Address>)";
    // Retrieve the root policy node that will contain all of the values
    String policyNode = selectFirstMatchOrDefault(wsdl, PolicyNodeContentRegexPatern);
    if (null != policyNode) {
        // Set authentication type to OnlineFederation.
        boolean authWithOrgId = true;
        // Retrieve the OrgId authentication policy (that contains the AppliesTo and LivePolicy values).
        String IdentityProviderTrustConfiguration = selectFirstMatchOrDefault(policyNode, OrgIdentityProviderTrustRegexPatern);
        // If OrgId authentication policy node not found then try LiveId policy node.
        if (null == IdentityProviderTrustConfiguration || IdentityProviderTrustConfiguration == "") {
            IdentityProviderTrustConfiguration = selectFirstMatchOrDefault(policyNode, LiveIdentityProviderTrustRegexPatern);
            // Set OnlineFederation authentication flag to false.
            authWithOrgId = false;
        }
        if (null != IdentityProviderTrustConfiguration) {
            String appliesTo = selectFirstMatchOrDefault(IdentityProviderTrustConfiguration, AppliesToRegexPattern);
            String livePolicy = selectFirstMatchOrDefault(IdentityProviderTrustConfiguration, LivePolicyRegexPattern);
            // The issuer container node contains the Issuer URI. Since the
            // Discovery Service exposes both Office 365
            // and Microsoft account authentication mechanisms, it lists
            // multiple issuers. In that case, the issuer is
            // listed under the reference parameters. In other scenarios, it
            // is listed in the Address node instead.
            String issuerContainerNode = selectFirstMatchOrDefault(policyNode, IssuerContainerRegexPater);
            if (null != issuerContainerNode) {
                // Read the value from the reference parameters. If it is
                // not set, check the Address node.
                String issuerUri = selectFirstMatchOrDefault(issuerContainerNode, (authWithOrgId) ? OrgIdReferenceIssuerUriNodeNameRegexPattern : LiveIdReferenceIssuerUriNodeNameRegexPattern);
                // Try Address node to find issuer Uri.
                if (null == issuerUri || "" == issuerUri) {
                    issuerUri = selectFirstMatchOrDefault(issuerContainerNode, AddressIssuerUriNodeNameRegexPattern);
                }
                // required information has been found.
                if (null != issuerUri && "" != issuerUri) {
                    this.initialize(appliesTo, livePolicy, new URI(issuerUri));
                    return;
                }
            }
        }
    }
    throw new InvalidActivityException(String.format(Locale.getDefault(), "Unable to parse the authentication policy from the WSDL \"%s\".", url));
}
Also used : InvalidActivityException(javax.activity.InvalidActivityException) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 InvalidActivityException (javax.activity.InvalidActivityException)1