-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HWORKS-743] Move API auth to separate module and add API key authent…
…ication to hopsworks-ca (#1438) * [HWORKS-743] [HWORKS-743] Move API auth to separate module [HWORKS-743] Annotate CA endpoints [HWORKS-743] Dedicated scope for PKI [HWORKS-743] Move InvalidQueryException to hopsworks-persistence package [HWORKS-743] Bump module version [HWORKS-743] Fix license * [HWORKS-743] Fixes for CE * [HWORKS-743] Remove empty files
- Loading branch information
Showing
132 changed files
with
1,368 additions
and
1,281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<!-- | ||
~ This file is part of Hopsworks | ||
~ Copyright (C) 2023, Hopsworks AB. All rights reserved | ||
~ | ||
~ Hopsworks is free software: you can redistribute it and/or modify it under the terms of | ||
~ the GNU Affero General Public License as published by the Free Software Foundation, | ||
~ either version 3 of the License, or (at your option) any later version. | ||
~ | ||
~ Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
~ PURPOSE. See the GNU Affero General Public License for more details. | ||
~ | ||
~ You should have received a copy of the GNU Affero General Public License along with this program. | ||
~ If not, see <https://www.gnu.org/licenses/>. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>hopsworks</artifactId> | ||
<groupId>io.hops</groupId> | ||
<version>3.7.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>io.hops.hopsworks</groupId> | ||
<artifactId>hopsworks-api-auth</artifactId> | ||
<version>3.7.0-SNAPSHOT</version> | ||
<packaging>ejb</packaging> | ||
<description>Hopsworks API authentication filters</description> | ||
<name>hopsworks-api-auth</name> | ||
|
||
<properties> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.hops.hopsworks</groupId> | ||
<artifactId>hopsworks-persistence</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.hops.hopsworks</groupId> | ||
<artifactId>hopsworks-rest-utils</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.hops.hopsworks</groupId> | ||
<artifactId>hopsworks-jwt</artifactId> | ||
<type>ejb</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<version>1.16.0</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>hopsworks-api-auth</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-ejb-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
80 changes: 80 additions & 0 deletions
80
hopsworks-api-auth/src/main/java/io/hops/hopsworks/api/auth/Configuration.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,80 @@ | ||
/* | ||
* This file is part of Hopsworks | ||
* Copyright (C) 2023, Hopsworks AB. All rights reserved | ||
* | ||
* Hopsworks is free software: you can redistribute it and/or modify it under the terms of | ||
* the GNU Affero General Public License as published by the Free Software Foundation, | ||
* either version 3 of the License, or (at your option) any later version. | ||
* | ||
* Hopsworks is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License along with this program. | ||
* If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package io.hops.hopsworks.api.auth; | ||
|
||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
import io.hops.hopsworks.persistence.entity.util.Variables; | ||
import io.hops.hopsworks.restutils.RESTLogLevel; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.ejb.ConcurrencyManagement; | ||
import javax.ejb.ConcurrencyManagementType; | ||
import javax.ejb.Singleton; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Singleton | ||
@ConcurrencyManagement(ConcurrencyManagementType.BEAN) | ||
public class Configuration { | ||
|
||
@PersistenceContext(unitName = "kthfsPU") | ||
private EntityManager em; | ||
private LoadingCache<AuthConfigurationKeys, String> configuration; | ||
|
||
public enum AuthConfigurationKeys { | ||
|
||
HOPSWORKS_REST_LOG_LEVEL("hopsworks_rest_log_level", RESTLogLevel.PROD.name()); | ||
|
||
private String key; | ||
private String defaultValue; | ||
|
||
AuthConfigurationKeys(String key, String defaultValue) { | ||
this.key = key; | ||
this.defaultValue = defaultValue; | ||
} | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
configuration = CacheBuilder.newBuilder() | ||
.maximumSize(100) | ||
.expireAfterWrite(10, TimeUnit.MINUTES) | ||
.build(new CacheLoader<AuthConfigurationKeys, String>() { | ||
@Override | ||
public String load(AuthConfigurationKeys k) throws Exception { | ||
Variables var = em.find(Variables.class, k.key); | ||
return var != null ? var.getValue() : k.defaultValue; | ||
} | ||
}); | ||
} | ||
|
||
private String get(AuthConfigurationKeys key) { | ||
try { | ||
return configuration.get(key); | ||
} catch (ExecutionException ex) { | ||
return key.defaultValue; | ||
} | ||
} | ||
|
||
public RESTLogLevel getLogLevel(AuthConfigurationKeys key) { | ||
return RESTLogLevel.valueOf(get(key)); | ||
} | ||
} |
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
Oops, something went wrong.