All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kaazing.gateway.server.test.config.SecurityConfiguration Maven / Gradle / Ivy

There is a newer version: 6.1.3
Show newest version
/**
 * Copyright 2007-2016, Kaazing Corporation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kaazing.gateway.server.test.config;

import java.security.KeyStore;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class SecurityConfiguration implements Configuration {

    private final SuppressibleSecurityConfiguration _configuration;

    private final List realms = new ArrayList<>();

    private Suppressible _keyStore;
    private Suppressible _keyStorePassword;
    private Suppressible _trustStorePassword;
    private Suppressible _trustStore;
    private String keyStoreFile;
    private String trustStoreFile;
    private String trustStorePasswordFile;
    private String keyStorePasswordFile;

    public SecurityConfiguration() {
        _configuration = new SuppressibleSecurityConfigurationImpl();
        _configuration.setSuppression(Suppressibles.getDefaultSuppressions());
    }

    @Override
    public void accept(ConfigurationVisitor visitor) {
        visitor.visit(this);
    }

    @Override
    public SuppressibleSecurityConfiguration getSuppressibleConfiguration() {
        return _configuration;
    }

    public List getRealms() {
        return realms;
    }

    public void setRealms(List newRealms) {
        realms.clear();
        realms.addAll(newRealms);
    }

    // keystore
    public KeyStore getKeyStore() {
        if (_keyStore == null) {
            return null;
        }
        return _keyStore.value();
    }

    public void setKeyStore(KeyStore keyStore) {
        this._keyStore = new Suppressible<>(keyStore);
    }

    // keyStore password
    public char[] getKeyStorePassword() {
        if (_keyStorePassword == null) {
            return null;
        }
        return _keyStorePassword.value();
    }

    public void setKeyStorePassword(char[] keyStorePassword) {
        this._keyStorePassword = new Suppressible<>(keyStorePassword);
    }

    // trust store
    public KeyStore getTrustStore() {
        if (_trustStore == null) {
            return null;
        }
        return _trustStore.value();
    }

    public void setTrustStore(KeyStore trustStore) {
        this._trustStore = new Suppressible<>(trustStore);
    }

    // keystore file

    /**
     * @param keyStoreFile
     * @Deprecated TODO : remove all file touch points
     */
    @Deprecated
    public void setKeyStoreFile(String keyStoreFile) {
        this.keyStoreFile = keyStoreFile;
    }

    @Deprecated
    public String getKeyStoreFile() {
        return keyStoreFile;
    }

    // truststore file
    @Deprecated
    public void setTrustStoreFile(String trustStoreFile) {
        this.trustStoreFile = trustStoreFile;
    }

    @Deprecated
    public String getTrustStoreFile() {
        return trustStoreFile;
    }

    public char[] getTrustStorePassword() {
        if (_trustStorePassword == null) {
            return null;
        }
        return _trustStorePassword.value();
    }

    public void setTrustStorePassword(char[] trustStorePassword) {

        this._trustStorePassword = new Suppressible<>(trustStorePassword);
    }

    // trust store password file
    @Deprecated
    public String getTrustStorePasswordFile() {
        return trustStorePasswordFile;
    }

    @Deprecated
    public void setTrustStorePasswordFile(String trustStorePasswordFile) {
        this.trustStorePasswordFile = trustStorePasswordFile;
    }

    // key store password file
    @Deprecated
    public String getKeyStorePasswordFile() {
        return keyStorePasswordFile;
    }

    @Deprecated
    public void setKeyStorePasswordFile(String keyStorePasswordFile) {
        this.keyStorePasswordFile = keyStorePasswordFile;
    }

    protected class SuppressibleSecurityConfigurationImpl extends SuppressibleSecurityConfiguration {
        private Set _suppressions;

        @Override
        public Set getSuppressions() {
            return _suppressions;
        }

        @Override
        public void setSuppression(Set
                                                   suppressions) {
            _suppressions = suppressions;
        }

        // keystore
        @Override
        public Suppressible getKeyStore() {
            return _keyStore;
        }

        @Override
        public void setKeyStore(Suppressible keyStore) {
            _keyStore = keyStore;
        }

        // keyStore password
        @Override
        public Suppressible getKeyStorePassword() {
            return _keyStorePassword;
        }

        @Override
        public void setKeyStorePassword(Suppressible keyStorePassword) {
            _keyStorePassword = keyStorePassword;
        }

        // trust store
        @Override
        public Suppressible getTrustStore() {
            return _trustStore;
        }

        @Override
        public void setTrustStore(Suppressible trustStore) {
            _trustStore = trustStore;
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy