org.apache.axis2.description.AxisModule Java Examples

The following examples show how to use org.apache.axis2.description.AxisModule. 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: UtilServer.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static ServiceContext createAdressedEnabledClientSide(
        AxisService service) throws AxisFault {
    File file = getAddressingMARFile();
    TestCase.assertTrue(file.exists());
    ConfigurationContext configContext = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(
                    "target/test-resources/integrationRepo", null);
    AxisModule axisModule = DeploymentEngine.buildModule(file,
                                                         configContext.getAxisConfiguration());

    AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
    axisConfiguration.addModule(axisModule);
    axisConfiguration.addService(service);
    ServiceGroupContext serviceGroupContext =
            configContext.createServiceGroupContext((AxisServiceGroup) service.getParent());
    return serviceGroupContext.getServiceContext(service);
}
 
Example #2
Source File: UtilServer.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static ServiceContext createAdressedEnabledClientSide(
        AxisService service, String clientHome) throws AxisFault {
    File file = getAddressingMARFile();
    TestCase.assertTrue(file.exists());

    ConfigurationContext configContext = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(clientHome, null);
    AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();

    AxisModule axisModule = DeploymentEngine.buildModule(file,axisConfiguration);
    axisConfiguration.addModule(axisModule);

    axisConfiguration.addService(service);
    ServiceGroupContext serviceGroupContext =
            configContext.createServiceGroupContext((AxisServiceGroup) service.getParent());
    return serviceGroupContext.getServiceContext(service);
}
 
Example #3
Source File: StatisticsServiceComponent.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
protected void unsetConfigurationContextService(ConfigurationContextService contextService) {

        AxisConfiguration axisConf = configContext.getAxisConfiguration();
        if (axisConf != null) {
            AxisModule statModule = axisConf.getModule(StatisticsConstants.STATISTISTICS_MODULE_NAME);
            if (statModule != null) {
                try {
                    axisConf.disengageModule(statModule);
                } catch (AxisFault axisFault) {
                    log.error("Failed disengage module: " + StatisticsConstants.STATISTISTICS_MODULE_NAME);
                }
            }
            this.configContext = null;
        }

    }
 
Example #4
Source File: SecurityConfigAdmin.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
protected boolean engageModules(String scenarioId, String serviceName, AxisService axisService)
        throws SecurityConfigException {

    boolean isRahasEngaged = false;
    SecurityScenario securityScenario = SecurityScenarioDatabase.get(scenarioId);
    String[] moduleNames = (String[]) securityScenario.getModules()
            .toArray(new String[securityScenario.getModules().size()]);
    // handle each module required
    try {

        for (String modName : moduleNames) {
            AxisModule module = axisService.getAxisConfiguration().getModule(modName);
            // engage at axis2
            axisService.disengageModule(module);
            axisService.engageModule(module);
            if (SecurityConstants.TRUST_MODULE.equalsIgnoreCase(modName)) {
                isRahasEngaged = true;
            }
        }
        return isRahasEngaged;

    } catch (AxisFault e) {
        log.error(e);
        throw new SecurityConfigException("Error in engaging modules", e);
    }
}
 
Example #5
Source File: UtilServer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static ConfigurationContext createClientConfigurationContext() throws AxisFault {
    File file = getAddressingMARFile();
    TestCase.assertTrue(file.exists());

    ConfigurationContext configContext =
            ConfigurationContextFactory .createConfigurationContextFromFileSystem(
                    "target/test-resources/integrationRepo",
                    "target/test-resources/integrationRepo/conf/axis2.xml");
    AxisModule axisModule = DeploymentEngine.buildModule(file,
                                                         configContext.getAxisConfiguration());
    configContext.getAxisConfiguration().addModule(axisModule);
    return configContext;
}
 
Example #6
Source File: TracerAdmin.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @param flag; support ON or OFF.
 * @return The information about the Tracer service
 * @throws AxisFault If the tracer module is not found
 */
