Search in sources :

Example 16 with ServiceURL

use of org.wso2.carbon.identity.core.ServiceURL in project carbon-mediation by wso2.

the class Utils method getTenantAxisService.

/**
 * Get the details of a deployed webapp for tenants
 *
 * @param serviceURL URI path
 * @return meta data for webapp
 */
private static AxisService getTenantAxisService(String tenant, String serviceURL) throws AxisFault {
    ConfigurationContextService contextService = IntegratorComponent.getContextService();
    ConfigurationContext configContext;
    ConfigurationContext tenantContext;
    if (null != contextService) {
        // Getting server's configContext instance
        configContext = contextService.getServerConfigContext();
        String[] urlparts = serviceURL.split("/");
        // urlpart[0] is tenant domain
        tenantContext = TenantAxisUtils.getTenantConfigurationContext(tenant, configContext);
        AxisService tenantAxisService = tenantContext.getAxisConfiguration().getService(urlparts[1]);
        if (tenantAxisService == null) {
            AxisServiceGroup axisServiceGroup = tenantContext.getAxisConfiguration().getServiceGroup(urlparts[1]);
            if (axisServiceGroup != null) {
                return axisServiceGroup.getService(urlparts[2]);
            } else {
                // for dss samples
                return tenantContext.getAxisConfiguration().getService(urlparts[2]);
            }
        } else {
            return tenantAxisService;
        }
    }
    return null;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisService(org.apache.axis2.description.AxisService) ConfigurationContextService(org.wso2.carbon.utils.ConfigurationContextService) AxisServiceGroup(org.apache.axis2.description.AxisServiceGroup)

Example 17 with ServiceURL

use of org.wso2.carbon.identity.core.ServiceURL in project carbon-identity-framework by wso2.

the class CallBackValidator method isValidCallbackURL.

/**
 * This method is to validate the callback URL in the request with the configured one.
 *
 * @param callbackURL  CallbackURL Passed in the request.
 * @param tenantDomain TenantDomain of the user.
 * @return The status of the validation.
 * @throws IdentityRecoveryException IdentityRecoveryException.
 */
public boolean isValidCallbackURL(String callbackURL, String tenantDomain) throws IdentityRecoveryException {
    if (StringUtils.isBlank(tenantDomain)) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
        if (log.isDebugEnabled()) {
            log.debug("Tenant domain is considered as super tenant domain: " + tenantDomain);
        }
    }
    IdentityProvider residentIdP;
    // Build the service URL of idp management admin service
    StringBuilder builder = new StringBuilder();
    String serviceURL = builder.append(IdentityManagementServiceUtil.getInstance().getServiceContextURL()).append(IdentityManagementEndpointConstants.ServiceEndpoints.IDENTITY_PROVIDER_MANAGEMENT_SERVICE).toString().replaceAll("(?<!(http:|https:))//", "/");
    try {
        IdentityProviderMgtServiceStub idPMgtStub = new IdentityProviderMgtServiceStub(serviceURL);
        ServiceClient idpClient = idPMgtStub._getServiceClient();
        IdentityManagementEndpointUtil.authenticate(idpClient);
        residentIdP = idPMgtStub.getResidentIdP();
    } catch (AxisFault axisFault) {
        throw new IdentityRecoveryException("Error while instantiating IdentityProviderMgtServiceStub", axisFault);
    } catch (Exception e) {
        throw new IdentityRecoveryException("Error occurred when getting residentIDP configurations.", e);
    }
    IdentityProviderProperty[] idpProperties = null;
    if (residentIdP != null) {
        idpProperties = residentIdP.getIdpProperties();
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Resident identity provider is not found for the tenant domain: " + tenantDomain);
        }
    }
    String callbackRegex = null;
    if (idpProperties != null) {
        for (IdentityProviderProperty property : idpProperties) {
            if (IdentityManagementEndpointConstants.UserInfoRecovery.RECOVERY_CALLBACK_REGEX.equals(property.getValue())) {
                callbackRegex = property.getValue();
                if (log.isDebugEnabled()) {
                    log.debug("Configured recovery callback URL regex: " + callbackRegex);
                }
                break;
            }
        }
    }
    if (StringUtils.isNotBlank(callbackURL)) {
        try {
            String encodeURL = URLEncoder.encode(callbackURL, IdentityManagementEndpointConstants.UTF_8);
            URI uri = new URI(encodeURL);
            callbackURL = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, null).toString();
            if (log.isDebugEnabled()) {
                log.debug("Callback URL in the username recovery request: " + callbackURL);
            }
        } catch (URISyntaxException e) {
            throw new IdentityRecoveryException("Error occurred while formatting the provided callback URL. ", e);
        } catch (UnsupportedEncodingException e) {
            throw new IdentityRecoveryException("Error occurred while encoding the provided callback URL.", e);
        }
    }
    return callbackRegex == null || callbackURL.matches(callbackRegex);
}
Also used : AxisFault(org.apache.axis2.AxisFault) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdentityProvider(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty) ServiceClient(org.apache.axis2.client.ServiceClient) IdentityProviderMgtServiceStub(org.wso2.carbon.idp.mgt.stub.IdentityProviderMgtServiceStub)

Example 18 with ServiceURL

use of org.wso2.carbon.identity.core.ServiceURL in project product-is by wso2.

