added resources to target
This commit is contained in:
parent
d218e82385
commit
4ec7f88f0a
42
.classpath
42
.classpath
|
@ -1,23 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
@ -29,5 +11,29 @@
|
|||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v3.0.1-SNAPSHOT] - [2024-02-02]
|
||||
|
||||
- authorization endpoints configuration retrieving moved from common scanner to reflection library
|
||||
|
||||
|
||||
## [v3.0.0] - [2022-06-06]
|
||||
|
|
22
pom.xml
22
pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<name>authorization service common library</name>
|
||||
<parent>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
|
@ -21,24 +21,23 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-configuration-scanner</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
|
@ -53,4 +52,13 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package org.gcube.common.authorization.library.endpoints;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.common.scan.ClasspathScanner;
|
||||
import org.gcube.common.scan.ClasspathScannerFactory;
|
||||
import org.gcube.common.scan.matchers.NameMatcher;
|
||||
import org.gcube.common.scan.resources.ClasspathResource;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.ResourcesScanner;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -38,17 +38,22 @@ public class AuthorizationEndpointScanner {
|
|||
|
||||
try {
|
||||
|
||||
ConfigurationBuilder reflectionConf = new ConfigurationBuilder().addUrls(ClasspathHelper.forJavaClassPath()).addClassLoader(AuthorizationEndpointScanner.class.getClassLoader()).setScanners(new ResourcesScanner());
|
||||
|
||||
Reflections reflection = new Reflections(reflectionConf);
|
||||
|
||||
Set<String> resources = reflection.getResources((String input)-> input.endsWith(".authorization"));
|
||||
log.info("loading resources {} ", resources);
|
||||
|
||||
JAXBContext context = JAXBContext.newInstance(AuthorizationEndpoint.class);
|
||||
Unmarshaller um = context.createUnmarshaller();
|
||||
|
||||
String defaultInfrastructure = null;
|
||||
int defaultInfraPriority= Integer.MAX_VALUE;
|
||||
|
||||
for (String r :getEnpointResourceNames()){
|
||||
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(r);
|
||||
|
||||
|
||||
for (String resource: resources) {
|
||||
log.info("loading {} ", resource);
|
||||
URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
|
||||
AuthorizationEndpoint endpoint = (AuthorizationEndpoint)um.unmarshal(url);
|
||||
if (defaultInfrastructure==null)
|
||||
defaultInfrastructure = endpoint.getInfrastructure();
|
||||
|
@ -56,7 +61,7 @@ public class AuthorizationEndpointScanner {
|
|||
|
||||
if (!endpointsMap.containsKey(endpoint.getInfrastructure())
|
||||
|| endpointsMap.get(endpoint.getInfrastructure()).getPriority()> endpoint.getPriority()){
|
||||
if (r.startsWith("default") && endpoint.getPriority()<defaultInfraPriority ){
|
||||
if (resource.startsWith("default") && endpoint.getPriority()<defaultInfraPriority ){
|
||||
defaultInfrastructure = endpoint.getInfrastructure();
|
||||
defaultInfraPriority = endpoint.getPriority();
|
||||
}
|
||||
|
@ -64,27 +69,22 @@ public class AuthorizationEndpointScanner {
|
|||
}
|
||||
|
||||
log.info("loaded endpoint {} ",endpoint.toString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (endpointsMap.size()==0)
|
||||
throw new Exception("no endpoints retreived");
|
||||
endpoints = new EndpointsContainer(endpointsMap, defaultInfrastructure);
|
||||
log.trace("authorization endpoint retrieving finished");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("could not load authorization endpoints", e);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error("errror scanning auth endpoints",e);
|
||||
throw new RuntimeException("could not load auth endpoints", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
private static Set<String> getEnpointResourceNames() {
|
||||
|
||||
ClasspathScanner scanner = ClasspathScannerFactory.scanner();
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (ClasspathResource r : scanner.scan(new NameMatcher(configurationPattern)))
|
||||
names.add(r.name());
|
||||
return names;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue