org.apache.axis2.context.ConfigurationContextFactory Java Examples

The following examples show how to use org.apache.axis2.context.ConfigurationContextFactory. 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: AxisOperationClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public AxisOperationClient() {

        String repositoryPath =
                System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator
                        + "axis2Server" + File.separator + "repository";
        File repository = new File(repositoryPath);
        log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());

        try {
            cfgCtx = ConfigurationContextFactory
                    .createConfigurationContextFromFileSystem(repository.getCanonicalPath(), null);
            serviceClient = new ServiceClient(cfgCtx, null);
            log.info("Sample clients initialized successfully...");
        } catch (Exception e) {
            log.error("Error while initializing the Operational Client", e);
        }
    }
 
Example #2
Source File: CarbonBasicPolicyPublisherModule.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public void init(PublisherDataHolder propertyHolder) throws EntitlementException {

    PublisherPropertyDTO[] propertyDTOs = propertyHolder.getPropertyDTOs();
    for (PublisherPropertyDTO dto : propertyDTOs) {
        if ("subscriberURL".equals(dto.getId())) {
            serverUrl = dto.getValue();
        } else if ("subscriberUserName".equals(dto.getId())) {
            serverUserName = dto.getValue();
        } else if ("subscriberPassword".equals(dto.getId())) {
            serverPassword = dto.getValue();
        }
    }

    try {
        configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    } catch (AxisFault axisFault) {
        log.error("Error while initializing module", axisFault);
        throw new EntitlementException("Error while initializing module", axisFault);
    }
}
 
Example #3
Source File: EntitlementCacheUpdateServlet.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ServletConfig config) throws EntitlementCacheUpdateServletException {

    EntitlementCacheUpdateServletDataHolder.getInstance().setServletConfig(config);
    try {
        EntitlementCacheUpdateServletDataHolder.getInstance().setConfigCtx(ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(null, null));
    } catch (AxisFault e) {
        log.error("Error while initializing Configuration Context", e);
        throw new EntitlementCacheUpdateServletException("Error while initializing Configuration Context", e);

    }

    EntitlementCacheUpdateServletDataHolder.getInstance().setHttpsPort(config.getInitParameter(EntitlementConstants.HTTPS_PORT));
    EntitlementCacheUpdateServletDataHolder.getInstance().setAuthentication(config.getInitParameter(EntitlementConstants.AUTHENTICATION));
    EntitlementCacheUpdateServletDataHolder.getInstance().setRemoteServiceUrl(config.getServletContext().getInitParameter(EntitlementConstants.REMOTE_SERVICE_URL));
    EntitlementCacheUpdateServletDataHolder.getInstance().setRemoteServiceUserName(config.getServletContext().getInitParameter(EntitlementConstants.USERNAME));
    EntitlementCacheUpdateServletDataHolder.getInstance().setRemoteServicePassword(config.getServletContext().getInitParameter(EntitlementConstants.PASSWORD));
    EntitlementCacheUpdateServletDataHolder.getInstance().setAuthenticationPage(config.getInitParameter(EntitlementConstants.AUTHENTICATION_PAGE));
    EntitlementCacheUpdateServletDataHolder.getInstance().setAuthenticationPageURL(config.getInitParameter(EntitlementConstants.AUTHENTICATION_PAGE_URL));


}
 
Example #4
Source File: Authenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private boolean authenticate() throws Exception {
    ConfigurationContext configurationContext;
    configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
    Map<String, TransportOutDescription> transportsOut =configurationContext
            .getAxisConfiguration().getTransportsOut();
    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        transportOutDescription.getSender().init(configurationContext, transportOutDescription);
    }
    AuthenticationAdminStub authAdmin = new AuthenticationAdminStub(configurationContext,
            serverUrl);
    boolean isAuthenticated = authAdmin.login(userName, password, "localhost");
    cookie = (String) authAdmin._getServiceClient().getServiceContext()
            .getProperty(HTTPConstants.COOKIE_STRING);
    authAdmin._getServiceClient().cleanupTransport();
    return isAuthenticated;

}
 
