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.
- Loading branch information
1 parent
b4ff427
commit 4bfb20c
Showing
12 changed files
with
240 additions
and
8 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
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
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
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
33 changes: 33 additions & 0 deletions
33
eventmesh-security-plugin/eventmesh-security-auth-token/build.gradle
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,33 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
|
||
def jwtVersion = '0.11.1' | ||
|
||
dependencies { | ||
|
||
implementation project(":eventmesh-common") | ||
implementation "io.jsonwebtoken:jjwt-api:${jwtVersion}" | ||
implementation "io.jsonwebtoken:jjwt-impl:${jwtVersion}" | ||
implementation "io.jsonwebtoken:jjwt-jackson:${jwtVersion}" | ||
|
||
implementation project(":eventmesh-security-plugin:eventmesh-security-api") | ||
|
||
testImplementation project(":eventmesh-security-plugin:eventmesh-security-api") | ||
|
||
|
||
} |
18 changes: 18 additions & 0 deletions
18
eventmesh-security-plugin/eventmesh-security-auth-token/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-token |
43 changes: 43 additions & 0 deletions
43
...y-auth-token/src/main/java/org/apache/eventmesh/auth/token/impl/AuthTokenServiceImpl.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,43 @@ | ||
package org.apache.eventmesh.auth.token.impl; | ||
|
||
import org.apache.eventmesh.api.acl.AclProperties; | ||
import org.apache.eventmesh.api.acl.AclService; | ||
import org.apache.eventmesh.api.exception.AclException; | ||
import org.apache.eventmesh.auth.token.impl.auth.AuthTokenUtils; | ||
|
||
public class AuthTokenServiceImpl implements AclService { | ||
|
||
@Override | ||
public void init() throws AclException { | ||
} | ||
|
||
@Override | ||
public void start() throws AclException { | ||
|
||
} | ||
|
||
@Override | ||
public void shutdown() throws AclException { | ||
|
||
} | ||
|
||
@Override | ||
public void doAclCheckInConnect(AclProperties aclProperties) throws AclException { | ||
AuthTokenUtils.authTokenByPublicKey(aclProperties); | ||
} | ||
|
||
@Override | ||
public void doAclCheckInHeartbeat(AclProperties aclProperties) throws AclException { | ||
|
||
} | ||
|
||
@Override | ||
public void doAclCheckInSend(AclProperties aclProperties) throws AclException { | ||
AuthTokenUtils.authTokenByPublicKey(aclProperties); | ||
} | ||
|
||
@Override | ||
public void doAclCheckInReceive(AclProperties aclProperties) throws AclException { | ||
AuthTokenUtils.authTokenByPublicKey(aclProperties); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ty-auth-token/src/main/java/org/apache/eventmesh/auth/token/impl/auth/AuthTokenUtils.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,62 @@ | ||
package org.apache.eventmesh.auth.token.impl.auth; | ||
|
||
import org.apache.eventmesh.api.acl.AclProperties; | ||
import org.apache.eventmesh.api.exception.AclException; | ||
import org.apache.eventmesh.common.config.CommonConfiguration; | ||
import org.apache.eventmesh.common.utils.ConfigurationContextUtil; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.security.Key; | ||
import java.security.KeyFactory; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.spec.InvalidKeySpecException; | ||
import java.security.spec.X509EncodedKeySpec; | ||
|
||
import io.jsonwebtoken.JwtException; | ||
import io.jsonwebtoken.JwtParser; | ||
import io.jsonwebtoken.Jwts; | ||
|
||
public class AuthTokenUtils { | ||
|
||
public static void authTokenByPublicKey(AclProperties aclProperties) { | ||
String publicKeyUrl = ""; | ||
for (String key : ConfigurationContextUtil.KEYS) { | ||
CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key); | ||
if (null == commonConfiguration) { | ||
continue; | ||
} | ||
if (StringUtils.isBlank(commonConfiguration.getEventMeshSecurityPublickey())) { | ||
|
||
throw new AclException("publicKeyUrl cannot be null"); | ||
|
||
} | ||
publicKeyUrl = commonConfiguration.getEventMeshSecurityPublickey(); | ||
} | ||
String token = aclProperties.getToken(); | ||
if (StringUtils.isNotBlank(token)) { | ||
token = token.replace("Bearer ", ""); | ||
byte[] validationKeyBytes = new byte[0]; | ||
try { | ||
validationKeyBytes = Files.readAllBytes(Paths.get(publicKeyUrl)); | ||
X509EncodedKeySpec spec = new X509EncodedKeySpec(validationKeyBytes); | ||
KeyFactory kf = KeyFactory.getInstance("RSA"); | ||
Key validationKey = kf.generatePublic(spec); | ||
JwtParser signedParser = Jwts.parserBuilder().setSigningKey(validationKey).build(); | ||
signedParser.parseClaimsJws(token); | ||
} catch (IOException e) { | ||
throw new AclException("public key read error!", e); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new AclException("no such RSA algorithm!", e); | ||
} catch (InvalidKeySpecException e) { | ||
throw new AclException("invalid public key spec!", e); | ||
} catch (JwtException e) { | ||
throw new AclException("invalid token!", e); | ||
} | ||
} | ||
} | ||
|
||
} |
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