org.apache.axis2.description.TransportOutDescription Java Examples

The following examples show how to use org.apache.axis2.description.TransportOutDescription. 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: 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 #2
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 #3
Source File: WebsocketConnectionFactory.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public WebsocketConnectionFactory(TransportOutDescription transportOut) throws AxisFault {
    this.transportOut = transportOut;
    boolean sslEnabled = WebsocketConstants.WSS.equalsIgnoreCase(transportOut.getName());
    if (sslEnabled) {
        Parameter trustParam = transportOut.getParameter(WebsocketConstants.TRUST_STORE_CONFIG_ELEMENT);
        if (trustParam != null) {
            OMElement trustStoreLocationElem = trustParam.getParameterElement().
                    getFirstChildWithName(new QName(WebsocketConstants.TRUST_STORE_LOCATION));
            OMElement trustStorePasswordElem = trustParam.getParameterElement().
                    getFirstChildWithName(new QName(WebsocketConstants.
                                                            TRUST_STORE_PASSWORD));

            if (trustStoreLocationElem == null || trustStorePasswordElem == null) {
                handleWssTrustStoreParameterError(
                        "Unable to read parameter(s) " + WebsocketConstants.TRUST_STORE_LOCATION + " and/or "
                                + WebsocketConstants.TRUST_STORE_PASSWORD + " from Transport configurations");
            }
        } else {
            handleWssTrustStoreParameterError(
                    "Unable to read parameter(s) " + WebsocketConstants.TRUST_STORE_LOCATION + " and/or "
                            + WebsocketConstants.TRUST_STORE_PASSWORD + " from Transport configurations");
        }
    }
}
 
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: 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 #6
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 #7
Source File: WebsocketTransportSender.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("Initializing WS Connection Factory.");
    }
    super.init(cfgCtx, transportOut);
    connectionFactory = new WebsocketConnectionFactory(transportOut);
}
 
Example #8
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
* Builds a TransportOutDescription object based on the specified XML configuration.
   * The XML should be as follows.
   *
   * <transportSender name="myTransport" class="my.transport.sender.Class">
   *     <parameter name="param1">value 1</parameter>
   *     <parameter name="param1">value 1</parameter>
   * </transportSender>
*
* @param transport An Iterator of OMElement which contains transport configurations.
   * @param init Whether to initialize the sender or not
* @return an array of transport out descriptions
* @throws DeploymentException on error
*/
  public static TransportOutDescription processTransportSender(
          OMElement transport, boolean init) throws DeploymentException {

      if (!TAG_TRANSPORT_SENDER.equals(transport.getLocalName())) {
          throw new DeploymentException("Invalid top level element in the transport sender " +
                  "configuration");
      }

      String name = transport.getAttributeValue(new QName(ATTRIBUTE_NAME));
      if (name == null || "".equals(name)) {
          throw new DeploymentException("Transport name is not specified in the receiver " +
                  "configuration");
      }

      String className = transport.getAttributeValue(new QName(ATTRIBUTE_CLASS));
      if (className == null || "".equals(className)) {
          throw new DeploymentException("Class name is not specified in the receiver " +
                  "configuration");
      }

      TransportOutDescription transportOut = new TransportOutDescription(name);
      if (init) {
          try {
              Class clazz = TransportBuilderUtils.class.getClassLoader().loadClass(className);
              TransportSender sender = (TransportSender) clazz.newInstance();
              transportOut.setSender(sender);
          } catch (Exception e) {
              throw new DeploymentException("Error while initializing transport sender", e);
          }
      }

      Iterator itr = transport.getChildrenWithName(new QName(TAG_PARAMETER));
      processParameters(itr, transportOut);
      return transportOut;
  }
 
Example #9
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static OMElement serializeTransportSender(TransportOutDescription transport) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement transportReceiver = fac.createOMElement(new QName(TAG_TRANSPORT_SENDER));
    transportReceiver.addAttribute(ATTRIBUTE_NAME, transport.getName(), null);
    transportReceiver.addAttribute(ATTRIBUTE_CLASS, transport.getSender().
            getClass().getName(), null);

    serializeParameters(transport, transportReceiver, fac);
    return transportReceiver;
}
 
Example #10
Source File: CarbonRemoteUserStoreManger.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param realmConfig
 * @param properties
 * @throws Exception
 */
public CarbonRemoteUserStoreManger(RealmConfiguration realmConfig, Map properties)
        throws Exception {

    ConfigurationContext configurationContext = ConfigurationContextFactory
            .createDefaultConfigurationContext();

    Map<String, TransportOutDescription> transportsOut = configurationContext
            .getAxisConfiguration().getTransportsOut();
    for (TransportOutDescription transportOutDescription : transportsOut.values()) {
        transportOutDescription.getSender().init(configurationContext, transportOutDescription);
    }

    String[] serverUrls = realmConfig.getUserStoreProperty(SERVER_URLS).split(",");

    for (int i = 0; i < serverUrls.length; i++) {
        remoteUserStore = new WSUserStoreManager(
                realmConfig.getUserStoreProperty(REMOTE_USER_NAME),
                realmConfig.getUserStoreProperty(PASSWORD), serverUrls[i],
                configurationContext);

        if (log.isDebugEnabled()) {
            log.debug("Remote Servers for User Management : " + serverUrls[i]);
        }

        remoteServers.put(serverUrls[i], remoteUserStore);
    }

    this.realmConfig = realmConfig;
    domainName = realmConfig.getUserStoreProperty(UserStoreConfigConstants.DOMAIN_NAME);
}