Example #5
Source File: SecureSample.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	String epr = "https://" + HOST_IP + ":" + HOST_HTTPS_PORT + "/services/samples/SecureDataService";
	System.setProperty("javax.net.ssl.trustStore", (new File(CLIENT_JKS_PATH)).getAbsolutePath());
	ConfigurationContext ctx = ConfigurationContextFactory
			.createConfigurationContextFromFileSystem(null, null);
               SecureDataServiceStub stub = new SecureDataServiceStub(ctx, epr);
	ServiceClient client = stub._getServiceClient();
	Options options = client.getOptions();
	client.engageModule("rampart");		
	options.setUserName("admin");
	options.setPassword("admin");

	options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(SECURITY_POLICY_PATH));
	Office[] offices = stub.showAllOffices();
	for (Office office : offices) {
		System.out.println("\t-----------------------------");
		System.out.println("\tOffice Code: " + office.getOfficeCode());
		System.out.println("\tPhone: " + office.getPhone());
		System.out.println("\tAddress Line 1: " + office.getAddressLine1());
		System.out.println("\tAddress Line 2: " + office.getAddressLine2());
		System.out.println("\tCity: " + office.getCity());			
		System.out.println("\tState: " + office.getState());
		System.out.println("\tPostal Code: " + office.getPostalCode());
		System.out.println("\tCountry: " + office.getCountry());
	}
}
 
Example #6
Source File: BasicAuthEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void initConfigurationContext() throws Exception {
    HttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);

    File configFile = new File(DEFAULT_AXIS2_XML);

    if (!configFile.exists()) {
        configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
        configurationContext.setProperty(HTTPConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST, MAX_CONNECTIONS_PER_HOST);
    } else {
        configurationContext = ConfigurationContextFactory.
                createConfigurationContextFromFileSystem(DEFAULT_CLIENT_REPO, DEFAULT_AXIS2_XML);
    }
    configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
    configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);

    Map<String, TransportOutDescription> transportsOut =
            configurationContext.getAxisConfiguration().getTransportsOut();

    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        if (Constants.TRANSPORT_HTTP.equals(transportOutDescription.getName()) ||
                Constants.TRANSPORT_HTTPS.equals(transportOutDescription.getName())) {
            transportOutDescription.getSender().init(configurationContext, transportOutDescription);
        }
    }
}
 
Example #7
Source File: Axis2ServerManager.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public Axis2ServerManager(String axis2xmlFile) {
    repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator +
            "samples" + File.separator + "axis2Server" + File.separator + "repository";
    File repository = new File(repositoryPath);
    log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());
    try {
        File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml");
        if (!axis2xml.exists()) {
            log.error("Error while copying the test axis2.xml to the file system");
            return;
        }
        log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath());
        cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                repository.getAbsolutePath(), axis2xml.getAbsolutePath());
    } catch (Exception e) {
        log.error("Error while initializing the configuration context", e);
    }
}
 
Example #8
Source File: SampleAxis2Server.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public SampleAxis2Server(String axis2xmlFile) {
    repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator +
                     "samples" + File.separator + "axis2Server" + File.separator + "repository";
    File repository = new File(repositoryPath);
    log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());

    try {
        File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml");
        if (axis2xml == null) {
            log.error("Error while copying the test axis2.xml to the file system");
            return;
        }
        log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath());
        cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                repository.getAbsolutePath(), axis2xml.getAbsolutePath());
    } catch (Exception e) {
        log.error("Error while initializing the configuration context", e);
    }
}
 
Example #9
Source File: LoadbalanceFailoverClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public LoadbalanceFailoverClient() {
    String repositoryPath = System.getProperty(ESBTestConstant.CARBON_HOME) + File.separator + "samples" + File.separator + "axis2Client" +
            File.separator + "client_repo";

    File repository = new File(repositoryPath);
    log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());

    try {
        cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                repository.getCanonicalPath(), null);
        serviceClient = new ServiceClient(cfgCtx, null);
        log.info("Sample clients initialized successfully...");
    } catch (Exception e) {
        log.error("Error while initializing the StockQuoteClient", e);
    }
}
 
