Java Code Examples for org.apache.axis2.description.AxisService#getParameter()

The following examples show how to use org.apache.axis2.description.AxisService#getParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private DataService getDataServiceByServicePath(String servicePath) throws Exception {
	Parameter tmpParam;
	DataService tmpDS;
	String canonicalServicePath = new File(servicePath).getCanonicalPath();
	for (AxisService axisService : this.axisConfig.getServices().values()) {
		tmpParam = axisService.getParameter(DBConstants.DATA_SERVICE_OBJECT);
		if (tmpParam != null) {
			tmpDS = (DataService) tmpParam.getValue();
			if (new File(tmpDS.getDsLocation()).getCanonicalPath().equals(
					canonicalServicePath)) {
		    	return tmpDS;
		    }
		}
	}
	//throw new DataServiceFault("Data service at '" + servicePath + "' cannot be found");
	return null;
}
 
Example 2
Source File: MessageSender.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private Config getDiscoveryConfig(AxisService service) {
    Parameter parameter = service.getParameter(DiscoveryConstants.WS_DISCOVERY_PARAMS);
    Config config;
    if (parameter != null) {
        OMElement element = parameter.getParameterElement();

        // For a ProxyService, the parameter defined as XML, is returned as a string value.
        // Until this problem is solved, we'll be adopting the approach below, to make an
        // attempt to construct the parameter element.
        if (element == null) {
            if (parameter.getValue() != null) {
                try {
                    String wrappedElementText = "<wrapper>" + parameter.getValue() + "</wrapper>";
                    element = AXIOMUtil.stringToOM(wrappedElementText);
                } catch (Exception ignored) { }
            } else {
                return getDefaultConfig();
            }
        }

        config = Config.fromOM(element);
    } else {
        return getDefaultConfig();
    }
    return config;
}
 
Example 3
Source File: SecurityServiceAdmin.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public void setServiceParameterElement(String serviceName, Parameter parameter)
        throws AxisFault {
    AxisService axisService = axisConfig.getService(serviceName);

    if (axisService == null) {
        throw new AxisFault("Invalid service name '" + serviceName + "'");
    }

    Parameter p = axisService.getParameter(parameter.getName());
    if (p != null) {
        if (!p.isLocked()) {
            axisService.addParameter(parameter);
        }
    } else {
        axisService.addParameter(parameter);
    }

}
 
Example 4
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public void setProofKeyType(String keyType) throws SecurityConfigException {
    try {
        AxisService service = getAxisConfig().getService(ServerConstants.STS_NAME);
        Parameter origParam = service.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG
                .getLocalPart());
        if (origParam != null) {
            OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName(
                    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG);
            SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem);
            samlConfig.setProofKeyType(keyType);
            setSTSParameter(samlConfig);
        } else {
            throw new AxisFault("missing parameter : "
                    + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart());
        }

    } catch (Exception e) {
        log.error("Error setting proof key type", e);
        throw new SecurityConfigException(e.getMessage(), e);
    }
}
 
Example 5
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public String getProofKeyType() throws SecurityConfigException {
    try {
        AxisService service = getAxisConfig().getService(ServerConstants.STS_NAME);
        Parameter origParam = service.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG
                .getLocalPart());
        if (origParam != null) {
            OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName(
                    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG);
            SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem);
            return samlConfig.getProofKeyType();
        } else {
            throw new SecurityConfigException("missing parameter : "
                    + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart());
        }
    } catch (Exception e) {
        log.error("Error while retrieving proof key type", e);
        throw new SecurityConfigException(e.getMessage(), e);
    }
}
 
Example 6
Source File: ApplicationAdmin.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Finds the artifact type of the given service. Service type parameter is used to check this.
 *
 * @param service - AxisService instance
 * @param fileName - file name of the service artifact
 * @return - Service type
 */
