Skip to content

Commit

Permalink
feat(jans-config-api): converting fido2 endpoint to plugin (#1304)
Browse files Browse the repository at this point in the history
* feat(jans-config-api): rectified scope for user fetch request

* feat(jans-config-api): converting fido2 endpoint to plugin issue#1224

* feat(jans-config-api): converting fido2 endpoint to plugin issue#1224

* feat(jans-config-api): converting fido2 endpoint to plugin issue#1224

* feat(jans-config-api): converting fido2 endpoint to plugin issue#1224

Co-authored-by: Mustafa Baser <mbaser@mail.com>
  • Loading branch information
pujavs and devrimyatar authored May 10, 2022
1 parent d016682 commit 88c3fff
Show file tree
Hide file tree
Showing 36 changed files with 722 additions and 84 deletions.
8 changes: 4 additions & 4 deletions jans-config-api/docs/jans-config-api-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tags:
- name: Cache Configuration – in-Memory
- name: Cache Configuration – Native-Persistence
- name: Configuration – Properties
- name: Configuration – Fido2
- name: Fido2 - Configuration
- name: Configuration – SMTP
- name: Configuration – Logging
- name: Configuration – JWK - JSON Web Key (JWK)
Expand Down Expand Up @@ -117,13 +117,13 @@ paths:
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
/jans-config-api/api/v1/fido2/config:
/jans-config-api/fido2/config:
get:
summary: Gets Jans Authorization Server Fido2 configuration properties.
description: Gets Jans Authorization Server Fido2 configuration properties.
operationId: get-properties-fido2
tags:
- Configuration – Fido2
- Fido2 - Configuration
responses:
'200':
description: OK
Expand All @@ -142,7 +142,7 @@ paths:
description: Updates Fido2 configuration properties.
operationId: put-properties-fido2
tags:
- Configuration – Fido2
- Fido2 - Configuration
requestBody:
content:
application/json:
Expand Down
222 changes: 222 additions & 0 deletions jans-config-api/plugins/fido2-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>plugins</artifactId>
<groupId>io.jans.jans-config-api.plugins</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>io.jans.jans-config-api.plugins</groupId>
<artifactId>fido2-plugin</artifactId>
<properties>
<httpcore.version>4.4.14</httpcore.version>
<httpclient.version>4.5.13</httpclient.version>
<jans.version>1.0.0-SNAPSHOT</jans.version>
</properties>

<dependencies>

<!-- config api -->
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-config-api-shared</artifactId>
<version>${jans.version}</version>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-config-api-server</artifactId>
<version>${jans.version}</version>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-orm-annotation</artifactId>
<version>${jans.version}</version>
</dependency>


<!-- Microprofile -->
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-config</artifactId>
<version>1.5.0</version>
</dependency>

<!-- Others -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>${httpcore.version}</version>
</dependency>

<!-- CDI -->
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>


<!-- Testing -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<scope>test</scope>
</dependency>

</dependencies>


<build>
<filters>
<filter>../../profiles/${cfg}/config-build.properties</filter>
<filter>../../profiles/${cfg}/config-api-test.properties</filter>
</filters>

<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>karate.properties</include>
<include>karate_jenkins.properties</include>
<include>test.properties</include>
<include>*.*</include>
</includes>
</testResource>
</testResources>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.json</include>
<include>META-INF/services/*.*</include>
</includes>
</resource>
</resources>


<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
</systemPropertyVariables>
<excludedGroups>integration</excludedGroups>
<systemProperties>
<karate.options>--tags ~@ignore</karate.options>
</systemProperties>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<failIfNoTests>false</failIfNoTests>
<excludedGroups>!integration</excludedGroups>
<groups>integration</groups>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>deploy-to-local-folder</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../target/plugins</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<include>*-distribution.jar</include>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd">

<id>distribution</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.jans.configapi.plugin.fido2.extensions;

import jakarta.enterprise.inject.spi.Extension;

public class Fido2Extension implements Extension {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.jans.configapi.plugin.fido2.model.config;

import io.jans.exception.ConfigurationException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import jakarta.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ApplicationScoped
public class Fido2ConfigSource implements ConfigSource {

private static Logger log = LoggerFactory.getLogger(Fido2ConfigSource.class);
private static final String FILE_CONFIG = "fido2.properties";
private Properties properties = null;
Map<String, String> propertiesMap = new HashMap<>();

public Fido2ConfigSource() {
this.loadProperties();
}

@Override
public Map<String, String> getProperties() {
log.debug("Getting properties");
return propertiesMap;
}

@Override
public Set<String> getPropertyNames() {
log.debug("Getting Property Names");
try {
return properties.stringPropertyNames();

} catch (Exception e) {
log.error("Unable to read properties from file: " + FILE_CONFIG, e);
}
return Collections.emptySet();
}

@Override
public int getOrdinal() {
return 800;
}

@Override
public String getValue(String name) {
log.debug("Fido2ConfigSource()::getValue() - name:{}", name);
try {
return properties.getProperty(name);
} catch (Exception e) {
log.error("Unable to read properties from file: " + FILE_CONFIG, e);
}

return null;
}

@Override
public String getName() {
return FILE_CONFIG;
}

private Properties loadProperties() {
// Load the properties file
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try ( InputStream inputStream = loader.getResourceAsStream(FILE_CONFIG)) {
properties = new Properties();
properties.load(inputStream);
properties.stringPropertyNames().stream().forEach(key -> propertiesMap.put(key, properties.getProperty(key)));
return properties;
} catch (Exception e) {
throw new ConfigurationException("Failed to load configuration from "+ FILE_CONFIG, e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.jans.configapi.plugin.fido2.rest;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;

@ApplicationPath("/fido2")
public class ApiApplication extends Application {

@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> classes = new HashSet<>();

classes.add(Fido2ConfigResource.class);

return classes;
}
}
Loading

0 comments on commit 88c3fff

Please sign in to comment.