org.apache.axiom.util.UIDGenerator Java Examples

The following examples show how to use org.apache.axiom.util.UIDGenerator. 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: JMSTestsUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Create a empty message context.
 *
 * @return A context with empty message
 * @throws AxisFault on an error creating a context
 */
public static org.apache.synapse.MessageContext createMessageContext() throws AxisFault {

    Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
    org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
    axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));

    ServiceContext svcCtx = new ServiceContext();
    OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
    axis2MC.setServiceContext(svcCtx);
    axis2MC.setOperationContext(opCtx);
    org.apache.synapse.MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(),
                                                                   synapseEnvironment);
    mc.setMessageID(UIDGenerator.generateURNString());
    SOAPEnvelope env = OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope();
    OMNamespace namespace = OMAbstractFactory.getSOAP11Factory()
            .createOMNamespace("http://ws.apache.org/commons/ns/payload", "text");
    env.declareNamespace(namespace);
    mc.setEnvelope(env);
    SOAPBody body = OMAbstractFactory.getSOAP11Factory().createSOAPBody();
    OMElement element = OMAbstractFactory.getSOAP11Factory().createOMElement("TestElement", namespace);
    element.setText("This is a test!!");
    body.addChild(element);
    mc.getEnvelope().addChild(body);
    return mc;
}
 
Example #2
Source File: ErrorResponseBuilder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static String generateErrorneousResponse() {
    Response response = new ResponseBuilder().buildObject();
    response.setIssuer(getIssuer());
    response.setStatus(buildStatus());
    response.setVersion(SAMLVersion.VERSION_20);
    response.setID(UIDGenerator.generateUID());

    try {
        return encode(marshall(response));
    } catch (IdentityException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while encoding.", e);
        }
        return null;
    }
}
 
Example #3
Source File: LDAPRealmConfigBuilder.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This will clone the bootstrap realm config and creates a tenant specific realm.
 * Here the user search base of the particular tenant is changes to the tenant specific user
 * store.
 *
 * @param bootStrapConfig
 * @param tenantInfo
 * @param tenantId
 * @return
 * @throws UserStoreException
 */
public RealmConfiguration getRealmConfigForTenantToPersist(RealmConfiguration
                                                                   bootStrapConfig, TenantMgtConfiguration tenantMgtConfiguration, Tenant tenantInfo,
                                                           int tenantId)
        throws UserStoreException {
    RealmConfiguration ldapRealmConfig = null;
    try {
        ldapRealmConfig = bootStrapConfig.cloneRealmConfiguration();
        //TODO: Random password generation. 
        ldapRealmConfig.setAdminPassword(UIDGenerator.generateUID());
        ldapRealmConfig.setAdminUserName(tenantInfo.getAdminName());
        ldapRealmConfig.setTenantId(tenantId);

        Map<String, String> authz = ldapRealmConfig.getAuthzProperties();
        authz.put(UserCoreConstants.RealmConfig.PROPERTY_ADMINROLE_AUTHORIZATION,
                UserCoreConstants.UI_ADMIN_PERMISSION_COLLECTION);

        Map<String, String> userStoreProperties = ldapRealmConfig.getUserStoreProperties();

        //If the domain is wso2.com, partition dn is composed as dc=wso2,dc=com as follows:
        String partitionDN = "dc=" + tenantInfo.getDomain().split("\\.")[0] + ",dc=" +
                tenantInfo.getDomain().split("\\.")[1];
        /*according to carbon/components/apacheds-server, users are stored under "ou=Users"
        context. So that is hard coded as the default in userSearchBase.*/
        String userSearchBase = "ou=Users," + partitionDN;
        //replace the tenant specific user search base.
        userStoreProperties.put(LDAPConstants.USER_SEARCH_BASE, userSearchBase);

        return ldapRealmConfig;

    } catch (Exception e) {
        String errorMessage = "Tenant specific realm config could not be created.";
        if (log.isDebugEnabled()) {
            log.debug(errorMessage, e);
        }
        throw new UserStoreException(errorMessage, e);
    }

}
 
