blob: d2232443f5ae92c48bcd3ceda7c1c70ab98ef5f6 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.submarine.server.security;
import org.apache.submarine.commons.utils.SubmarineConfVars;
import org.apache.submarine.commons.utils.SubmarineConfiguration;
import org.apache.submarine.server.security.simple.SimpleSecurityProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class SecurityFactory {
private static final Logger LOG = LoggerFactory.getLogger(SecurityFactory.class);
private static final Map<String, SecurityProvider> providerMap;
public static SimpleSecurityProvider getSimpleSecurityProvider() {
return (SimpleSecurityProvider) providerMap.get("simple");
}
static {
// int provider map
providerMap = new HashMap<>();
providerMap.put("simple", new SimpleSecurityProvider());
}
public static void addProvider(String name, SecurityProvider provider) {
providerMap.put(name, provider);
}
public static Optional<SecurityProvider> getSecurityProvider() {
String authType = SubmarineConfiguration.getInstance()
.getString(SubmarineConfVars.ConfVars.SUBMARINE_AUTH_TYPE);
if (providerMap.containsKey(authType)) {
return Optional.ofNullable(providerMap.get(authType));
} else {
LOG.warn("current auth type is {} but we can not recognize, so use none!", authType);
return Optional.empty();
}
}
}