Example #10
Source File: LoadBalanceSessionFullClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private void init() throws IOException {
    String repositoryPath =
        System.getProperty(ESBTestConstant.CARBON_HOME) + File.separator + "samples" + File.separator +
        "axis2Client" + File.separator + DEFAULT_CLIENT_REPO;

    File repository = new File(repositoryPath);
    if (log.isDebugEnabled()) {
        log.debug("Axis2 repository path: " + repository.getAbsolutePath());
    }

    ConfigurationContext configurationContext =
        ConfigurationContextFactory.createConfigurationContextFromFileSystem(
            repository.getCanonicalPath(), null);
    serviceClient = new ServiceClient(configurationContext, null);
    log.info("LoadBalanceSessionFullClient initialized successfully...");
}
 
Example #11
Source File: AxisOperationClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public AxisOperationClient() {


        String repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator +
                "samples" + File.separator + "axis2Server" + File.separator + "repository";
        File repository = new File(repositoryPath);
        log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());

        try {
            cfgCtx =
                    ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository.getCanonicalPath(),
                            null);
            serviceClient = new ServiceClient(cfgCtx, null);
            log.info("Sample clients initialized successfully...");
        } catch (Exception e) {
            log.error("Error while initializing the Operational Client", e);
        }
    }
 
Example #12
Source File: RegistryCacheInvalidationClient.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Invalidates registry cache of the resource in the given path in given server
 * @param path registry path of the resource
 * @param tenantDomain
 * @param serverURL
 * @param cookie
 * @throws AxisFault
 * @throws RemoteException
 * @throws APIManagementException
 */
public void clearCache(String path, String tenantDomain, String serverURL, String cookie) 
        throws AxisFault, RemoteException, APIManagementException {
    RegistryCacheInvalidationServiceStub registryCacheServiceStub;

    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    registryCacheServiceStub = getRegistryCacheInvalidationServiceStub(serverURL, ctx);
    ServiceClient client = registryCacheServiceStub._getServiceClient();
    Options options = client.getOptions();
    options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
    options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
    options.setManageSession(true);
    options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
    
    try {
        registryCacheServiceStub.invalidateCache(path, tenantDomain);      
    } catch (RegistryCacheInvalidationServiceAPIManagementExceptionException e) {
        APIUtil.handleException(e.getMessage(), e);
    }
}
 
Example #13
Source File: CarbonBasicPolicyPublisherModule.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void init(PublisherDataHolder propertyHolder) throws EntitlementException {

    PublisherPropertyDTO[] propertyDTOs = propertyHolder.getPropertyDTOs();
    for (PublisherPropertyDTO dto : propertyDTOs) {
        if ("subscriberURL".equals(dto.getId())) {
            serverUrl = dto.getValue();
        } else if ("subscriberUserName".equals(dto.getId())) {
            serverUserName = dto.getValue();
        } else if ("subscriberPassword".equals(dto.getId())) {
            serverPassword = dto.getValue();
        }
    }

    try {
        configCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    } catch (AxisFault axisFault) {
        log.error("Error while initializing module", axisFault);
        throw new EntitlementException("Error while initializing module", axisFault);
    }
}
 
Example #14
Source File: CEPPolicyManagementServiceClient.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
public CEPPolicyManagementServiceClient() throws APIManagementException {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().
            getAPIManagerConfiguration();
    String serviceURL = config.getFirstProperty(APIConstants.CPS_SERVER_URL);
    username = config.getFirstProperty(APIConstants.CPS_SERVER_USERNAME);

    if (serviceURL == null) {
        throw new APIManagementException("Required connection details for the central policy server not provided");
    }
    try {

        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
        //Initialize the client here
    } catch (AxisFault axisFault) {
        throw new APIManagementException("Error while initializing central policy client", axisFault);
    }
}
 
