forked from apache/eventmesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue apache#658] create auth-http-basic security module
- Loading branch information
1 parent
a5d818f
commit 0d1f76e
Showing
17 changed files
with
259 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...tmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/HttpAuthWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.apache.eventmesh.runtime.core.plugin; | ||
|
||
import org.apache.eventmesh.api.auth.AuthService; | ||
import org.apache.eventmesh.spi.EventMeshExtensionFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class HttpAuthWrapper { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(HttpAuthWrapper.class); | ||
|
||
private static Map<String, AuthService> authServices = new ConcurrentHashMap<>(); | ||
|
||
public static AuthService getHttpAuthPlugin(String pluginType) { | ||
if (authServices.containsKey(pluginType)) { | ||
return authServices.get(pluginType); | ||
} | ||
|
||
AuthService authService = EventMeshExtensionFactory.getExtension(AuthService.class, pluginType); | ||
|
||
if (authService == null) { | ||
logger.error("can't load the authService plugin, please check."); | ||
throw new RuntimeException("doesn't load the authService plugin, please check."); | ||
} | ||
try { | ||
authService.init(); | ||
authServices.put(pluginType, authService); | ||
return authService; | ||
} catch (Exception e) { | ||
logger.error("Error in initializing authService", e); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/urlauth/AuthProvider.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/urlauth/AuthType.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...mesh-security-api/src/main/java/org/apache/eventmesh/api/common/ConfigurationWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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.eventmesh.api.common; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Properties; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ConfigurationWrapper { | ||
|
||
private static Logger logger = LoggerFactory.getLogger("ConfigurationWrapper"); | ||
|
||
private static final String EVENTMESH_CONFIG_HOME = System.getProperty("confPath", System.getenv("confPath")); | ||
|
||
public static Properties getConfig(String configFile) { | ||
String configFilePath; | ||
|
||
// get from classpath | ||
URL resource = ConfigurationWrapper.class.getClassLoader().getResource(configFile); | ||
if (resource != null && new File(resource.getPath()).exists()) { | ||
configFilePath = resource.getPath(); | ||
} else { | ||
// get from config home | ||
configFilePath = EVENTMESH_CONFIG_HOME + File.separator + configFile; | ||
} | ||
|
||
logger.info("loading auth config: {}", configFilePath); | ||
Properties properties = new Properties(); | ||
try { | ||
properties.load(new BufferedReader(new FileReader(configFilePath))); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException( | ||
String.format("Cannot load RocketMQ configuration file from :%s", configFilePath)); | ||
} | ||
return properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
eventmesh-security-plugin/eventmesh-security-auth-http-basic/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 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. | ||
# | ||
|
||
pluginType=security | ||
pluginName=auth-http-basic |
24 changes: 24 additions & 0 deletions
24
...uth-http-basic/src/main/java/org/apache/eventmesh/auth/http/basic/config/AuthConfigs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.apache.eventmesh.auth.http.basic.config; | ||
|
||
import org.apache.eventmesh.api.common.ConfigurationWrapper; | ||
|
||
import java.util.Properties; | ||
|
||
public class AuthConfigs { | ||
|
||
public String username; | ||
|
||
public String password; | ||
|
||
private static AuthConfigs instance; | ||
|
||
public static synchronized AuthConfigs getConfigs() { | ||
if (instance == null) { | ||
Properties props = ConfigurationWrapper.getConfig("auth-http-basic.properties"); | ||
instance = new AuthConfigs(); | ||
instance.username = props.getProperty("auth.username"); | ||
instance.password = props.getProperty("auth.password"); | ||
} | ||
return instance; | ||
} | ||
} |
Oops, something went wrong.