Java Code Examples for org.apache.axis2.transport.http.HttpTransportProperties#Authenticator

The following examples show how to use org.apache.axis2.transport.http.HttpTransportProperties#Authenticator . 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: WSUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public WSUserStoreManager(String userName, String password, String serverUrl,
                          ConfigurationContext configCtxt) throws UserStoreException {
    try {

        if (serverUrl != null && !serverUrl.endsWith("/")) {
            serverUrl += "/";
        }

        stub = new RemoteUserStoreManagerServiceStub(configCtxt, serverUrl
                + SERVICE_NAME);

        HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator();
        authenticator.setUsername(userName);
        authenticator.setPassword(password);
        authenticator.setPreemptiveAuthentication(true);

        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
                authenticator);
    } catch (AxisFault e) {
        handleException(e.getMessage(), e);
    }
}
 
Example 2
Source File: WorkflowDeployerClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public WorkflowDeployerClient(String bpsURL, String username, char[] password) throws AxisFault {
    bpelUploaderStub = new BPELUploaderStub(bpsURL + BPEL_UPLOADER_SERVICE);
    ServiceClient serviceClient = bpelUploaderStub._getServiceClient();
    Options options = serviceClient.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(username);
    auth.setPassword(new String(password));
    auth.setPreemptiveAuthentication(true);
    List<String> authSchemes = new ArrayList<>();
    authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
    auth.setAuthSchemes(authSchemes);
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    serviceClient.setOptions(options);

    humanTaskUploaderStub = new HumanTaskUploaderStub(bpsURL + HT_UPLOADER_SERVICE);
    ServiceClient htServiceClient = humanTaskUploaderStub._getServiceClient();
    Options htOptions = htServiceClient.getOptions();
    htOptions.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    htServiceClient.setOptions(htOptions);
}
 
Example 3
Source File: ServiceAuthenticator.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void authenticate(ServiceClient client) throws AuthenticationException {

        if (accessUsername != null && accessPassword != null) {
            Options option = client.getOptions();
            HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
            auth.setUsername(accessUsername);
            auth.setPassword(accessPassword);
            auth.setPreemptiveAuthentication(true);
            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
            option.setManageSession(true);

        } else {
            throw new AuthenticationException("Authentication username or password not set");
        }
    }
 
Example 4
Source File: WSXACMLEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public WSXACMLEntitlementServiceClient(String serverUrl, String userName, String password) {
    this.serverUrl = serverUrl;
    authenticator = new HttpTransportProperties.Authenticator();
    authenticator.setUsername(userName);
    authenticator.setPassword(password);
    authenticator.setPreemptiveAuthentication(true);
}
 
Example 5
Source File: SubscriptionUpdateWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);
    return client;
}
 
Example 6
Source File: SubscriptionCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);

    return client;
}
 
Example 7
Source File: UserSignUpWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);

    return client;
}
 
Example 8
Source File: ApplicationRegistrationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);

    return client;
}
 
Example 9
Source File: ApplicationCreationWSWorkflowExecutor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves configured ServiceClient for communication with external services
 *
 * @param action web service action to use
 * @return configured service client
 * @throws AxisFault
 */
public ServiceClient getClient(String action) throws AxisFault {
    ServiceClient client = new ServiceClient(
            ServiceReferenceHolder.getInstance().getContextService().getClientConfigContext(), null);
    Options options = new Options();
    options.setAction(action);
    options.setTo(new EndpointReference(serviceEndpoint));

    if (contentType != null) {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, contentType);
    } else {
        options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
    }

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();

    // Assumes authentication is required if username and password is given
    if (username != null && !username.isEmpty() && password != null && password.length != 0) {
        auth.setUsername(username);
        auth.setPassword(String.valueOf(password));
        auth.setPreemptiveAuthentication(true);
        List<String> authSchemes = new ArrayList<String>();
        authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
        auth.setAuthSchemes(authSchemes);

        if (contentType == null) {
            options.setProperty(Constants.Configuration.MESSAGE_TYPE, HTTPConstants.MEDIA_TYPE_TEXT_XML);
        }
        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
        options.setManageSession(true);
    }
    client.setOptions(options);

    return client;
}
 
Example 10
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 11
Source File: WSXACMLEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public WSXACMLEntitlementServiceClient(String serverUrl, String userName, String password) {
    this.serverUrl = serverUrl;
    authenticator = new HttpTransportProperties.Authenticator();
    authenticator.setUsername(userName);
    authenticator.setPassword(password);
    authenticator.setPreemptiveAuthentication(true);
}
 
