Java Code Examples for org.apache.axis2.description.Parameter#setName()

The following examples show how to use org.apache.axis2.description.Parameter#setName() . 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: ServiceComponent.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void engagePoxSecurity() {
    try {
        AxisConfiguration axisConfig = DataHolder.getInstance().getConfigCtx().getAxisConfiguration();
        Parameter passwordCallbackParam = new Parameter();
        DefaultPasswordCallback passwordCallbackClass = new DefaultPasswordCallback();
        passwordCallbackParam.setName("passwordCallbackRef");
        passwordCallbackParam.setValue(passwordCallbackClass);
        axisConfig.addParameter(passwordCallbackParam);
        String enablePoxSecurity = CarbonServerConfigurationService.getInstance()
                .getFirstProperty("EnablePoxSecurity");
        if (enablePoxSecurity == null || "true".equals(enablePoxSecurity)) {
            AxisConfiguration mainAxisConfig = DataHolder.getInstance().getConfigCtx().getAxisConfiguration();
            // Check for the module availability
            if (mainAxisConfig.getModules().toString().contains(POX_SECURITY_MODULE)){
                mainAxisConfig.engageModule(POX_SECURITY_MODULE);
                log.debug("UT Security is activated");
            } else {
                log.error("UT Security is not activated UTsecurity.mar is not available");
            }
        } else {
            log.debug("POX Security Disabled");
        }
    } catch (Throwable e) {
        log.error("Failed to activate Micro Integrator UT security module ", e);
    }
}
 
Example 2
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static Parameter toAxisParameter(TransportParameter parameter) throws XMLStreamException {
    Parameter p = new Parameter();
    p.setName(parameter.getName());

    OMElement paramElement = AXIOMUtil.stringToOM(parameter.getParamElement());
    p.setParameterElement(paramElement);

    if (paramElement.getFirstElement() != null) {
        p.setValue(paramElement);
        p.setParameterType(Parameter.OM_PARAMETER);
    } else {
        p.setValue(paramElement.getText());
        p.setParameterType(Parameter.TEXT_PARAMETER);
    }
    return p;
}
 
Example 3
Source File: SecurityConfigAdmin.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
protected void disableRESTCalls(String serviceName, String scenrioId)
        throws SecurityConfigException {

    if (scenrioId.equals(SecurityConstants.USERNAME_TOKEN_SCENARIO_ID)) {
        return;
    }

    try {
        AxisService service = axisConfig.getServiceForActivation(serviceName);
        if (service == null) {
            throw new SecurityConfigException("nullService");
        }

        Parameter param = new Parameter();
        param.setName(DISABLE_REST);
        param.setValue(Boolean.TRUE.toString());
        service.addParameter(param);

    } catch (AxisFault e) {
        log.error(e);
        throw new SecurityConfigException("disablingREST", e);
    }
}
 
Example 4
Source File: RahasUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static Parameter getTokenCancelerConfigParameter() {

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMElement paramElem = fac.createOMElement(new QName("parameter"), null);
        paramElem.addAttribute(fac.createOMAttribute("name",
                null,
                TokenCancelerConfig.TOKEN_CANCELER_CONFIG.
                        getLocalPart()));
        paramElem.addAttribute(fac.createOMAttribute("type",
                null, Integer.toString(Parameter.OM_PARAMETER).
                        toString()));

        fac.createOMElement(TokenCancelerConfig.TOKEN_CANCELER_CONFIG,
                paramElem);
        Parameter param = new Parameter();
        param.setName(TokenCancelerConfig.TOKEN_CANCELER_CONFIG.getLocalPart());
        param.setParameterElement(paramElem);
        param.setValue(paramElem);
        param.setParameterType(Parameter.OM_PARAMETER);
        return param;
    }
 