public TracerServiceInfo setMonitoring(String flag) throws AxisFault {
    if (!flag.equalsIgnoreCase("ON") && !flag.equalsIgnoreCase("OFF")) {
        throw new RuntimeException("IllegalArgument for monitoring status. Only 'ON' and 'OFF' is allowed");
    }
    TracerServiceInfo tracerServiceInfo = new TracerServiceInfo();
    ConfigurationContext configurationContext = getConfigContext();
    AxisConfiguration axisConfiguration = configurationContext.getAxisConfiguration();
    AxisModule axisModule = axisConfiguration.getModule(TracerConstants.WSO2_TRACER);

    if (axisModule == null) {
        throw new RuntimeException(TracerAdmin.class.getName() + " " +
                                   TracerConstants.WSO2_TRACER + " is not available");
    }

    if (flag.equalsIgnoreCase("ON")) {
        if (!axisConfiguration.isEngaged(axisModule.getName())) {
            try {
                axisConfiguration.engageModule(axisModule);
            } catch (AxisFault axisFault) {
                log.error(axisFault);
                throw new RuntimeException(axisFault);
            }
        }
    } else if (flag.equalsIgnoreCase("OFF")) {
        if (axisConfiguration.isEngaged(axisModule.getName())) {
            axisConfiguration.disengageModule(axisModule);
            configurationContext.removeProperty(TracerConstants.MSG_SEQ_BUFFER);
        }
    }
    TracePersister tracePersister = getTracePersister();
    tracePersister.saveTraceStatus(flag);
    tracerServiceInfo.setEmpty(true);
    tracerServiceInfo.setFlag(flag);
    tracerServiceInfo.setTracePersister(tracePersister.getClass().getName());

    return tracerServiceInfo;
}
 
Example #7
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 #8
Source File: SecurityAxis2ConfigurationContextObserver.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
@Override
public void createdConfigurationContext(ConfigurationContext configurationContext) {
    AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
    AxisModule poxSecModule =
            axisConfig.getModule("POXSecurityModule");
    if (poxSecModule != null) {
        try {
            axisConfig.engageModule(poxSecModule);
        } catch (AxisFault e) {
            log.error("Cannot globally engage POX Security module", e);
        }
    }
}
 
Example #9
Source File: CarbonAxisConfigurator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public boolean isGlobalyEngaged(AxisModule axisModule) {
    String modName = axisModule.getName();
    for (Object globallyEngagedModule : globallyEngagedModules) {
        AxisModule module = (AxisModule) globallyEngagedModule;
        if (modName.startsWith(module.getName())) {
            return true;
        }
    }
    return false;
}
 
Example #10
Source File: SecurityDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void moduleUpdate(AxisEvent event, AxisModule module) {
    // This method will not be used
}
 
Example #11
Source File: SecurityDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
private void processPolicy (AxisService axisService, String policyId,
                            PolicyComponent currentPolicyComponent) throws UserStoreException,
        AxisFault {

    // Do not apply anything if no policy
    if(StringUtils.isNotEmpty(policyId) && NO_POLICY_ID.equalsIgnoreCase(policyId)){
        if(axisService != null){
            UserRealm userRealm = (UserRealm)PrivilegedCarbonContext.getThreadLocalCarbonContext()
                    .getUserRealm();
            String serviceGroupId = axisService.getAxisServiceGroup().getServiceGroupName();
            String serviceName = axisService.getName();
            removeAuthorization(userRealm,serviceGroupId,serviceName);
        }

        AxisModule module = axisService.getAxisConfiguration().getModule(SecurityConstants
                .RAMPART_MODULE_NAME);
        // disengage at axis2
        axisService.disengageModule(module);
        return;
    }

    if (policyId != null && isSecPolicy(policyId)) {

        if (log.isDebugEnabled()) {
            log.debug("Policy " + policyId + " is identified as a security " +
                    "policy and trying to apply security parameters");
        }

        SecurityScenario scenario = SecurityScenarioDatabase.getByWsuId(policyId);
        if (scenario == null) {
            // if there is no security scenario id,  put default id
            if (log.isDebugEnabled()) {
                log.debug("Policy " + policyId + " does not belongs to a" +
                        " pre-defined security scenario. " +
                        "So treating as a custom policy");
            }
            SecurityScenario securityScenario = new SecurityScenario();
            securityScenario.setScenarioId(
                    SecurityConstants.CUSTOM_SECURITY_SCENARIO);
            securityScenario.setWsuId(policyId);
            securityScenario.setGeneralPolicy(false);
            securityScenario.setSummary(
                    SecurityConstants.CUSTOM_SECURITY_SCENARIO_SUMMARY);
            SecurityScenarioDatabase.put(policyId, securityScenario);
            scenario = securityScenario;
        }
        applySecurityParameters(axisService, scenario,
                (Policy) currentPolicyComponent);
    }
}
 
Example #12
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 #13
Source File: STSDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void moduleUpdate(AxisEvent arg0, AxisModule arg1) {
    // Nothing to implement
}
 
Example #14
Source File: TenantSTSObserver.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) {
    // Nothing to implement
}
 
Example #15
Source File: POXSecurityModule.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void init(ConfigurationContext configContext,
                 AxisModule module) throws AxisFault {
    // Do Nothing
}
 