Example #15
Source File: BasicAuthEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private void initConfigurationContext() throws Exception {
    HttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);

    File configFile = new File(DEFAULT_AXIS2_XML);

    if (!configFile.exists()) {
        configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
        configurationContext.setProperty(HTTPConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST, MAX_CONNECTIONS_PER_HOST);
    } else {
        configurationContext = ConfigurationContextFactory.
                createConfigurationContextFromFileSystem(DEFAULT_CLIENT_REPO, DEFAULT_AXIS2_XML);
    }
    configurationContext.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
    configurationContext.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);

    Map<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration()
            .getTransportsOut();

    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        if (Constants.TRANSPORT_HTTP.equals(transportOutDescription.getName()) || Constants.TRANSPORT_HTTPS
                .equals(transportOutDescription.getName())) {
            transportOutDescription.getSender().init(configurationContext, transportOutDescription);
        }
    }
}
 
Example #16
Source File: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public LoadbalanceFailoverClient() {
    String repositoryPath =
            System.getProperty(ESBTestConstant.CARBON_HOME) + File.separator + "samples" + File.separator
                    + "axis2Client" + File.separator + "client_repo";

    File repository = new File(repositoryPath);
    log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());

    try {
        cfgCtx = ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(repository.getCanonicalPath(), null);
        serviceClient = new ServiceClient(cfgCtx, null);
        log.info("Sample clients initialized successfully...");
    } catch (Exception e) {
        log.error("Error while initializing the StockQuoteClient", e);
    }
}
 
Example #17
Source File: SampleAxis2Server.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public SampleAxis2Server(String axis2xmlFile) {
    repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator
            + "axis2Server" + File.separator + "repository";
    File repository = new File(repositoryPath);
    log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());

    try {
        File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml");
        if (axis2xml == null) {
            log.error("Error while copying the test axis2.xml to the file system");
            return;
        }
        log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath());
        cfgCtx = ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(repository.getAbsolutePath(), axis2xml.getAbsolutePath());
    } catch (Exception e) {
        log.error("Error while initializing the configuration context", e);
    }
}
 
Example #18
Source File: SecureSample.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	String epr = "https://" + HOST_IP + ":" + HOST_HTTPS_PORT + "/services/samples/SecureDataService";
	System.setProperty("javax.net.ssl.trustStore", (new File(CLIENT_JKS_PATH)).getAbsolutePath());
	ConfigurationContext ctx = ConfigurationContextFactory
			.createConfigurationContextFromFileSystem(null, null);
               SecureDataServiceStub stub = new SecureDataServiceStub(ctx, epr);
	ServiceClient client = stub._getServiceClient();
	Options options = client.getOptions();
	client.engageModule("rampart");		
	options.setUserName("admin");
	options.setPassword("admin");

	options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(SECURITY_POLICY_PATH));
	Office[] offices = stub.showAllOffices();
	for (Office office : offices) {
		System.out.println("\t-----------------------------");
		System.out.println("\tOffice Code: " + office.getOfficeCode());
		System.out.println("\tPhone: " + office.getPhone());
		System.out.println("\tAddress Line 1: " + office.getAddressLine1());
		System.out.println("\tAddress Line 2: " + office.getAddressLine2());
		System.out.println("\tCity: " + office.getCity());			
		System.out.println("\tState: " + office.getState());
		System.out.println("\tPostal Code: " + office.getPostalCode());
		System.out.println("\tCountry: " + office.getCountry());
	}
}
 
Example #19
Source File: RestCommandLineService.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the rest client and set username and password of the user
 *
 * @param serverURL server URL
 * @param username  username
 * @param password  password
 * @throws AxisFault
 */
private void initializeRestClient(String serverURL, String username, String password) throws AxisFault {
    HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
    authenticator.setUsername(username);
    authenticator.setPassword(password);
    authenticator.setPreemptiveAuthentication(true);

    ConfigurationContext configurationContext;
    try {
        configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
    } catch (Exception e) {
        String msg = "Backend error occurred. Please contact the service admins!";
        throw new AxisFault(msg, e);
    }
    HashMap<String, TransportOutDescription> transportsOut = configurationContext
            .getAxisConfiguration().getTransportsOut();
    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        transportOutDescription.getSender().init(configurationContext, transportOutDescription);
    }

    this.restClient = new RestClient(serverURL, username, password);
}
 