Example 5
Source File: ResponseTimeCalculator.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private static void updateCurrentInvocationStatistic(MessageContext messageContext,
                                                     long responseTime) throws AxisFault {
    messageContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_INVOCATION_RESPONSE_TIME,responseTime);

    if (messageContext.getAxisOperation() != null) {
        Parameter operationResponseTimeParam = new Parameter();
        operationResponseTimeParam.setName(StatisticsConstants.OPERATION_RESPONSE_TIME);
        operationResponseTimeParam.setValue(responseTime);
        messageContext.getAxisOperation().addParameter(operationResponseTimeParam);
    }

    if (messageContext.getAxisService() != null) {
        Parameter serviceResponseTimeParam = new Parameter();
        serviceResponseTimeParam.setName(StatisticsConstants.SERVICE_RESPONSE_TIME);
        serviceResponseTimeParam.setValue(responseTime);
        messageContext.getAxisService().addParameter(serviceResponseTimeParam);
    }
}
 
Example 6
Source File: StartupFinalizer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void setServerStartTimeParam() {
    Parameter startTimeParam = new Parameter();
    startTimeParam.setName(SERVER_START_TIME);
    startTimeParam.setValue(System.getProperty(START_TIME));
    try {
        configCtx.getAxisConfiguration().addParameter(startTimeParam);
    } catch (AxisFault e) {
        log.error("Could not set the  server start time parameter", e);
    }
}
 
Example 7
Source File: StartupFinalizer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void setServerStartUpDurationParam(String startupTime) {
    Parameter startupDurationParam = new Parameter();
    startupDurationParam.setName(START_UP_DURATION);
    startupDurationParam.setValue(startupTime);
    try {
        configCtx.getAxisConfiguration().addParameter(startupDurationParam);
    } catch (AxisFault e) {
        log.error("Could not set the  server start up duration parameter", e);
    }
}
 
Example 8
Source File: STSConfigAdmin.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static Parameter getPasswordCallBackRefParameter() throws AxisFault {
    Parameter param = new Parameter();
    param.setName(WSHandlerConstants.PW_CALLBACK_REF);
    try {
        param.setValue(new IPPasswordCallbackHandler());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new AxisFault(e.getMessage(), e);
    }
    return param;
}
 
Example 9
Source File: POXSecurityHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private String getScenarioId(MessageContext msgCtx, AxisService service) throws SecurityConfigException {
    String scenarioID = null;
    try {
        scenarioID = (String) service.getParameter(SecurityConstants.SCENARIO_ID_PARAM_NAME).getValue();
    } catch (Exception e) {
    }//ignore

    if (scenarioID == null) {
        synchronized (this) {
            SecurityConfigAdmin securityAdmin = new SecurityConfigAdmin(msgCtx.
                    getConfigurationContext().getAxisConfiguration());
            SecurityScenarioData data = securityAdmin.getCurrentScenario(service.getName());
            if (data != null) {
                scenarioID = data.getScenarioId();
                try {
                    Parameter param = new Parameter();
                    param.setName(SecurityConstants.SCENARIO_ID_PARAM_NAME);
                    param.setValue(scenarioID);
                    service.addParameter(param);
                } catch (AxisFault axisFault) {
                    log.error("Error while adding Scenario ID parameter", axisFault);
                }
            }
        }
    }

    return scenarioID;
}
 
Example 10
Source File: SystemStatisticsDeploymentInterceptor.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void serviceUpdate(AxisEvent axisEvent, AxisService axisService) {

        if (SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) || axisService.isClientSide()) {
            return;
        }
        if (axisEvent.getEventType() == AxisEvent.SERVICE_DEPLOY) {
            for (Iterator iter = axisService.getOperations(); iter.hasNext(); ) {
                AxisOperation op = (AxisOperation) iter.next();
                setCountersAndProcessors(op);
            }
            // see ESBJAVA-2327
            if (JavaUtils.isTrueExplicitly(axisService.getParameterValue("disableOperationValidation"))) {
                AxisOperation defaultOp = (AxisOperation) axisService.getParameterValue("_default_mediate_operation_");
                if (defaultOp != null) {
                    setCountersAndProcessors(defaultOp);
                }
            }
            // Service response time processor
            Parameter responseTimeProcessor = new Parameter();
            responseTimeProcessor.setName(StatisticsConstants.SERVICE_RESPONSE_TIME_PROCESSOR);
            responseTimeProcessor.setValue(new ResponseTimeProcessor());
            try {
                axisService.addParameter(responseTimeProcessor);
            } catch (AxisFault axisFault) {
                // will not occur
            }
        }
    }
 