private String getArtifactTypeFromService(AxisService service, String fileName) {
    String artifactType = null;

    Parameter serviceTypeParam = service.getParameter(ServerConstants.SERVICE_TYPE);
    String serviceType;
    if (serviceTypeParam != null) {
        serviceType = (String) serviceTypeParam.getValue();
    } else {
        if (fileName.endsWith(".jar")) {
            serviceType = "jaxws";
        } else {
            serviceType = "axis2";
        }
    }

    if (serviceType.equals("axis2")) {
        artifactType = DefaultAppDeployer.AAR_TYPE;
    } else if (serviceType.equals("data_service")) {
        artifactType = DS_TYPE;
    }
    return artifactType;
}
 
Example 7
Source File: STSConfigAdmin.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Override WSAS callback handler to be able to auth users with usermanager.
 *
 * @param axisConfig
 * @throws AxisFault
 */
public static void overrideCallbackHandler(AxisConfiguration axisConfig, String service) throws AxisFault {
    AxisService sts = axisConfig.getService(service);
    Parameter cbHandlerParam = sts.getParameter(WSHandlerConstants.PW_CALLBACK_REF);
    if (cbHandlerParam != null) {
        sts.removeParameter(cbHandlerParam);
        if (log.isDebugEnabled()) {
            log.debug("removedParameter");
        }
    }

    Parameter param = getPasswordCallBackRefParameter();

    sts.addParameter(param);

    if (log.isDebugEnabled()) {
        log.debug("addedParameter");
    }
}
 
Example 8
Source File: SecurityDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private Policy applyPolicyToBindings(AxisService axisService) throws ServerException {
    Parameter parameter = axisService.getParameter(APPLY_POLICY_TO_BINDINGS);
    if (parameter != null && "true".equalsIgnoreCase(parameter.getValue().toString()) &&
            axisService.getPolicySubject() != null && axisService.getPolicySubject().getAttachedPolicyComponents()
            != null) {
        Iterator iterator = axisService.getPolicySubject().
                getAttachedPolicyComponents().iterator();
        while (iterator.hasNext()) {
            PolicyComponent currentPolicyComponent = (PolicyComponent) iterator.next();
            if (currentPolicyComponent instanceof Policy) {
                Policy policy = ((Policy) currentPolicyComponent);
                String policyId = policy.getId();
                axisService.getPolicySubject().detachPolicyComponent(policyId);
                addPolicyToAllBindings(axisService, policy);
                return policy;
            }
        }
    }
    return null;
}
 
Example 9
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public void removeTrustedService(String serviceAddress) throws SecurityConfigException {
    try {
        AxisService stsService = getAxisConfig().getService(ServerConstants.STS_NAME);
        Parameter origParam = stsService.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG
                .getLocalPart());
        if (origParam != null) {
            OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName(
                    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG);
            SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem);
            samlConfig.getTrustedServices().remove(serviceAddress);
            setSTSParameter(samlConfig);
            removeTrustedService(ServerConstants.STS_NAME, ServerConstants.STS_NAME,
                    serviceAddress);
        } else {
            throw new AxisFault("missing parameter : "
                    + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart());
        }

    } catch (Exception e) {
        log.error("Error while removing a trusted service", e);
        throw new SecurityConfigException(e.getMessage(), e);
    }
}
 
Example 10
Source File: SystemStatisticsUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public long getMaxServiceResponseTime(AxisService axisService) throws AxisFault {
    long max = 0;
    Parameter parameter =
            axisService.getParameter(StatisticsConstants.SERVICE_RESPONSE_TIME_PROCESSOR);
    if (parameter != null) {
        ResponseTimeProcessor proc = (ResponseTimeProcessor) parameter.getValue();
        max = proc.getMaxResponseTime();
    }
    return max;
}
 
Example 11
Source File: SystemStatisticsUtil.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public double getAvgServiceResponseTime(AxisService axisService) throws AxisFault {
    double avg = 0;
    Parameter parameter =
            axisService.getParameter(StatisticsConstants.SERVICE_RESPONSE_TIME_PROCESSOR);
    if (parameter != null) {
        ResponseTimeProcessor proc = (ResponseTimeProcessor) parameter.getValue();
        avg = proc.getAvgResponseTime();
    }
    return avg;
}
 