Example #20
Source File: SecureSample.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String epr = "https://" + HOST_IP + ":" + HOST_HTTPS_PORT + "/services/samples/SecureDataService";
    System.setProperty("javax.net.ssl.trustStore", (new File(CLIENT_JKS_PATH)).getAbsolutePath());
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    SecureDataServiceStub stub = new SecureDataServiceStub(ctx, epr);
    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();
    client.engageModule("rampart");
    options.setUserName("admin");
    options.setPassword("admin");

    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(SECURITY_POLICY_PATH));
    Office[] offices = stub.showAllOffices();
    for (Office office : offices) {
        System.out.println("\t-----------------------------");
        System.out.println("\tOffice Code: " + office.getOfficeCode());
        System.out.println("\tPhone: " + office.getPhone());
        System.out.println("\tAddress Line 1: " + office.getAddressLine1());
        System.out.println("\tAddress Line 2: " + office.getAddressLine2());
        System.out.println("\tCity: " + office.getCity());
        System.out.println("\tState: " + office.getState());
        System.out.println("\tPostal Code: " + office.getPostalCode());
        System.out.println("\tCountry: " + office.getCountry());
    }
}
 
Example #21
Source File: TcpClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public TcpClient() {
    String repositoryPath = /*ProductConstant.getModuleClientPath()*/
            FrameworkPathUtil.getSystemResourceLocation() + File.separator + "client";

    File repository = new File(repositoryPath);
    try {
        cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository.getCanonicalPath(),
                /*ProductConstant.getResourceLocations(ProductConstant.ESB_SERVER_NAME)*/
                FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator
                        + "ESB" + File.separator + "tcp" + File.separator + "transport" + File.separator
                        + "client_axis2.xml");
        serviceClient = new ServiceClient(cfgCtx, null);
    } catch (Exception e) {
        log.error(e);
    }
}
 
Example #22
Source File: Authenticator.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private boolean authenticate() throws Exception {
    ConfigurationContext configurationContext;
    configurationContext = ConfigurationContextFactory.createDefaultConfigurationContext();
    Map<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration()
            .getTransportsOut();
    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        transportOutDescription.getSender().init(configurationContext, transportOutDescription);
    }
    boolean isAuthenticated = false;
    if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
        //if authorized cookie is not available authorize using credentials
        AuthenticationAdminStub authAdmin = new AuthenticationAdminStub(configurationContext, serverUrl);
        isAuthenticated = authAdmin.login(userName, password, "localhost");
        cookie = (String) authAdmin._getServiceClient().getServiceContext()
                .getProperty(HTTPConstants.COOKIE_STRING);
        authAdmin._getServiceClient().cleanupTransport();
    } else if (StringUtils.isNotEmpty(authorizedCookie)) {
        //when authorized cookie is available assign it to local variable
        isAuthenticated = true;
        cookie = authorizedCookie;
    }
    return isAuthenticated;

}
 
Example #23
Source File: Axis2ServerManager.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public Axis2ServerManager(String axis2xmlFile) {
    repositoryPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "samples" + File.separator
            + "axis2Server" + File.separator + "repository";
    File repository = new File(repositoryPath);
    log.info("Using the Axis2 repository path: " + repository.getAbsolutePath());
    try {
        File axis2xml = copyResourceToFileSystem(axis2xmlFile, "axis2.xml");
        if (!axis2xml.exists()) {
            log.error("Error while copying the test axis2.xml to the file system");
            return;
        }
        log.info("Loading axis2.xml from: " + axis2xml.getAbsolutePath());
        cfgCtx = ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(repository.getAbsolutePath(), axis2xml.getAbsolutePath());
    } catch (Exception e) {
        log.error("Error while initializing the configuration context", e);
    }
}
 