Example 11
Source File: StatisticsModule.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void init(ConfigurationContext configContext,
                 AxisModule module) throws AxisFault {

    AxisConfiguration axisConfig = configContext.getAxisConfiguration();

    {
        AtomicInteger globalRequestCounter = new AtomicInteger(0);
        Parameter globalRequestCounterParam = new Parameter();
        globalRequestCounterParam.setName(StatisticsConstants.GLOBAL_REQUEST_COUNTER);
        globalRequestCounterParam.setValue(globalRequestCounter);
        axisConfig.addParameter(globalRequestCounterParam);
    }

    {
        AtomicInteger globalResponseCounter = new AtomicInteger(0);
        Parameter globalResponseCounterParam = new Parameter();
        globalResponseCounterParam.setName(StatisticsConstants.GLOBAL_RESPONSE_COUNTER);
        globalResponseCounterParam.setValue(globalResponseCounter);
        axisConfig.addParameter(globalResponseCounterParam);
    }

    {
        AtomicInteger globalFaultCounter = new AtomicInteger(0);
        Parameter globalFaultCounterParam = new Parameter();
        globalFaultCounterParam.setName(StatisticsConstants.GLOBAL_FAULT_COUNTER);
        globalFaultCounterParam.setValue(globalFaultCounter);
        axisConfig.addParameter(globalFaultCounterParam);
    }

    {
        ResponseTimeProcessor responseTimeProcessor = new ResponseTimeProcessor();
        Parameter responseTimeProcessorParam = new Parameter();
        responseTimeProcessorParam.setName(StatisticsConstants.RESPONSE_TIME_PROCESSOR);
        responseTimeProcessorParam.setValue(responseTimeProcessor);
        axisConfig.addParameter(responseTimeProcessorParam);
    }
}
 
Example 12
Source File: ParameterUtil.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Create an Axis2 parameter using the given OMElement
 *
 * @param parameterElement The OMElement of the parameter
 * @return Axis2 parameter with an the given OMElement
 * @throws AxisFault If the <code>parameterElement</code> is malformed
 */
public static Parameter createParameter(OMElement parameterElement) throws AxisFault {
    if(parameterElement.getParent() instanceof OMDocument) {
        parameterElement.detach();  //To enable a unified way of accessing the parameter via xpath.
    }
    Parameter parameter = new Parameter();
    //setting parameterElement
    parameter.setParameterElement(parameterElement);

    //setting parameter Name
    OMAttribute paraName = parameterElement.getAttribute(new QName("name"));
    if (paraName == null) {
        throw new AxisFault(Messages.getMessage(DeploymentErrorMsgs.BAD_PARAMETER_ARGUMENT));
    }
    parameter.setName(paraName.getAttributeValue());

    //setting parameter Value (the chiled elemnt of the parameter)
    OMElement paraValue = parameterElement.getFirstElement();
    if (paraValue != null) {
        parameter.setValue(parameterElement);
        parameter.setParameterType(Parameter.OM_PARAMETER);
    } else {
        String paratextValue = parameterElement.getText();
        parameter.setValue(paratextValue);
        parameter.setParameterType(Parameter.TEXT_PARAMETER);
    }

    //setting locking attribute
    OMAttribute paraLocked = parameterElement.getAttribute(new QName("locked"));
    parameter.setParameterElement(parameterElement);

    if (paraLocked != null) {
        String lockedValue = paraLocked.getAttributeValue();
        if ("true".equals(lockedValue)) {

            parameter.setLocked(true);

        } else {
            parameter.setLocked(false);
        }
    }
    return parameter;
}
 
Example 13
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Processes transport parameters from the given configuration.
 * 
 * @param parameters An Iterator of OMElement which contains transport parameters.
 * @param parameterInclude ParameterInclude
 * @throws DeploymentException on error
 */