Example 12
Source File: Util.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Get the WS-D types of an Axis2 service. By default the port types of the
 * service are considered as WS-D types.
 *
 * @param axisService The Axis2 service
 * @return a WS-D type to be associated with the service
 */
public static QName getTypes(AxisService axisService) {
    QName portType;
    String localPart;
    if (axisService.getParameter(WSDL2Constants.INTERFACE_LOCAL_NAME) != null) {
        localPart = (String) axisService.getParameter(
                WSDL2Constants.INTERFACE_LOCAL_NAME).getValue();
    } else {
        localPart = axisService.getName() + Java2WSDLConstants.PORT_TYPE_SUFFIX;
    }
    portType = new QName(axisService.getTargetNamespace(), localPart);
    return portType;
}
 
Example 13
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public TrustedServiceData[] getTrustedServices() throws SecurityConfigException {
    try {
        AxisService service = getAxisConfig().getService(ServerConstants.STS_NAME);
        Parameter origParam = service.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG
                .getLocalPart());
        if (origParam != null) {
            OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName(
                    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG);
            SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem);
            Map trustedServicesMap = samlConfig.getTrustedServices();
            Set addresses = trustedServicesMap.keySet();

            List serviceBag = new ArrayList();
            for (Iterator iterator = addresses.iterator(); iterator.hasNext(); ) {
                String address = (String) iterator.next();
                String alias = (String) trustedServicesMap.get(address);
                TrustedServiceData data = new TrustedServiceData(address, alias);
                serviceBag.add(data);
            }
            return (TrustedServiceData[]) serviceBag.toArray(new TrustedServiceData[serviceBag
                    .size()]);
        } else {
            throw new SecurityConfigException("missing parameter : "
                    + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart());
        }
    } catch (Exception e) {
        log.error("Error while retrieving trusted services", e);
        throw new SecurityConfigException(e.getMessage(), e);
    }
}
 
Example 14
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void addTrustedService(String serviceAddress, String certAlias)
        throws SecurityConfigException {
    try {
        AxisService stsService = getAxisConfig().getService(ServerConstants.STS_NAME);
        Parameter origParam = stsService.getParameter(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG
                .getLocalPart());
        if (origParam != null) {
            OMElement samlConfigElem = origParam.getParameterElement().getFirstChildWithName(
                    SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG);
            SAMLTokenIssuerConfig samlConfig = new SAMLTokenIssuerConfig(samlConfigElem);
            samlConfig.addTrustedServiceEndpointAddress(serviceAddress, certAlias);
            setSTSParameter(samlConfig);
            persistTrustedService(ServerConstants.STS_NAME,
                    ServerConstants.STS_NAME,
                    serviceAddress,
                    certAlias);
        } else {
            throw new AxisFault("missing parameter : "
                    + SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG.getLocalPart());
        }

    } catch (Exception e) {
        log.error("Error while adding a trusted service", e);
        throw new SecurityConfigException(e.getMessage(), e);
    }
}
 
Example 15
Source File: AbstractAdmin.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void checkAdminService() {
    MessageContext msgCtx = MessageContext.getCurrentMessageContext();
    if (msgCtx == null) {
        return;
    }
    AxisService axisService = msgCtx.getAxisService();
    if (axisService.getParameter(Constants.ADMIN_SERVICE_PARAM_NAME) == null) {
        throw new RuntimeException(
                "AbstractAdmin can only be extended by Carbon admin services. " + getClass().getName()
                        + " is not an admin service. Service name " + axisService.getName()
                        + ". The service should have defined the " + Constants.ADMIN_SERVICE_PARAM_NAME
                        + " parameter");
    }
}
 
Example 16
Source File: ServiceAdmin.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private String getServiceType(AxisService service) {

        Parameter serviceTypeParam = service.getParameter("serviceType");
        String serviceType;
        if (serviceTypeParam != null) {
            serviceType = (String) serviceTypeParam.getValue();
        } else {
            serviceType = "axis2";
        }

        return serviceType;
    }
 