Example #16
Source File: IdentityMgtDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) {
    //Overridden method from parent interface, don't need any code here.
}
 
Example #17
Source File: SystemStatisticsDeploymentInterceptor.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) {
    // Nothing to implement
}
 
Example #18
Source File: STSObserver.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public void moduleUpdate(AxisEvent arg0, AxisModule arg1) {
    // Nothing to implement

}
 
Example #19
Source File: IdentityMgtDeploymentInterceptor.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) {
    //Overridden method from parent interface, don't need any code here.
}
 
Example #20
Source File: TracerAdmin.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
public TracerServiceInfo getMessages(int numberOfMessages, String filter) throws AxisFault {

        ConfigurationContext configContext = getConfigContext();
        AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
        CircularBuffer<MessageInfo> msgSeqBuff = getMessageSequenceBuffer();
        List<MessageInfo> messageObjs;
        TracerServiceInfo tracerServiceInfo = new TracerServiceInfo();
        AxisModule axisModule = axisConfiguration.getModule(TracerConstants.WSO2_TRACER);

        if (axisModule == null) {
            throw new AxisFault(TracerConstants.WSO2_TRACER + " module is not available");
        }
        TracePersister tracePersister = getTracePersister();
        tracerServiceInfo.setTracePersister(tracePersister.getClass().getName());
        if (tracePersister.isTracingEnabled()) {
            if (!axisConfiguration.isEngaged(axisModule)) {
                axisConfiguration.engageModule(axisModule);
            }
            tracerServiceInfo.setFlag("ON");
        } else {
            if (axisConfiguration.isEngaged(axisModule)) {
                axisConfiguration.disengageModule(axisModule);
            }
            tracerServiceInfo.setFlag("OFF");
        }
        if (msgSeqBuff == null) {
            tracerServiceInfo.setEmpty(true);
            return tracerServiceInfo;
        } else {
            messageObjs = msgSeqBuff.get(numberOfMessages);

            if (messageObjs.isEmpty()) {
                tracerServiceInfo.setEmpty(true);
                return tracerServiceInfo;

            } else {
                ArrayList<MessageInfo> msgInfoList = new ArrayList<MessageInfo>();
                boolean filterProvided = (filter != null && (filter = filter.trim()).length() != 0);
                tracerServiceInfo.setFilter(filterProvided);

                for (MessageInfo mi : messageObjs) {
                    if (filterProvided) {
                        MessagePayload miPayload = getMessage(mi.getServiceId(),
                                                              mi.getOperationName(),
                                                              mi.getMessageSequence());
                        String req = miPayload.getRequest();
                        if (req == null) {
                            req = "";
                        }
                        String resp = miPayload.getResponse();
                        if (resp == null) {
                            resp = "";
                        }
                        if (req.toUpperCase().contains(filter.toUpperCase())
                            || resp.toUpperCase().contains(filter.toUpperCase())) {
                            msgInfoList.add(mi);
                        }
                    } else {
                        msgInfoList.add(mi);
                    }
                }

                if (filterProvided) {
                    tracerServiceInfo.setFilterString(filter);
                    if (msgInfoList.size() == 0) {
                        tracerServiceInfo.setEmpty(true);
                        return tracerServiceInfo;
                    }
                }

                Collections.reverse(msgInfoList);
                MessageInfo lastMessageInfo = msgInfoList.get(0);
                tracerServiceInfo.setMessageInfo(
                        msgInfoList.toArray(new MessageInfo[msgInfoList.size()]));
                MessagePayload lastMsg = getMessage(lastMessageInfo.getServiceId(),
                                                    lastMessageInfo.getOperationName(),
                                                    lastMessageInfo.getMessageSequence());
                tracerServiceInfo.setLastMessage(lastMsg);
                tracerServiceInfo.setEmpty(false);
            }
        }
        return tracerServiceInfo;
    }
 
Example #21
Source File: IWADeploymentInterceptor.java    From carbon-identity with Apache License 2.0 2 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moduleUpdate(AxisEvent arg0, AxisModule arg1) {
}
 
Example #22
Source File: UrlMappingDeploymentInterceptor.java    From carbon-commons with Apache License 2.0 2 votes vote down vote up
public void moduleUpdate(AxisEvent axisEvent, AxisModule axisModule) {

    }
 
Example #23
Source File: DiscoveryModule.java    From carbon-commons with Apache License 2.0 2 votes vote down vote up
public void init(ConfigurationContext configurationContext, AxisModule axisModule) throws AxisFault {

    }