Example #24
Source File: RegistryProviderUtil.java    From product-es with Apache License 2.0 5 votes vote down vote up
public WSRegistryServiceClient getWSRegistry (AutomationContext automationContext)
        throws Exception {

    System.setProperty("carbon.repo.write.mode", "true");
    WSRegistryServiceClient registry = null;
    ConfigurationContext configContext;
    String axis2Repo = FrameworkPathUtil.getSystemResourceLocation() + File.separator + "client";
    String axis2Conf = FrameworkPathUtil.getSystemResourceLocation() + "axis2config" +
            File.separator + "axis2_client.xml";
    TestFrameworkUtils.setKeyStoreProperties(automationContext);
    try {
        configContext = ConfigurationContextFactory.
                createConfigurationContextFromFileSystem(axis2Repo, axis2Conf);

        configContext.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIME_OUT_VALUE);

        log.info("Group ConfigurationContext Timeout " +
                configContext.getServiceGroupContextTimeoutInterval());

        registry = new WSRegistryServiceClient(
                automationContext.getContextUrls().getBackEndUrl(),
                automationContext.getContextTenant().getContextUser().getUserName(),
                automationContext.getContextTenant().getContextUser().getPassword(), configContext);

        log.info("WS Registry Created - Login Successful");

    } catch (Exception e) {
        handleException("Failed instantiate WSRegistry client instance ", e);
    }
    return registry;
}
 
Example #25
Source File: LoadBalanceSessionFullClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void init() throws IOException {
    String repositoryPath =
            System.getProperty(ESBTestConstant.CARBON_HOME) + File.separator + "samples" + File.separator
                    + "axis2Client" + File.separator + DEFAULT_CLIENT_REPO;

    File repository = new File(repositoryPath);
    if (log.isDebugEnabled()) {
        log.debug("Axis2 repository path: " + repository.getAbsolutePath());
    }

    ConfigurationContext configurationContext = ConfigurationContextFactory
            .createConfigurationContextFromFileSystem(repository.getCanonicalPath(), null);
    serviceClient = new ServiceClient(configurationContext, null);
    log.info("LoadBalanceSessionFullClient initialized successfully...");
}
 
Example #26
Source File: HostObjectComponent.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Activate
protected void activate(ComponentContext componentContext) {
    try {
        ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(getClientRepoLocation(), getAxis2ClientXmlLocation());
        ServiceReferenceHolder.getInstance().setAxis2ConfigurationContext(ctx);
        if (log.isDebugEnabled()) {
            log.debug("HostObjectComponent activated");
        }
    } catch (AxisFault axisFault) {
        log.error("Error while initializing the API HostObject component", axisFault);
    }
}
 
Example #27
Source File: EntitlementServiceClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method will initiate entitlement service client which calls PDP
 *
 * @throws Exception whenever if failed to initiate client properly.
 */
public EntitlementServiceClient() throws Exception {
    ConfigurationContext configContext;
    try {
        String repositoryBasePath = CarbonUtils.getCarbonHome() + File.separator + "repository";
        String clientRepo = repositoryBasePath +
                File.separator + "deployment" + File.separator + "client";
        String clientAxisConf = repositoryBasePath +
                File.separator + "conf" + File.separator + "axis2" + File.separator + "axis2_client.xml";

        configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepo, clientAxisConf);
        String serviceEndPoint = EntitlementClientUtils.getServerUrl() + "EntitlementService";
        entitlementServiceStub =
                new EntitlementServiceStub(configContext, serviceEndPoint);
        ServiceClient client = entitlementServiceStub._getServiceClient();
        Options option = client.getOptions();
        option.setProperty(HTTPConstants.COOKIE_STRING, null);
        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setUsername(EntitlementClientUtils.getServerUsername());
        auth.setPassword(EntitlementClientUtils.getServerPassword());
        auth.setPreemptiveAuthentication(true);
        option.setProperty(HTTPConstants.AUTHENTICATE, auth);
        option.setManageSession(true);
    } catch (Exception e) {
        logger.error("Error while initiating entitlement service client ", e);
    }
}
 