Example 17
Source File: SwaggerUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch the swagger from registry if available or create one from scratch.
 *
 * @param requestURI           request URI.
 * @param configurationContext Configuration context with details.
 * @param isJSON               result format JSON or YAML.
 * @return Swagger definition as string
 * @throws AxisFault Error occurred while fetching the host details.
 */
public static String getDataServiceSwagger(String requestURI, ConfigurationContext configurationContext,
                                           boolean isJSON) throws AxisFault, SwaggerException {
    String dataServiceName = requestURI.substring(requestURI.lastIndexOf("/") + 1);
    AxisService dataService = configurationContext.getAxisConfiguration().getService(dataServiceName);
    if (dataService != null) {
        MIServerConfig serverConfig = new MIServerConfig();
        Object dataServiceObject =
                dataService.getParameter(SwaggerProcessorConstants.DATA_SERVICE_OBJECT).getValue();
        if (dataService.getParameter(SwaggerProcessorConstants.SWAGGER_RESOURCE_PATH) != null) {
            String swaggerLocation =
                    (String) dataService.getParameter(SwaggerProcessorConstants.SWAGGER_RESOURCE_PATH).getValue();
            if (StringUtils.isNotEmpty(swaggerLocation)) {
                String swaggerFromReg = SwaggerUtils.fetchSwaggerFromRegistry(swaggerLocation);
                if (StringUtils.isNotEmpty(swaggerFromReg)) {
                    return swaggerFromReg;
                } else throw new SwaggerException("Could not fetch the swagger definition from registry. Registry" +
                        " path : " + swaggerLocation);
            }
            return null;
        } else {
            List<String> transports = dataService.getExposedTransports();
            if (dataServiceObject instanceof AxisResources) {
                AxisResourceMap axisResourceMap = ((AxisResources) dataServiceObject).getAxisResourceMap();
                return SwaggerUtils.createSwaggerFromDefinition(axisResourceMap, dataServiceName, transports,
                        serverConfig, isJSON);
            }
        }
        return null;
    }
    return null;
}
 
Example 18
Source File: DBUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method verifies whether there's an existing data service for the given name.
 *
 * @param axisConfiguration Axis configuration
 * @param dataService       Data service
 * @return Boolean (Is available)
 * @throws AxisFault
 */
public static boolean isAvailableDS(AxisConfiguration axisConfiguration, String dataService) throws AxisFault {
    Map<String, AxisService> map = axisConfiguration.getServices();
    AxisService axisService = map.get(dataService);
    if (axisService != null) {
        Parameter parameter = axisService.getParameter(DBConstants.AXIS2_SERVICE_TYPE);
        if (parameter != null) {
            if (DBConstants.DB_SERVICE_TYPE.equals(parameter.getValue().toString())) {
                return true;
            }
        }
    }
    return false;
}
 
