コード例 #1
0
 protected void printHelp(CommandContext ctx) {
   InputStream helpInput =
       SecurityActions.getClassLoader(CommandHandlerWithHelp.class).getResourceAsStream(filename);
   if (helpInput != null) {
     BufferedReader reader = new BufferedReader(new InputStreamReader(helpInput));
     try {
       String helpLine = reader.readLine();
       while (helpLine != null) {
         ctx.printLine(helpLine);
         helpLine = reader.readLine();
       }
     } catch (java.io.IOException e) {
       ctx.printLine("Failed to read help/help.txt: " + e.getLocalizedMessage());
     } finally {
       StreamUtils.safeClose(reader);
     }
   } else {
     ctx.printLine("Failed to locate command description " + filename);
   }
   return;
 }
コード例 #2
0
 protected static OptionMap getOptions(ModelNode properties) {
   final OptionMap optionMap;
   if (properties.isDefined() && properties.asInt() > 0) {
     OptionMap.Builder builder = OptionMap.builder();
     final ClassLoader loader = SecurityActions.getClassLoader(ConnectorResource.class);
     for (Property property : properties.asPropertyList()) {
       String name = property.getName();
       if (!name.contains(".")) {
         name = "org.xnio.Options." + name;
       }
       final Option option = Option.fromString(name, loader);
       builder.set(
           option,
           option.parseValue(property.getValue().get(CommonAttributes.VALUE).asString(), loader));
     }
     optionMap = builder.getMap();
   } else {
     optionMap = OptionMap.EMPTY;
   }
   return optionMap;
 }
コード例 #3
0
  protected static jline.ConsoleReader initConsoleReader() {

    final String bindingsName;
    final String osName = SecurityActions.getSystemProperty("os.name").toLowerCase();
    if (osName.indexOf("windows") >= 0) {
      bindingsName = "keybindings/jline-windows-bindings.properties";
    } else if (osName.startsWith("mac")) {
      bindingsName = "keybindings/jline-mac-bindings.properties";
    } else {
      bindingsName = "keybindings/jline-default-bindings.properties";
    }

    ClassLoader cl = SecurityActions.getClassLoader(CommandLineMain.class);
    InputStream bindingsIs = cl.getResourceAsStream(bindingsName);
    if (bindingsIs == null) {
      System.err.println("Failed to locate key bindings for OS '" + osName + "': " + bindingsName);
      try {
        return new jline.ConsoleReader();
      } catch (IOException e) {
        throw new IllegalStateException("Failed to initialize console reader", e);
      }
    } else {
      try {
        final InputStream in = new FileInputStream(FileDescriptor.in);
        String encoding =
            SecurityActions.getSystemProperty("jline.WindowsTerminal.output.encoding");
        if (encoding == null) {
          encoding = SecurityActions.getSystemProperty("file.encoding");
        }
        final Writer out = new PrintWriter(new OutputStreamWriter(System.out, encoding));
        return new jline.ConsoleReader(in, out, bindingsIs);
      } catch (Exception e) {
        throw new IllegalStateException("Failed to initialize console reader", e);
      } finally {
        StreamUtils.safeClose(bindingsIs);
      }
    }
  }
コード例 #4
0
    @SuppressWarnings("rawtypes")
    public JBWSTokenClient(STSClientConfig config, Map<String, ? super Object> options) {
      super(config);

      try {
        this.dataTypefactory = DatatypeFactory.newInstance();
      } catch (DatatypeConfigurationException dce) {
        throw logger.wsTrustUnableToGetDataTypeFactory(dce);
      }

      requestType = (String) options.get(STSClientConfig.REQUEST_TYPE);
      if (requestType == null) {
        requestType = config.getRequestType();
      }

      String soapBinding = (String) options.get(STSClientConfig.SOAP_BINDING);
      if (soapBinding != null) {
        setSoapBinding(soapBinding);
      }

      // Get pre-constructed Dispatch from super
      Dispatch<Source> dispatch = super.getDispatch();

      String overrideDispatchStr = (String) options.get("overrideDispatch");
      if (StringUtil.isNotNull(overrideDispatchStr)) {
        boolean bool = Boolean.valueOf(overrideDispatchStr);
        if (bool) {
          dispatch = new PicketLinkDispatch(dispatch, (String) options.get("endpointAddress"));
          String useWSSE = (String) options.get("useWSSE");
          if (StringUtil.isNotNull(useWSSE) && useWSSE.equalsIgnoreCase("true")) {
            ((PicketLinkDispatch) dispatch).setUseWSSE(true);
          }
        }
      }

      Binding binding = dispatch.getBinding();

      List<Handler> handlers = binding.getHandlerChain();

      String handlerStr = (String) options.get("handlerChain");

      if (StringUtil.isNotNull(handlerStr)) {
        List<String> tokens = StringUtil.tokenize(handlerStr);
        for (String token : tokens) {
          if (token.equalsIgnoreCase("binary")) {
            BinaryTokenHandler binaryTokenHandler = new BinaryTokenHandler();
            handlers.add(binaryTokenHandler);
          } else if (token.equalsIgnoreCase("saml2")) {
            SAML2Handler samlHandler = new SAML2Handler();
            handlers.add(samlHandler);
          } else if (token.equalsIgnoreCase("map")) {
            MapBasedTokenHandler mapBasedHandler = new MapBasedTokenHandler(options);
            handlers.add(mapBasedHandler);
          } else {
            ClassLoader cl = SecurityActions.getClassLoader(getClass());
            try {
              handlers.add((Handler) cl.loadClass(token).newInstance());
            } catch (Exception e) {
              throw logger.authUnableToInstantiateHandler(token, e);
            }
          }
        }
      }

      binding.setHandlerChain(handlers);

      setDispatch(dispatch);

      String securityDomainForFactory = (String) options.get("securityDomainForFactory");
      if (StringUtil.isNotNull(securityDomainForFactory)) {
        logger.trace("We got security domain for domain ssl factory = " + securityDomainForFactory);
        logger.trace("Setting it on the system property org.jboss.security.ssl.domain.name");

        String sslFactoryName = "org.jboss.security.ssl.JaasSecurityDomainSocketFactory";
        SecurityActions.setSystemProperty(
            "org.jboss.security.ssl.domain.name", securityDomainForFactory);
        // StubExt.PROPERTY_SOCKET_FACTORY
        dispatch.getRequestContext().put("org.jboss.ws.socketFactory", sslFactoryName);

        // If we are using PL Dispatch. Then we need to set the SSL Socket Factory
        if (dispatch instanceof PicketLinkDispatch) {
          ClassLoader cl = SecurityActions.getClassLoader(getClass());
          SSLSocketFactory socketFactory = null;
          if (cl != null) {
            try {
              Class<?> clazz = cl.loadClass(sslFactoryName);
              socketFactory = (SSLSocketFactory) clazz.newInstance();
            } catch (Exception e) {
              cl = SecurityActions.getContextClassLoader();
              try {
                Class<?> clazz = cl.loadClass(sslFactoryName);
                socketFactory = (SSLSocketFactory) clazz.newInstance();
              } catch (Exception e1) {
                throw logger.jbossWSUnableToCreateSSLSocketFactory(e1);
              }
            } finally {
              if (socketFactory != null) {
                ((PicketLinkDispatch) dispatch).setSSLSocketFactory(socketFactory);
              } else throw logger.jbossWSUnableToFindSSLSocketFactory();
            }
          } else {
            logger.trace(
                "Classloader is null. Unable to set the SSLSocketFactory on PicketLinkDispatch");
          }
        }
      }
    }