Example #28
Source File: RemoteUserManagerClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public RemoteUserManagerClient(String cookie) throws APIManagementException {

		APIManagerConfiguration config = ServiceReferenceHolder.getInstance()
		                                                       .getAPIManagerConfigurationService()
		                                                       .getAPIManagerConfiguration();
		String serviceURL = config.getFirstProperty(APIConstants.AUTH_MANAGER_URL);
		String username = config.getFirstProperty(APIConstants.AUTH_MANAGER_USERNAME);
		String password = config.getFirstProperty(APIConstants.AUTH_MANAGER_PASSWORD);
		if (serviceURL == null || username == null || password == null) {
			throw new APIManagementException("Required connection details for authentication");
		}
		
		try {

			String clientRepo = CarbonUtils.getCarbonHome() + File.separator + "repository" +
                    File.separator + "deployment" + File.separator + "client";
			String clientAxisConf = CarbonUtils.getCarbonHome() + File.separator + "repository" +
                    File.separator + "conf" + File.separator + "axis2"+ File.separator +"axis2_client.xml";
			
			ConfigurationContext configContext = ConfigurationContextFactory. createConfigurationContextFromFileSystem(clientRepo,clientAxisConf);
			userStoreManagerStub = new RemoteUserStoreManagerServiceStub(configContext, serviceURL +
			                                                                   "RemoteUserStoreManagerService");
			ServiceClient svcClient = userStoreManagerStub._getServiceClient();
			CarbonUtils.setBasicAccessSecurityHeaders(username, password, svcClient);
			Options options = svcClient.getOptions();
			options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
			options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
			options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
			options.setCallTransportCleanup(true);
			options.setManageSession(true);		
			options.setProperty(HTTPConstants.COOKIE_STRING, cookie);	
		
		} catch (AxisFault axisFault) {
			throw new APIManagementException(
			                                 "Error while initializing the remote user store manager stub",
			                                 axisFault);
		}
	}
 
Example #29
Source File: TierCacheInvalidationClient.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void clearCache(String tenantDomain, String serverURL, String cookie) throws AxisFault, RemoteException {
    TierCacheServiceStub tierCacheServiceStub;

    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    tierCacheServiceStub = getTierCacheServiceStub(serverURL, ctx);
    ServiceClient client = tierCacheServiceStub._getServiceClient();
    Options options = client.getOptions();
    options.setTimeOutInMilliSeconds(TIMEOUT_IN_MILLIS);
    options.setProperty(HTTPConstants.SO_TIMEOUT, TIMEOUT_IN_MILLIS);
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, TIMEOUT_IN_MILLIS);
    options.setManageSession(true);
    options.setProperty(HTTPConstants.COOKIE_STRING, cookie);

    tierCacheServiceStub.invalidateCache(tenantDomain);
}
 
Example #30
Source File: StratosManagerServiceClient.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private StratosManagerServiceClient(String epr) throws AxisFault {
    MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new
            MultiThreadedHttpConnectionManager();
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    params.setDefaultMaxConnectionsPerHost(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_CONNECTIONS_PER_HOST);
    params.setMaxTotalConnections(StratosConstants.STRATOS_MANAGER_CLIENT_MAX_TOTAL_CONNECTIONS);
    multiThreadedHttpConnectionManager.setParams(params);
    HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
    ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null);
    ctx.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);

    String ccSocketTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT) == null ?
            StratosConstants.DEFAULT_CLIENT_SOCKET_TIMEOUT :
            System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_SOCKET_TIMEOUT);

    String ccConnectionTimeout = System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT)
            == null ?
            StratosConstants.DEFAULT_CLIENT_CONNECTION_TIMEOUT :
            System.getProperty(StratosConstants.STRATOS_MANAGER_CLIENT_CONNECTION_TIMEOUT);
    try {
        stub = new StratosManagerServiceStub(ctx, epr);
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, Integer.valueOf
                (ccSocketTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, Integer.valueOf
                (ccConnectionTimeout));
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE);
        stub._getServiceClient().getOptions().setProperty(Constants.Configuration.DISABLE_SOAP_ACTION, Boolean
                .TRUE);
    } catch (AxisFault axisFault) {
        String msg = "Could not initialize stratos manager service client";
        log.error(msg, axisFault);
        throw new AxisFault(msg, axisFault);
    }
}