blocking auth filter fix for demo user
diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml
index 90437df..e2a1bce 100644
--- a/dependency-reduced-pom.xml
+++ b/dependency-reduced-pom.xml
@@ -70,7 +70,7 @@
<exclude>**/*APITest.java</exclude>
</excludes>
<includes>
- <include>de.ids_mannheim.korap.**/*.java</include>
+ <include>de/ids_mannheim/korap/**/*.java</include>
</includes>
</configuration>
</plugin>
diff --git a/pom.xml b/pom.xml
index 4876e67..099aeeb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -337,7 +337,7 @@
<dependency>
<groupId>de.ids_mannheim.korap</groupId>
<artifactId>Krill</artifactId>
- <version>0.54</version>
+ <version>0.55</version>
<exclusions>
<exclusion>
<groupId>org.xerial</groupId>
diff --git a/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java b/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
index 7c24af2..2eb99bd 100644
--- a/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
+++ b/src/main/java/de/ids_mannheim/korap/config/BeanConfiguration.java
@@ -10,7 +10,6 @@
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -83,17 +82,6 @@
}
- @Deprecated
- private static void setManualBeans() {
- if (getBeans().getPolicyDbProvider() != null
- && getBeans().getEncryption() != null
- && getBeans().getResourceProvider() != null)
- de.ids_mannheim.korap.security.ac.SecurityManager
- .setProviders(getBeans().getPolicyDbProvider(),
- getBeans().getEncryption(),
- Arrays.asList(getBeans().getResourceProvider()));
- }
-
public static void loadFileContext(String filepath) {
if (!hasContext()) {
ApplicationContext context = new FileSystemXmlApplicationContext(
diff --git a/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java b/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java
index f63a023..6016025 100644
--- a/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java
+++ b/src/main/java/de/ids_mannheim/korap/config/KustvaktClassLoader.java
@@ -1,13 +1,8 @@
package de.ids_mannheim.korap.config;
-import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
-import de.ids_mannheim.korap.interfaces.db.ResourceOperationIface;
import org.reflections.Reflections;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashSet;
import java.util.Set;
/**
@@ -37,38 +32,4 @@
Class<? extends Annotation> annotation) {
return reflections.getTypesAnnotatedWith(annotation);
}
-
-
-
- @Deprecated
- public static void registerResourceClasses() {
- PersistenceClient cl = BeanConfiguration.getBeans()
- .getPersistenceClient();
- Set<ResourceOperationIface> set = new HashSet<>();
- Set<Class<? extends ResourceOperationIface>> resource_prov = loadSubTypes(
- ResourceOperationIface.class);
- for (Class<? extends ResourceOperationIface> op : resource_prov) {
- Constructor c;
- try {
- c = op.getConstructor(PersistenceClient.class);
- set.add((ResourceOperationIface) c.newInstance(cl));
- }catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
- // do nothing;
- }
- }
-
- if (BeanConfiguration.hasContext()) {
- BeanConfiguration.BeanHolderHelper helper = BeanConfiguration
- .getBeans();
- if (helper.getPolicyDbProvider() != null
- && helper.getEncryption() != null
- && helper.getResourceProvider() != null) {
-
- de.ids_mannheim.korap.security.ac.SecurityManager
- .setProviders(helper.getPolicyDbProvider(),
- helper.getEncryption(), set);
-
- }
- }
- }
}
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
index fcdca03..5cd0738 100755
--- a/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/ResourceFinder.java
@@ -41,11 +41,6 @@
throw new RuntimeException("provider not set!");
}
- @Deprecated
- public static void setProviders(PolicyHandlerIface policyHandler) {
- ResourceFinder.policydao = policyHandler;
- }
-
public static <T extends KustvaktResource> Set<T> search(String path,
boolean asParent, User user, Class<T> clazz,
Permissions.PERMISSIONS... perms) throws KustvaktException {
@@ -104,12 +99,8 @@
Set<T> resources = new HashSet<>();
if (this.containers != null) {
for (KustvaktResource.Container c : this.containers) {
- ResourceOperationIface<T> iface = SecurityManager.getHandlers()
- .get(c.getType());
- if (iface == null)
- iface = SecurityManager.getHandlers()
- .get(KustvaktResource.class);
-
+ ResourceOperationIface<T> iface = BeanConfiguration.getBeans()
+ .getResourceProvider();
try {
T resource = (T) iface
.findbyId(c.getPersistentID(), this.user);
diff --git a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
index 50d22b9..d37385d 100644
--- a/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/ac/SecurityManager.java
@@ -83,11 +83,6 @@
handlers.put(iface.getType(), iface);
}
- @Deprecated
- public static Map<Class<? extends KustvaktResource>, ResourceOperationIface> getHandlers() {
- return handlers;
- }
-
/**
* only allowed if the resource is uniquely identifiable by the name, if not, use path or id!
* Shortcut so resource values do not need to be retrieved afterwards!
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
index 680f67d..b3fbbed 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
@@ -65,7 +65,8 @@
*/
public TokenContext getTokenStatus(String token, String host,
String useragent) throws KustvaktException {
- jlog.info("getting session status of token '{}'", token);
+ jlog.info("getting session status of token type '{}'",
+ token.split(" ")[0]);
AuthenticationIface provider = getProvider(
StringUtils.getTokenType(token), null);
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java b/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
index 8004e31..34070b5 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/SessionFactory.java
@@ -133,12 +133,12 @@
* TODO: persist userdata to database when session times out!
*/
private void timeoutMaintenance() {
- jlog.debug("running session cleanup thread");
+ jlog.trace("running session cleanup thread");
Set<String> inactive = new HashSet<>();
for (Entry<String, DateTime> entry : timeCheck.entrySet()) {
if (!isUserSessionValid(entry.getKey())) {
TokenContext user = sessionsObject.get(entry.getKey());
- jlog.debug("removing user session for user {}",
+ jlog.trace("removing user session for user {}",
user.getUsername());
inactive.add(user.getUsername());
removeSession(entry.getKey());
@@ -146,7 +146,7 @@
}
// fixme: not doing anything!
if (inactive.size() > 0)
- jlog.debug("removing inactive user session for users '{}' ",
+ jlog.trace("removing inactive user session for users '{}' ",
inactive);
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java
index 70670bb..ff15fe1 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/BlockingFilter.java
@@ -19,10 +19,11 @@
@Override
public ContainerRequest filter(ContainerRequest request) {
- String authentication = request
- .getHeaderValue(ContainerRequest.AUTHORIZATION);
- if (authentication == null || authentication.isEmpty())
+ try {
+ request.getUserPrincipal();
+ }catch (UnsupportedOperationException e) {
throw KustvaktResponseHandler.throwAuthenticationException();
+ }
return request;
}
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
index e28be03..07108a1 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/DefaultFilter.java
@@ -31,9 +31,14 @@
.getHeaderValue(ContainerRequest.AUTHORIZATION);
// means that this is the public service
- if (authentication == null)
- request.setSecurityContext(
- new KorAPContext(createShorterToken(host, ua)));
+ if (authentication == null || authentication.isEmpty()) {
+ try {
+ request.getUserPrincipal();
+ }catch (UnsupportedOperationException e) {
+ request.setSecurityContext(
+ new KorAPContext(createShorterToken(host, ua)));
+ }
+ }
return request;
}
diff --git a/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java b/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
index 2b3667a..0bed7ff 100644
--- a/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
+++ b/src/test/java/de/ids_mannheim/korap/web/service/full/AuthServiceTest.java
@@ -1,6 +1,11 @@
package de.ids_mannheim.korap.web.service.full;
+import de.ids_mannheim.korap.config.BeanConfiguration;
+import de.ids_mannheim.korap.config.TestHelper;
import de.ids_mannheim.korap.web.service.FastJerseyTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
/**
* @author hanl
@@ -10,7 +15,35 @@
//todo: test basicauth via secure connection
+ @BeforeClass
+ public static void setup() {
+ BeanConfiguration.loadClasspathContext("default-config.xml");
+ FastJerseyTest.setPackages("de.ids_mannheim.korap.web.service.full",
+ "de.ids_mannheim.korap.web.filter",
+ "de.ids_mannheim.korap.web.utils");
+ TestHelper.setupAccount();
+ }
+ @AfterClass
+ public static void close() {
+ TestHelper.dropUser();
+ BeanConfiguration.closeApplication();
+ }
+
+ @Test
+ public void testKustvaktAuth() {
+
+ }
+
+ @Test
+ public void testDemoAuth() {
+
+ }
+
+ @Test
+ public void testUnauthorizedAuth() {
+
+ }