the class ProvisioningTestCase method createServiceClientsForServers.

private void createServiceClientsForServers(String sessionCookie, int portOffset, CommonConstants.AdminClients[] adminClients) throws Exception {
    if (adminClients == null) {
        return;
    }
    // TODO: Need to remove getSecureServiceUrl method when server start issue got fixed / TAF 4.3.1
    String serviceUrl = getSecureServiceUrl(portOffset, automationContextMap.get(portOffset).getContextUrls().getSecureServiceUrl());
    if (sessionCookie == null) {
        AuthenticatorClient authenticatorClient = new AuthenticatorClient(serviceUrl);
        sessionCookie = authenticatorClient.login(automationContextMap.get(portOffset).getSuperTenant().getTenantAdmin().getUserName(), automationContextMap.get(portOffset).getSuperTenant().getTenantAdmin().getPassword(), automationContextMap.get(portOffset).getDefaultInstance().getHosts().get("default"));
        if (sessionCookie == null) {
            throw new Exception("Unable to login to the server instance : " + automationContextMap.get(portOffset).getInstance().getName());
        }
    }
    ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    for (CommonConstants.AdminClients client : adminClients) {
        if (CommonConstants.AdminClients.APPLICATION_MANAGEMENT_SERVICE_CLIENT.equals(client)) {
            applicationManagementServiceClients.put(portOffset, new ApplicationManagementServiceClient(sessionCookie, serviceUrl, configContext));
        } else if (CommonConstants.AdminClients.IDENTITY_PROVIDER_MGT_SERVICE_CLIENT.equals(client)) {
            identityProviderMgtServiceClients.put(portOffset, new IdentityProviderMgtServiceClient(sessionCookie, serviceUrl));
        } else if (CommonConstants.AdminClients.USER_MANAGEMENT_CLIENT.equals(client)) {
            userMgtServiceClients.put(portOffset, new UserManagementClient(serviceUrl, sessionCookie));
        }
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) CommonConstants(org.wso2.identity.integration.test.utils.CommonConstants) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) UserManagementClient(org.wso2.identity.integration.common.clients.UserManagementClient) IdentityProviderMgtServiceClient(org.wso2.identity.integration.common.clients.Idp.IdentityProviderMgtServiceClient) CharonException(org.wso2.charon.core.exceptions.CharonException) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 19 with ServiceURL

use of org.wso2.carbon.identity.core.ServiceURL in project product-is by wso2.

the class ConditionalAuthenticationTestCase method startSecondaryIS.

private void startSecondaryIS() throws Exception {
    AutomationContext context = testDataHolder.getAutomationContext();
    String serviceUrl = (context.getContextUrls().getSecureServiceUrl()).replace("9853", String.valueOf(IS_DEFAULT_HTTPS_PORT + PORT_OFFSET_1)) + "/";
    AuthenticatorClient authenticatorClient = new AuthenticatorClient(serviceUrl);
    sessionCookie = authenticatorClient.login(context.getSuperTenant().getTenantAdmin().getUserName(), context.getSuperTenant().getTenantAdmin().getPassword(), context.getDefaultInstance().getHosts().get("default"));
    if (sessionCookie != null) {
        ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
        applicationManagementServiceClient2 = new ApplicationManagementServiceClient(sessionCookie, serviceUrl, configContext);
        samlSSOConfigServiceClient = new SAMLSSOConfigServiceClient(serviceUrl, sessionCookie);
    }
}
Also used : AutomationContext(org.wso2.carbon.automation.engine.context.AutomationContext) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AuthenticatorClient(org.wso2.carbon.integration.common.admin.client.AuthenticatorClient) ApplicationManagementServiceClient(org.wso2.identity.integration.common.clients.application.mgt.ApplicationManagementServiceClient) SAMLSSOConfigServiceClient(org.wso2.identity.integration.common.clients.sso.saml.SAMLSSOConfigServiceClient)

Example 20 with ServiceURL

use of org.wso2.carbon.identity.core.ServiceURL in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCLogoutServletTest method mockServiceURLBuilder.

private void mockServiceURLBuilder(String context) throws URLBuilderException {
    mockStatic(ServiceURLBuilder.class);
    ServiceURLBuilder serviceURLBuilder = mock(ServiceURLBuilder.class);
    when(ServiceURLBuilder.create()).thenReturn(serviceURLBuilder);
    when(serviceURLBuilder.addPath(any())).thenReturn(serviceURLBuilder);
    ServiceURL serviceURL = mock(ServiceURL.class);
    when(serviceURL.getRelativeInternalURL()).thenReturn(context);
    when(serviceURLBuilder.build()).thenReturn(serviceURL);
}
Also used : ServiceURL(org.wso2.carbon.identity.core.ServiceURL) ServiceURLBuilder(org.wso2.carbon.identity.core.ServiceURLBuilder)

Aggregations

OMElement (org.apache.axiom.om.OMElement)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)3 Iterator (java.util.Iterator)3 Properties (java.util.Properties)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Response (javax.ws.rs.core.Response)3 QName (javax.xml.namespace.QName)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ServiceClient (org.apache.axis2.client.ServiceClient)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 ServiceURL (org.wso2.carbon.identity.core.ServiceURL)3 ServiceURLBuilder (org.wso2.carbon.identity.core.ServiceURLBuilder)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2