Example 12
Source File: ProcessManagementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public ProcessManagementServiceClient(String bpsURL, String username, char[] password) throws AxisFault {
    stub = new ProcessManagementServiceStub(bpsURL + WFImplConstant.BPS_PROCESS_SERVICES_URL);
    ServiceClient serviceClient = stub._getServiceClient();
    Options options = serviceClient.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(username);
    auth.setPassword(new String(password));
    auth.setPreemptiveAuthentication(true);
    List<String> authSchemes = new ArrayList<>();
    authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
    auth.setAuthSchemes(authSchemes);
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    serviceClient.setOptions(options);
}
 
Example 13
Source File: HumanTaskClientAPIAdminClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public HumanTaskClientAPIAdminClient(String bpsURL, String username, char[] password) throws AxisFault {
    stub = new HumanTaskClientAPIAdminStub(bpsURL + WFImplConstant.HT_SERVICES_URL);
    ServiceClient serviceClient = stub._getServiceClient();
    Options options = serviceClient.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(username);
    auth.setPassword(new String(password));
    auth.setPreemptiveAuthentication(true);
    List<String> authSchemes = new ArrayList<>();
    authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
    auth.setAuthSchemes(authSchemes);
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    serviceClient.setOptions(options);
}
 
Example 14
Source File: BPELPackageManagementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public BPELPackageManagementServiceClient(String bpsURL, String username, char[] password) throws AxisFault {
    stub = new BPELPackageManagementServiceStub(bpsURL + WFImplConstant.BPS_PACKAGE_SERVICES_URL);
    ServiceClient serviceClient = stub._getServiceClient();
    Options options = serviceClient.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(username);
    auth.setPassword(new String(password));
    auth.setPreemptiveAuthentication(true);
    List<String> authSchemes = new ArrayList<>();
    authSchemes.add(HttpTransportProperties.Authenticator.BASIC);
    auth.setAuthSchemes(authSchemes);
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    serviceClient.setOptions(options);
}
 
Example 15
Source File: RemoteTaskManagerFactory.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private static RemoteTaskAdmin getRemoteTaskAdmin() throws TaskException {
    if (remoteTaskAdmin == null) {
        synchronized (RemoteTaskManagerFactory.class) {
            if (remoteTaskAdmin == null) {
                TaskServiceConfiguration serverConfig = TasksDSComponent.getTaskService()
                        .getServerConfiguration();
                String username = serverConfig.getRemoteServerUsername();
                String password = serverConfig.getRemoteServerPassword();
                String taskServerAddress = serverConfig.getRemoteServerAddress();
                try {
                    remoteTaskAdmin = new RemoteTaskAdminStub(taskServerAddress
                            + "/services/RemoteTaskAdmin");
                } catch (AxisFault e) {
                    throw new TaskException(e.getMessage(), Code.UNKNOWN, e);
                }
                HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
                auth.setUsername(username);
                auth.setPassword(password);
                auth.setPreemptiveAuthentication(true);
                remoteTaskAdmin
                        ._getServiceClient()
                        .getOptions()
                        .setProperty(
                                org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
                                auth);
                remoteTaskAdmin._getServiceClient().getOptions().setCallTransportCleanup(true);
            }
        }
    }
    return remoteTaskAdmin;
}
 
Example 16
Source File: BssClient.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Ugly hack which only works due to the fact that the session server
 * doesn't verifiy the user's organization role
 * 
 * @param stub
 */
private void setBasicAuth(Stub stub) {
    HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
    basicAuth.setUsername(userKey);
    basicAuth.setPassword(password);
    basicAuth.setPreemptiveAuthentication(true);
    final Options clientOptions = stub._getServiceClient().getOptions();
    clientOptions.setProperty(HTTPConstants.AUTHENTICATE, basicAuth);
}
 
Example 17
Source File: ServiceAuthenticator.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public void authenticate(ServiceClient client) throws ApplicationManagementException {
    Options option = client.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(username);
    auth.setPassword(password);
    auth.setPreemptiveAuthentication(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    option.setManageSession(true);
}
 
Example 18
Source File: IdentityManagementServiceUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
static void setAutheticationOptions(ServiceClient client, String accessUsername, String accessPassword) {
    Options option = client.getOptions();
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
    auth.setUsername(accessUsername);
    auth.setPassword(accessPassword);
    auth.setPreemptiveAuthentication(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth);
    option.setManageSession(true);
}
 
Example 19
Source File: EntitlementServiceStubFactory.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
public EntitlementServiceStubFactory(ConfigurationContext configurationContext,
                                     String targetEndpoint, HttpTransportProperties.Authenticator authenticator) {
    this.configurationContext = configurationContext;
    this.targetEndpoint = targetEndpoint;
    this.authenticator = authenticator;
}
 
Example 20
Source File: EntitlementServiceStubFactory.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public EntitlementServiceStubFactory(ConfigurationContext configurationContext, String targetEndpoint,
                                     HttpTransportProperties.Authenticator authenticator) {
    this.configurationContext = configurationContext;
    this.targetEndpoint = targetEndpoint;
    this.authenticator = authenticator;
}