Search in sources :

Example 11 with ServiceURL

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

the class SubscriptionDataStoreImpl method isAPIResourceValidationEnabled.

public boolean isAPIResourceValidationEnabled() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String serviceURL = config.getFirstProperty(APIConstants.GATEWAY_RESOURCE_CACHE_ENABLED);
    if (StringUtils.isNotEmpty(serviceURL)) {
        return Boolean.parseBoolean(serviceURL);
    }
    return true;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 12 with ServiceURL

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

the class APIManagerConfiguration method setEventHubConfiguration.

private void setEventHubConfiguration(OMElement omElement) {
    EventHubConfigurationDto eventHubConfigurationDto = new EventHubConfigurationDto();
    OMElement enableElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.ENABLE));
    if (enableElement != null && Boolean.parseBoolean(enableElement.getText())) {
        eventHubConfigurationDto.setEnabled(true);
        OMElement serviceUrlElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.SERVICE_URL));
        if (serviceUrlElement != null) {
            String serviceUrl = APIUtil.replaceSystemProperty(serviceUrlElement.getText());
            if (StringUtils.isNotEmpty(serviceUrl)) {
                serviceUrl = serviceUrl.split("/" + APIConstants.SERVICES_URL_RELATIVE_PATH)[0];
                eventHubConfigurationDto.setServiceUrl(serviceUrl);
            }
        }
        OMElement initDelay = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.INIT_DELAY));
        if (initDelay != null) {
            eventHubConfigurationDto.setInitDelay(Integer.parseInt(initDelay.getText()));
        }
        OMElement usernameElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.USERNAME));
        if (usernameElement != null) {
            eventHubConfigurationDto.setUsername(usernameElement.getText());
        }
        OMElement passwordElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.PASSWORD));
        if (passwordElement != null) {
            String password = MiscellaneousUtil.resolve(passwordElement, secretResolver);
            eventHubConfigurationDto.setPassword(APIUtil.replaceSystemProperty(password).toCharArray());
        }
        OMElement configurationRetrieverElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.EVENT_RECEIVER_CONFIGURATION));
        if (configurationRetrieverElement != null) {
            EventHubConfigurationDto.EventHubReceiverConfiguration eventHubReceiverConfiguration = new EventHubConfigurationDto.EventHubReceiverConfiguration();
            Iterator receiverConnectionDetailsElements = configurationRetrieverElement.getChildElements();
            Properties properties = new Properties();
            while (receiverConnectionDetailsElements.hasNext()) {
                OMElement element = (OMElement) receiverConnectionDetailsElements.next();
                String value = MiscellaneousUtil.resolve(element, secretResolver);
                properties.put(element.getLocalName(), APIUtil.replaceSystemProperty(value));
            }
            eventHubReceiverConfiguration.setJmsConnectionParameters(properties);
            eventHubConfigurationDto.setEventHubReceiverConfiguration(eventHubReceiverConfiguration);
        }
        OMElement eventPublisherElement = omElement.getFirstChildWithName(new QName(APIConstants.KeyManager.EVENT_PUBLISHER_CONFIGURATIONS));
        EventHubConfigurationDto.EventHubPublisherConfiguration eventHubPublisherConfiguration = new EventHubConfigurationDto.EventHubPublisherConfiguration();
        if (eventPublisherElement != null) {
            OMElement receiverUrlGroupElement = eventPublisherElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_REVEIVER_URL_GROUP));
            if (receiverUrlGroupElement != null) {
                eventHubPublisherConfiguration.setReceiverUrlGroup(APIUtil.replaceSystemProperty(receiverUrlGroupElement.getText()));
            }
            OMElement authUrlGroupElement = eventPublisherElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_AUTH_URL_GROUP));
            if (authUrlGroupElement != null) {
                eventHubPublisherConfiguration.setAuthUrlGroup(APIUtil.replaceSystemProperty(authUrlGroupElement.getText()));
            }
            OMElement eventTypeElement = eventPublisherElement.getFirstChildWithName(new QName(APIConstants.AdvancedThrottleConstants.DATA_PUBLISHER_CONFIGURAION_TYPE));
            if (eventTypeElement != null) {
                eventHubPublisherConfiguration.setType(eventTypeElement.getText().trim());
            }
            Map<String, String> publisherProps = extractPublisherProperties(eventPublisherElement);
            if (publisherProps != null) {
                eventHubPublisherConfiguration.setProperties(publisherProps);
            }
            eventHubConfigurationDto.setEventHubPublisherConfiguration(eventHubPublisherConfiguration);
        }
    }
    this.eventHubConfigurationDto = eventHubConfigurationDto;
}
Also used : EventHubConfigurationDto(org.wso2.carbon.apimgt.impl.dto.EventHubConfigurationDto) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) GatewayArtifactSynchronizerProperties(org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties) WorkflowProperties(org.wso2.carbon.apimgt.impl.dto.WorkflowProperties) Properties(java.util.Properties) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)

Example 13 with ServiceURL

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

the class APIUtil method getLoggedInUserInfo.

/**
 * Gets the information of the logged in User.
 *
 * @param cookie     Cookie of the previously logged in session.
 * @param serviceUrl Url of the authentication service.
 * @return LoggedUserInfo object containing details of the logged in user.
 * @throws ExceptionException
 * @throws RemoteException
 */
public static LoggedUserInfo getLoggedInUserInfo(String cookie, String serviceUrl) throws RemoteException, ExceptionException {
    LoggedUserInfoAdminStub stub = new LoggedUserInfoAdminStub(null, serviceUrl + "LoggedUserInfoAdmin");
    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();
    options.setManageSession(true);
    options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
    return stub.getUserInfo();
}
Also used : Options(org.apache.axis2.client.Options) ServiceClient(org.apache.axis2.client.ServiceClient) LoggedUserInfoAdminStub(org.wso2.carbon.core.commons.stub.loggeduserinfo.LoggedUserInfoAdminStub)

Example 14 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 15 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)

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