Example 19
Source File: ServiceAdmin.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public ServiceMetaData getServiceData(String serviceName) throws Exception {

        AxisService service = axisConfiguration.getServiceForActivation(serviceName);

        if (service == null) {
            String msg = "Invalid service name, service not found : " + serviceName;
            throw new AxisFault(msg);
        }

        String serviceType = getServiceType(service);
        List<String> ops = new ArrayList<String>();
        for (Iterator<AxisOperation> opIter = service.getOperations(); opIter.hasNext(); ) {
            AxisOperation axisOperation = opIter.next();

            if (axisOperation.getName() != null) {
                ops.add(axisOperation.getName().getLocalPart());
            }
        }

        ServiceMetaData serviceMetaData = new ServiceMetaData();
        serviceMetaData.setOperations(ops.toArray(new String[ops.size()]));
        serviceMetaData.setName(serviceName);
        serviceMetaData.setServiceId(serviceName);
        serviceMetaData.setServiceVersion("");
        serviceMetaData.setActive(service.isActive());
        String[] eprs = this.getServiceEPRs(serviceName);
        serviceMetaData.setEprs(eprs);
        serviceMetaData.setServiceType(serviceType);

        serviceMetaData.setWsdlURLs(Utils.getWsdlInformation(serviceName, axisConfiguration));

        AxisServiceGroup serviceGroup = (AxisServiceGroup) service.getParent();
        serviceMetaData.setFoundWebResources(serviceGroup.isFoundWebResources());
        serviceMetaData.setScope(service.getScope());
        serviceMetaData.setWsdlPorts(service.getEndpoints());
        Parameter deploymentTime = service.getParameter("serviceDeploymentTime");
        if (deploymentTime != null) {
            serviceMetaData.setServiceDeployedTime((Long) deploymentTime.getValue());
        }

        serviceMetaData.setServiceGroupName(serviceGroup.getServiceGroupName());

        if (service.getDocumentation() != null) {
            serviceMetaData.setDescription(service.getDocumentation());
        } else {
            serviceMetaData.setDescription("No service description found");
        }

        Parameter parameter = service.getParameter("enableMTOM");
        if (parameter != null) {
            serviceMetaData.setMtomStatus((String) parameter.getValue());
        } else {
            serviceMetaData.setMtomStatus("false");
        }

        parameter = service.getParameter("disableTryIt");
        if (parameter != null && Boolean.TRUE.toString().equalsIgnoreCase((String) parameter.getValue())) {
            serviceMetaData.setDisableTryit(true);
        }

        return serviceMetaData;
    }
 
Example 20
Source File: SecurityConfigAdmin.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public SecurityConfigData getSecurityConfigData(String serviceName, String scenarioId,
                                                String policyPath) throws SecurityConfigException {

    SecurityConfigData data = null;
    AxisService service = axisConfig.getServiceForActivation(serviceName);
    String serviceGroupId = service.getAxisServiceGroup().getServiceGroupName();
    try {
        if (scenarioId == null) {
            return data;
        }
        /**
         * Scenario ID can either be a default one (out of 15) or "policyFromRegistry", which
         * means the current scenario refers to a custom policy from registry. If that is the
         * case, we can't read the current scenario from the WSU ID. Therefore, we don't
         * check the scenario ID. In default cases, we check it.
         */
        if (scenarioId.equals(SecurityConstants.POLICY_FROM_REG_SCENARIO)) {
            Parameter param = service.getParameter(SecurityConstants.SECURITY_POLICY_PATH);
            if (param == null || !policyPath.equals(param.getValue())) {
                return data;
            }
        } else {
            SecurityScenario scenario = readCurrentScenario(serviceName);
            if (scenario == null || !scenario.getScenarioId().equals(scenarioId)) {
                return data;
            }
        }

        Policy policy = getCurrentPolicy(service);
        OMElement carbonSecConfig = getCarbonSecConfigs(policy);
        RampartConfig rampartConfigs = getRampartConfigs(policy);
        Map<String, String> trustProperties = getTrustProperties(carbonSecConfig);
        KerberosConfigData kerberosData = this.readKerberosConfigurations(carbonSecConfig);

        data = new SecurityConfigData();
        data.setKerberosConfigurations(kerberosData);
        //may be we don't need this in the new persistence model
        // String serviceXPath = PersistenceUtils.getResourcePath(service);
        AuthorizationManager acReader = realm.getAuthorizationManager();
        String[] roles = acReader.getAllowedRolesForResource(
                serviceGroupId + "/" + serviceName,
                UserCoreConstants.INVOKE_SERVICE_PERMISSION);

        data.setUserGroups(roles);

        String privateStore = getProperty(rampartConfigs, trustProperties, ServerCrypto.PROP_ID_PRIVATE_STORE);
        if (StringUtils.isNotBlank(privateStore)) {
            data.setPrivateStore(privateStore);
        }

        String trustedStores = getProperty(rampartConfigs, trustProperties, ServerCrypto.PROP_ID_TRUST_STORES);
        if (StringUtils.isNotBlank(trustedStores)) {
            data.setTrustedKeyStores(trustedStores.split(","));
        }
        return data;

    } catch (UserStoreException e) {
        log.error("Error in getting security config data. Failed to get Authorization Manager", e);
    }
    return data;
}