private static void processParameters(Iterator parameters,
                                         ParameterInclude parameterInclude) throws DeploymentException {

       if (parameters == null) {
           return;
       }

	while (parameters.hasNext()) {
		// this is to check whether some one has locked the parameter at the
		// top level
		OMElement parameterElement = (OMElement) parameters.next();
		Parameter parameter = new Parameter();
		// setting parameterElement
		parameter.setParameterElement(parameterElement);
		// setting parameter Name
		OMAttribute paramName = parameterElement.getAttribute(new QName(ATTRIBUTE_NAME));
		if (paramName == null) {
			throw new DeploymentException(Messages.getMessage(
					DeploymentErrorMsgs.BAD_PARAMETER_ARGUMENT, parameterElement.toString()));
		}
		parameter.setName(paramName.getAttributeValue());
		// setting parameter Value (the child element of the parameter)
		OMElement paramValue = parameterElement.getFirstElement();
		if (paramValue != null) {
			parameter.setValue(parameterElement);
			parameter.setParameterType(Parameter.OM_PARAMETER);
		} else {
			String paratextValue = parameterElement.getText();
			parameter.setValue(paratextValue);
			parameter.setParameterType(Parameter.TEXT_PARAMETER);
		}
		// setting locking attribute
		OMAttribute paramLocked = parameterElement.getAttribute(new QName(ATTRIBUTE_LOCKED));

		if (paramLocked != null) {
			String lockedValue = paramLocked.getAttributeValue();
			if (BOOLEAN_TRUE.equals(lockedValue)) {
				parameter.setLocked(true);
			} else {
				parameter.setLocked(false);
			}
		}
		try {
			parameterInclude.addParameter(parameter);
		} catch (AxisFault axisFault) {
			throw new DeploymentException(axisFault);
		}
	}
}
 
Example 14
Source File: SecurityDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
private void applySecurityParameters(AxisService service, SecurityScenario secScenario,
                                     Policy policy) {
    try {

        UserRealm userRealm = (UserRealm) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                .getUserRealm();

        UserRegistry govRegistry = (UserRegistry) PrivilegedCarbonContext
                .getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE);

        String serviceGroupId = service.getAxisServiceGroup().getServiceGroupName();
        String serviceName = service.getName();

        SecurityConfigParams configParams =
                SecurityConfigParamBuilder.getSecurityParams(getSecurityConfig(policy));

        // Set Trust (Rahas) Parameters
        if (secScenario.getModules().contains(SecurityConstants.TRUST_MODULE)) {
            AxisModule trustModule = service.getAxisConfiguration()
                    .getModule(SecurityConstants.TRUST_MODULE);
            if (log.isDebugEnabled()) {
                log.debug("Enabling trust module : " + SecurityConstants.TRUST_MODULE);
            }

            service.disengageModule(trustModule);
            service.engageModule(trustModule);

            Properties cryptoProps = new Properties();
            cryptoProps.setProperty(ServerCrypto.PROP_ID_PRIVATE_STORE,
                                    configParams.getPrivateStore());
            cryptoProps.setProperty(ServerCrypto.PROP_ID_DEFAULT_ALIAS,
                                    configParams.getKeyAlias());
            if (configParams.getTrustStores() != null) {
                cryptoProps.setProperty(ServerCrypto.PROP_ID_TRUST_STORES,
                                        configParams.getTrustStores());
            }
            service.addParameter(RahasUtil.getSCTIssuerConfigParameter(
                    ServerCrypto.class.getName(), cryptoProps, -1, null, true, true));

            service.addParameter(RahasUtil.getTokenCancelerConfigParameter());

        }

        // Authorization
        AuthorizationManager manager = userRealm.getAuthorizationManager();
        String resourceName = serviceGroupId + "/" + serviceName;
        removeAuthorization(userRealm,serviceGroupId,serviceName);
        String allowRolesParameter = configParams.getAllowedRoles();
        if (allowRolesParameter != null) {
            if (log.isDebugEnabled()) {
                log.debug("Authorizing roles " + allowRolesParameter);
            }
            String[] allowRoles = allowRolesParameter.split(",");
            if (allowRoles != null) {
                for (String role : allowRoles) {
                    manager.authorizeRole(role, resourceName,
                                          UserCoreConstants.INVOKE_SERVICE_PERMISSION);
                }
            }
        }

        // Password Callback Handler
        ServicePasswordCallbackHandler handler =
                new ServicePasswordCallbackHandler(configParams, serviceGroupId, serviceName,
                                                   govRegistry, userRealm);

        Parameter param = new Parameter();
        param.setName(WSHandlerConstants.PW_CALLBACK_REF);
        param.setValue(handler);
        service.addParameter(param);

    } catch (Throwable e) {
    //TODO: Copied from 4.2.2.
    //TODO: Not sure why we are catching throwable. Need to check error handling is correct
        String msg = "Cannot apply security parameters";
        log.error(msg, e);
    }
}
 
