Package org.xnio.OptionMap

Examples of org.xnio.OptionMap.Builder


    @Override
    public OptionMap getOptionMap() {
        List<String> mechanisms = new LinkedList<String>();
        Set<Property> properties = new HashSet<Property>();
        Builder builder = OptionMap.builder();

        mechanisms.add(JBOSS_LOCAL_USER);
        builder.set(SASL_POLICY_NOPLAINTEXT, false);
        properties.add(Property.of(LOCAL_DEFAULT_USER, DOLLAR_LOCAL));
        if (tokensDir != null) {
            properties.add(Property.of(LOCAL_USER_CHALLENGE_PATH, tokensDir));
        }
        if (digestMd5Supported()) {
            mechanisms.add(DIGEST_MD5);
            properties.add(Property.of(REALM_PROPERTY, realm.getName()));
            if (contains(DigestHashCallback.class, realm.getCallbackHandler().getSupportedCallbacks())) {
                properties.add(Property.of(PRE_DIGESTED_PROPERTY, Boolean.TRUE.toString()));
            }
        } else if (plainSupported()) {
            mechanisms.add(PLAIN);
        } else if (realm == null) {
            mechanisms.add(ANONYMOUS);
            builder.set(SASL_POLICY_NOANONYMOUS, false);
        } else {
            throw new IllegalStateException("A security realm has been specified but no supported mechanism identified.");
        }

        SslMode sslMode = getSslMode();
        switch (sslMode) {
            case OFF:
                builder.set(SSL_ENABLED, false);
                break;
            case TRANSPORT_ONLY:
                builder.set(SSL_ENABLED, true);
                builder.set(SSL_STARTTLS, true);
                break;
            case CLIENT_AUTH_REQUESTED:
                builder.set(SSL_ENABLED, true);
                builder.set(SSL_STARTTLS, true);
                mechanisms.add(0, EXTERNAL);
                builder.set(SSL_CLIENT_AUTH_MODE, REQUESTED);
                break;
        // We do not currently support the SSL_CLIENT_AUTH_MODE of REQUIRED as there is always
        // the possibility that the local mechanism will still be needed.
        }

        builder.set(SASL_MECHANISMS, Sequence.of(mechanisms));
        builder.set(SASL_PROPERTIES, Sequence.of(properties));

        return builder.getMap();
    }
View Full Code Here


    @Override
    public OptionMap getOptionMap() {
        List<String> mechanisms = new LinkedList<String>();
        Set<Property> properties = new HashSet<Property>();
        Builder builder = OptionMap.builder();

        mechanisms.add(JBOSS_LOCAL_USER); // If this becomes optional based on the realm config then adjust the check below.
        builder.set(SASL_POLICY_NOPLAINTEXT, false);
        properties.add(Property.of(LOCAL_DEFAULT_USER, DOLLAR_LOCAL));
        if (tokensDir != null) {
            properties.add(Property.of(LOCAL_USER_CHALLENGE_PATH, tokensDir));
        }
        if (digestMd5Supported()) {
            mechanisms.add(DIGEST_MD5);
            properties.add(Property.of(REALM_PROPERTY, realm.getName()));
            if (contains(DigestHashCallback.class, realm.getCallbackHandler().getSupportedCallbacks())) {
                properties.add(Property.of(PRE_DIGESTED_PROPERTY, Boolean.TRUE.toString()));
            }
        } else if (plainSupported()) {
            mechanisms.add(PLAIN);
        } else if (realm == null) {
            mechanisms.add(ANONYMOUS);
            builder.set(SASL_POLICY_NOANONYMOUS, false);
        }

        SslMode sslMode = getSslMode();
        switch (sslMode) {
            case OFF:
                builder.set(SSL_ENABLED, false);
                break;
            case TRANSPORT_ONLY:
                builder.set(SSL_ENABLED, true);
                builder.set(SSL_STARTTLS, true);
                break;
            case CLIENT_AUTH_REQUESTED:
                builder.set(SSL_ENABLED, true);
                builder.set(SSL_STARTTLS, true);
                mechanisms.add(0, EXTERNAL);
                builder.set(SSL_CLIENT_AUTH_MODE, REQUESTED);
                break;
        // We do not currently support the SSL_CLIENT_AUTH_MODE of REQUIRED as there is always
        // the possibility that the local mechanism will still be needed.
        }

        if (mechanisms.size() == 1) {
            throw MESSAGES.noSupportingMechanismsForRealm();
        }

        builder.set(SASL_MECHANISMS, Sequence.of(mechanisms));
        builder.set(SASL_PROPERTIES, Sequence.of(properties));

        return builder.getMap();
    }