Example #4
Source File: CacheMediatorTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create Synapse Context.
 *
 * @return mc created message context.
 * @throws AxisFault when exception happens on message context creation.
 */
private MessageContext createSynapseMessageContext() throws AxisFault {
    org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
    axis2MC.setConfigurationContext(this.configContext);
    ServiceContext svcCtx = new ServiceContext();
    OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
    axis2MC.setServiceContext(svcCtx);
    axis2MC.setOperationContext(opCtx);
    Axis2MessageContext mc = new Axis2MessageContext(axis2MC, this.synapseConfig, null);
    mc.setMessageID(UIDGenerator.generateURNString());
    mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
    mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody());

    return mc;
}
 
Example #5
Source File: InboundWebsocketSourceHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static org.apache.axis2.context.MessageContext createAxis2MessageContext() {
    org.apache.axis2.context.MessageContext axis2MsgCtx = new org.apache.axis2.context.MessageContext();
    axis2MsgCtx.setMessageID(UIDGenerator.generateURNString());
    axis2MsgCtx.setConfigurationContext(
            ServiceReferenceHolder.getInstance().getConfigurationContextService().getServerConfigContext());
    axis2MsgCtx.setProperty(org.apache.axis2.context.MessageContext.CLIENT_API_NON_BLOCKING, Boolean.TRUE);
    axis2MsgCtx.setServerSide(true);

    return axis2MsgCtx;
}
 