Example 15
Source File: RahasUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static Parameter getSCTIssuerConfigParameter(String cryptoImpl,
                                                    Properties cryptoProperties,
                                                    int keyComputation,
                                                    String proofKeyType,
                                                    boolean addRequestedAttachedRef,
                                                    boolean addRequestedUnattachedRef) throws Exception {

    if (cryptoImpl == null || "".equals(cryptoImpl)) {
        throw new Exception("Crypto impl missing");
    }

    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement paramElem = fac.createOMElement(new QName("parameter"), null);
    paramElem.addAttribute(fac.createOMAttribute("name",
            null,
            SCTIssuerConfig.SCT_ISSUER_CONFIG.
                    getLocalPart()));

    paramElem.addAttribute(fac.createOMAttribute("type",
            null, Integer.toString(Parameter.OM_PARAMETER)));

    OMElement elem = fac.createOMElement(
            SCTIssuerConfig.SCT_ISSUER_CONFIG, paramElem);

    OMElement cryptoPropElem = fac.createOMElement(
            AbstractIssuerConfig.CRYPTO_PROPERTIES, elem);
    OMElement cryptoElem = fac.createOMElement(
            AbstractIssuerConfig.CRYPTO, cryptoPropElem);
    cryptoElem.addAttribute(fac.createOMAttribute("provider", null,
            cryptoImpl));

    Enumeration keysEnum = cryptoProperties.keys();
    while (keysEnum.hasMoreElements()) {
        String key = (String) keysEnum.nextElement();
        OMElement prop = fac.createOMElement(new QName("property"), cryptoElem);
        prop.addAttribute(fac.createOMAttribute("name", null, key));
        prop.setText(cryptoProperties.getProperty(key));
    }

    if (!(keyComputation == AbstractIssuerConfig.KeyComputation.KEY_COMP_PROVIDE_ENT ||
            keyComputation == AbstractIssuerConfig.KeyComputation.KEY_COMP_USE_OWN_KEY ||
            keyComputation == AbstractIssuerConfig.KeyComputation.KEY_COMP_USE_REQ_ENT)) {

        keyComputation = AbstractIssuerConfig.KeyComputation.KEY_COMP_USE_OWN_KEY;
    }

    OMElement keyCompElem = fac.createOMElement(
            AbstractIssuerConfig.KeyComputation.KEY_COMPUTATION, elem);
    keyCompElem.setText(Integer.toString(keyComputation));

    if (proofKeyType == null || "".equals(proofKeyType)) {
        proofKeyType = TokenIssuerUtil.BINARY_SECRET;
    } else if (!(TokenIssuerUtil.BINARY_SECRET.equals(proofKeyType)) ||
            TokenIssuerUtil.ENCRYPTED_KEY.equals(proofKeyType)) {
        throw new Exception("Invalid proof token type configuration : " + proofKeyType);
    }

    OMElement proofKeyTypeElem = fac.createOMElement(AbstractIssuerConfig.PROOF_KEY_TYPE, elem);
    proofKeyTypeElem.setText(proofKeyType);

    if (addRequestedAttachedRef) {
        fac.createOMElement(AbstractIssuerConfig.ADD_REQUESTED_ATTACHED_REF, elem);
    }

    if (addRequestedUnattachedRef) {
        fac.createOMElement(AbstractIssuerConfig.ADD_REQUESTED_UNATTACHED_REF, elem);
    }

    Parameter param = new Parameter();
    param.setName(SCTIssuerConfig.SCT_ISSUER_CONFIG.getLocalPart());
    param.setParameterType(Parameter.OM_PARAMETER);
    param.setValue(paramElem);
    param.setParameterElement(paramElem);
    return param;
}
 
Example 16
Source File: WSS4JUtil.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public static Parameter getClientUsernameTokenHandler(String password) {
    Parameter param = new Parameter();
    param.setName(WSHandlerConstants.PW_CALLBACK_REF);
    param.setValue(new ClientUserPasswordCallbackHandler(password));
    return param;
}