View Full Code Here

    @Override
    protected void startListening(XnioWorker worker, InetSocketAddress socketAddress, ChannelListener<AcceptingChannel<StreamConnection>> acceptListener) throws IOException {

        SSLContext sslContext = securityRealm.getValue().getSSLContext();
        Builder builder = OptionMap.builder().addAll(commonOptions);
        builder.addAll(socketOptions);
        builder.set(Options.USE_DIRECT_BUFFERS, true);
        OptionMap combined = builder.getMap();

        XnioSsl xnioSsl = new JsseXnioSsl(worker.getXnio(), combined, sslContext);
        sslServer = xnioSsl.createSslConnectionServer(worker, socketAddress, (ChannelListener) acceptListener, combined);
        sslServer.resumeAccepts();
View Full Code Here

    @Override
    public OptionMap getOptionMap() {
        List<String> mechanisms = new LinkedList<String>();
        Set<Property> properties = new HashSet<Property>();
        Builder builder = OptionMap.builder();

        if (realm == null) {
            mechanisms.add(ANONYMOUS);
            builder.set(SASL_POLICY_NOANONYMOUS, false);
            builder.set(SSL_ENABLED, false);
        } else {
            Set<AuthenticationMechanism> authMechs = realm.getSupportedAuthenticationMechanisms();
            if (authMechs.contains(AuthenticationMechanism.LOCAL)) {
                mechanisms.add(JBOSS_LOCAL_USER);
                Map<String, String> mechConfig = realm.getMechanismConfig(AuthenticationMechanism.LOCAL);
                if (mechConfig.containsKey(LOCAL_DEFAULT_USER)) {
                    properties.add(Property.of(SASL_OPT_LOCAL_DEFAULT_USER, mechConfig.get(LOCAL_DEFAULT_USER)));
                }
                if (tokensDir != null) {
                    properties.add(Property.of(SASL_OPT_LOCAL_USER_CHALLENGE_PATH, tokensDir));
                }
            }

            if (authMechs.contains(AuthenticationMechanism.DIGEST)) {
                mechanisms.add(DIGEST_MD5);
                properties.add(Property.of(SASL_OPT_REALM_PROPERTY, realm.getName()));
                Map<String, String> mechConfig = realm.getMechanismConfig(AuthenticationMechanism.DIGEST);
                boolean plainTextDigest = true;
                if (mechConfig.containsKey(DIGEST_PLAIN_TEXT)) {
                    plainTextDigest = Boolean.parseBoolean(mechConfig.get(DIGEST_PLAIN_TEXT));
                }

                if (plainTextDigest == false) {
                    properties.add(Property.of(SASL_OPT_PRE_DIGESTED_PROPERTY, Boolean.TRUE.toString()));
                }
            }

            if (authMechs.contains(AuthenticationMechanism.PLAIN)) {
                mechanisms.add(PLAIN);
                builder.set(SASL_POLICY_NOPLAINTEXT, false);
            }

            if (realm.getSSLContext() == null) {
                builder.set(SSL_ENABLED, false);
            } else {
                if (authMechs.contains(AuthenticationMechanism.CLIENT_CERT)) {
                    builder.set(SSL_ENABLED, true);
                    builder.set(SSL_STARTTLS, true);
                    mechanisms.add(0, EXTERNAL);
                    // TODO - If no other mechanisms are available we can use REQUIRED.
                    builder.set(SSL_CLIENT_AUTH_MODE, REQUESTED);
                } else {
                    builder.set(SSL_ENABLED, true);
                    builder.set(SSL_STARTTLS, true);
                }
            }

        }

        if (mechanisms.size() == 0) {
            throw MESSAGES.noSupportingMechanismsForRealm();
        }

        builder.set(SASL_MECHANISMS, Sequence.of(mechanisms));
        builder.set(SASL_PROPERTIES, Sequence.of(properties));

        return builder.getMap();
    }
View Full Code Here

    @Override
    public OptionMap getOptionMap() {
        List<String> mechanisms = new LinkedList<String>();
        Set<Property> properties = new HashSet<Property>();
        Builder builder = OptionMap.builder();

        mechanisms.add(JBOSS_LOCAL_USER);
        builder.set(SASL_POLICY_NOPLAINTEXT, false);
        properties.add(Property.of(LOCAL_DEFAULT_USER, DOLLAR_LOCAL));
        if (tokensDir != null) {
            properties.add(Property.of(LOCAL_USER_CHALLENGE_PATH, tokensDir));
        }
        if (digestMd5Supported()) {
            mechanisms.add(DIGEST_MD5);
            properties.add(Property.of(REALM_PROPERTY, realm.getName()));
            if (contains(DigestHashCallback.class, realm.getCallbackHandler().getSupportedCallbacks())) {
                properties.add(Property.of(PRE_DIGESTED_PROPERTY, Boolean.TRUE.toString()));
            }
        } else if (plainSupported()) {
            mechanisms.add(PLAIN);
        } else if (realm == null) {
            mechanisms.add(ANONYMOUS);
            builder.set(SASL_POLICY_NOANONYMOUS, false);
        } else {
            throw MESSAGES.noSupportingMechanismsForRealm();
        }

        SslMode sslMode = getSslMode();
        switch (sslMode) {
            case OFF:
                builder.set(SSL_ENABLED, false);
                break;
            case TRANSPORT_ONLY:
                builder.set(SSL_ENABLED, true);
                builder.set(SSL_STARTTLS, true);
                break;
            case CLIENT_AUTH_REQUESTED:
                builder.set(SSL_ENABLED, true);
                builder.set(SSL_STARTTLS, true);
                mechanisms.add(0, EXTERNAL);
                builder.set(SSL_CLIENT_AUTH_MODE, REQUESTED);
                break;
        // We do not currently support the SSL_CLIENT_AUTH_MODE of REQUIRED as there is always
        // the possibility that the local mechanism will still be needed.
        }

        builder.set(SASL_MECHANISMS, Sequence.of(mechanisms));
        builder.set(SASL_PROPERTIES, Sequence.of(properties));

        return builder.getMap();
    }
View Full Code Here

    public Connection connect(CallbackHandler handler, Map<String, String> saslOptions) throws IOException {
        if (connection != null) {
            throw MESSAGES.alreadyConnected();
        }

        Builder builder = OptionMap.builder();
        builder.set(SASL_POLICY_NOANONYMOUS, Boolean.FALSE);
        builder.set(SASL_POLICY_NOPLAINTEXT, Boolean.FALSE);
        if (isLocal() == false) {
            builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of(JBOSS_LOCAL_USER));
        }
        List<Property> tempProperties = new ArrayList<Property>(saslOptions != null ? saslOptions.size() : 1);
        tempProperties.add(Property.of("jboss.sasl.local-user.quiet-auth", "true"));
        if (saslOptions != null) {
            for (String currentKey : saslOptions.keySet()) {
                tempProperties.add(Property.of(currentKey, saslOptions.get(currentKey)));
            }
        }
        builder.set(Options.SASL_PROPERTIES, Sequence.of(tempProperties));

        CallbackHandler actualHandler = handler != null ? handler : new AnonymousCallbackHandler();
        WrapperCallbackHandler wrapperHandler = new WrapperCallbackHandler(actualHandler);
        IoFuture<Connection> future = endpoint.connect(uri, builder.getMap(), wrapperHandler);
        try {
            this.connection = future.get();
        } catch (CancellationException e) {
            throw MESSAGES.connectWasCancelled();
        } catch (IOException e) {
View Full Code Here

    }

    OptionMap getSaslOptionMap() {
        List<String> mechanisms = new LinkedList<String>();
        Set<Property> properties = new HashSet<Property>();
        Builder builder = OptionMap.builder();

        mechanisms.add(JBOSS_LOCAL_USER);
        builder.set(SASL_POLICY_NOPLAINTEXT, false);
        properties.add(Property.of(LOCAL_DEFAULT_USER, DOLLAR_LOCAL));
        if (tokensDir != null) {
            properties.add(Property.of(LOCAL_USER_CHALLENGE_PATH, tokensDir));
        }
        if (digestMd5Supported()) {
            mechanisms.add(DIGEST_MD5);
            properties.add(Property.of(REALM_PROPERTY, realm.getName()));
            if (contains(DigestHashCallback.class, realm.getCallbackHandler().getSupportedCallbacks())) {
                properties.add(Property.of(PRE_DIGESTED_PROPERTY, Boolean.TRUE.toString()));
            }
        } else if (plainSupported()) {
            int i = 1;
            if (i + i == 2)
                throw new IllegalStateException("PLAIN not enabled until SSL supported for Native Interface");

            mechanisms.add(PLAIN);
        } else if (realm == null) {
            mechanisms.add(ANONYMOUS);
            builder.set(SASL_POLICY_NOANONYMOUS, false);
        } else {
            throw new IllegalStateException("A security realm has been specified but no supported mechanism identified.");
        }

        builder.set(SASL_MECHANISMS, Sequence.of(mechanisms));
        builder.set(SASL_PROPERTIES, Sequence.of(properties));

        return builder.getMap();
    }
View Full Code Here

TOP

Related Classes of org.xnio.OptionMap.Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.