Example #6
Source File: WebSocketClientHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static org.apache.axis2.context.MessageContext createAxis2MessageContext() {
    org.apache.axis2.context.MessageContext axis2MsgCtx = new org.apache.axis2.context.MessageContext();
    axis2MsgCtx.setMessageID(UIDGenerator.generateURNString());
    axis2MsgCtx.setConfigurationContext(
            ServiceReferenceHolder.getInstance().getAxis2ConfigurationContextService().getServerConfigContext());
    axis2MsgCtx.setProperty(org.apache.axis2.context.MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
    axis2MsgCtx.setServerSide(true);
    return axis2MsgCtx;
}
 
Example #7
Source File: MessageSender.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private String getServiceID(Config config, AxisService service) throws Exception {

        String uniqueID = config.getUniqueId();
        if (uniqueID == null) {
            // Get the unique id from the registry.
            // Use the service to get hold of the Carbon context of the tenant
            // to which the service belongs
            Registry registry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
                    getRegistry(RegistryType.SYSTEM_CONFIGURATION);
            uniqueID = DiscoveryMgtUtils.getExistingServiceIdOrUpdate(getNameForService(service),
                    UIDGenerator.generateURNString(), registry);
        }
        return uniqueID;
    }
 
Example #8
Source File: CarbonEventBroker.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String subscribe(Subscription subscription)
        throws EventBrokerException {

    //if there is a subscription with the same topic and event sink url then
    //we think it is the same subscription.
    Subscription existingSubscription = getExistingNonExpiredSubscription(subscription);
    if (existingSubscription != null) {
        return existingSubscription.getId();
    }
    if (EventBrokerHolder.getInstance().getTenantDomain() != null) {
        subscription.setTenantDomain(EventBrokerHolder.getInstance().getTenantDomain());
        subscription.setTenantId(EventBrokerHolder.getInstance().getTenantId());
    }
    // generates an id for the subscription
    subscription.setId(UIDGenerator.generateUID());
    this.topicManager.addTopic(subscription.getTopicName());
    this.deliveryManager.subscribe(subscription);

    if (subscription.getEventDispatcherName() != null) {
        // we persists a subscription only if it has a event dispatcher
        // name. the subscriptions with only an event dispatcher is not persisted.
        this.subscriptionManager.addSubscription(subscription);
    } else {
        if (subscription.getEventDispatcher() == null) {
            throw new EventBrokerException(" subscription url, event " +
                                           "dispatcher name and event dispatcher is null");
        }
    }
    return subscription.getId();
}
 
Example #9
Source File: WebsocketInboundHandler.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Checks if the request is throttled
 *
 * @param ctx ChannelHandlerContext
 * @return false if throttled
 * @throws APIManagementException
 */
public boolean doThrottle(ChannelHandlerContext ctx, WebSocketFrame msg) {

    String applicationLevelTier = infoDTO.getApplicationTier();
    String apiLevelTier = infoDTO.getApiTier();
    String subscriptionLevelTier = infoDTO.getTier();
    String resourceLevelTier = apiLevelTier;
    String authorizedUser;
    if (MultitenantConstants.SUPER_TENANT_DOMAIN_NAME
            .equalsIgnoreCase(infoDTO.getSubscriberTenantDomain())) {
        authorizedUser = infoDTO.getSubscriber() + "@" + infoDTO.getSubscriberTenantDomain();
    } else {
        authorizedUser = infoDTO.getSubscriber();
    }
    String apiName = infoDTO.getApiName();
    String apiContext = apiContextUri;
    String apiVersion = version;
    String appTenant = infoDTO.getSubscriberTenantDomain();
    String apiTenant = tenantDomain;
    String appId = infoDTO.getApplicationId();
    String applicationLevelThrottleKey = appId + ":" + authorizedUser;
    String apiLevelThrottleKey = apiContext + ":" + apiVersion;
    String resourceLevelThrottleKey = apiLevelThrottleKey;
    String subscriptionLevelThrottleKey = appId + ":" + apiContext + ":" + apiVersion;
    String messageId = UIDGenerator.generateURNString();
    String remoteIP = getRemoteIP(ctx);
    if (log.isDebugEnabled()) {
        log.debug("Remote IP address : " + remoteIP);
    }
    if (remoteIP.indexOf(":") > 0) {
        remoteIP = remoteIP.substring(1, remoteIP.indexOf(":"));
    }
    JSONObject jsonObMap = new JSONObject();
    if (remoteIP != null && remoteIP.length() > 0) {
        try {
            InetAddress address = APIUtil.getAddress(remoteIP);
            if (address instanceof Inet4Address) {
                jsonObMap.put(APIThrottleConstants.IP, APIUtil.ipToLong(remoteIP));
            } else if (address instanceof Inet6Address) {
                jsonObMap.put(APIThrottleConstants.IPv6, APIUtil.ipToBigInteger(remoteIP));
            }
        } catch (UnknownHostException e) {
            //ignore the error and log it
            log.error("Error while parsing host IP " + remoteIP, e);
        }
    }
    jsonObMap.put(APIThrottleConstants.MESSAGE_SIZE, msg.content().capacity());
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext()
                .setTenantDomain(tenantDomain, true);
        boolean isThrottled = WebsocketUtil
                .isThrottled(resourceLevelThrottleKey, subscriptionLevelThrottleKey,
                        applicationLevelThrottleKey);
        if (isThrottled) {
            if (APIUtil.isAnalyticsEnabled()) {
                publishThrottleEvent();
            }
            return false;
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
    Object[] objects =
            new Object[]{messageId, applicationLevelThrottleKey, applicationLevelTier,
                    apiLevelThrottleKey, apiLevelTier, subscriptionLevelThrottleKey,
                    subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier,
                    authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId,
                    apiName, jsonObMap.toString()};
    org.wso2.carbon.databridge.commons.Event event =
            new org.wso2.carbon.databridge.commons.Event(
                    "org.wso2.throttle.request.stream:1.0.0", System.currentTimeMillis(), null,
                    null, objects);
    ServiceReferenceHolder.getInstance().getThrottleDataPublisher().getDataPublisher().tryPublish(event);
    return true;
}
 
Example #10
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 3 votes vote down vote up
private static org.apache.axis2.context.MessageContext createAxis2MessageContext() {

        org.apache.axis2.context.MessageContext axis2MsgCtx = new org.apache.axis2.context.MessageContext();
        axis2MsgCtx.setMessageID(UIDGenerator.generateURNString());

        axis2MsgCtx.setConfigurationContext(
                ServiceReferenceHolder.getInstance().getConfigurationContextService().getServerConfigContext());

        // Axis2 spawns a new threads to send a message if this is TRUE
        axis2MsgCtx.setProperty(org.apache.axis2.context.MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);

        axis2MsgCtx.setServerSide(true);

        return axis2MsgCtx;
    }