Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #174 from junkerm/develop
Browse files Browse the repository at this point in the history
version 0.1.7
  • Loading branch information
junkerm authored Jun 15, 2018
2 parents 73ef806 + 6941cf4 commit 439f0a4
Show file tree
Hide file tree
Showing 91 changed files with 4,722 additions and 692 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ public boolean canPost(Object target, EObject object) {
}

@Override
public Object get(Object target, MultivaluedMap<String, String> queryParams) throws SpecmateException {
public Object get(Object target, MultivaluedMap<String, String> queryParams, String token)
throws SpecmateException {
if (target instanceof Resource) {
return statusMap.get(getCurrentStatus().getName());
}
return null;
}

@Override
public Object post(Object target, EObject object) throws SpecmateException, SpecmateValidationException {
public Object post(Object target, EObject object, String token)
throws SpecmateException, SpecmateValidationException {
if (target instanceof Resource) {
Status status = (Status) object;
switch (status.getValue()) {
Expand Down
7 changes: 7 additions & 0 deletions bundles/specmate-auth-api/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="src" output="bin" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions bundles/specmate-auth-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/generated/
23 changes: 23 additions & 0 deletions bundles/specmate-auth-api/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>specmate-auth-api</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>bndtools.core.bndnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/bnd.bnd=UTF-8
11 changes: 11 additions & 0 deletions bundles/specmate-auth-api/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
5 changes: 5 additions & 0 deletions bundles/specmate-auth-api/bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bundle-Version: 0.0.0.${tstamp}
-buildpath: \
specmate-model-gen;version=latest,\
specmate-common;version=latest
Export-Package: com.specmate.auth.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import com.specmate.common.SpecmateException;
import com.specmate.usermodel.AccessRights;
import com.specmate.usermodel.UserSession;

public interface IAuthenticationService {
public String authenticate(String username, String password, String projectname) throws SpecmateException;
public String authenticate(String username, String password) throws SpecmateException;
public UserSession authenticate(String username, String password, String projectname) throws SpecmateException;

public UserSession authenticate(String username, String password) throws SpecmateException;

public void deauthenticate(String token) throws SpecmateException;

public void validateToken(String token, String path, boolean refresh) throws SpecmateException;

public AccessRights getSourceAccessRights(String token) throws SpecmateException;

public AccessRights getTargetAccessRights(String token) throws SpecmateException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

import com.specmate.common.SpecmateException;
import com.specmate.usermodel.AccessRights;
import com.specmate.usermodel.UserSession;

public interface ISessionService {
public String create(AccessRights alm, AccessRights ppm, String projectName) throws SpecmateException;
public String create();
public boolean isExpired(String token) throws SpecmateException ;
public UserSession create(AccessRights alm, AccessRights ppm, String projectName) throws SpecmateException;

public UserSession create();

public boolean isExpired(String token) throws SpecmateException;

public boolean isAuthorized(String token, String path) throws SpecmateException;

public void refresh(String token) throws SpecmateException;

public AccessRights getSourceAccessRights(String token) throws SpecmateException;

public AccessRights getTargetAccessRights(String token) throws SpecmateException;

public void delete(String token) throws SpecmateException;
}
11 changes: 8 additions & 3 deletions bundles/specmate-auth-test/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Test-Cases: \
-buildpath: \
org.apache.servicemix.bundles.junit,\
specmate-model-gen;version=latest,\
specmate-auth;version=latest,\
specmate-common;version=latest,\
specmate-config-api;version=latest,\
osgi.core,\
Expand All @@ -12,7 +11,12 @@ Test-Cases: \
specmate-logging-slf4j;version=latest,\
specmate-logging-slf4j-julbridge;version=latest,\
specmate-migration-api;version=latest,\
specmate-persistency-cdo;version=latest
specmate-persistency-cdo;version=latest,\
specmate-auth-api;version=latest,\
org.eclipse.emf.cdo,\
org.eclipse.emf.cdo.common,\
org.eclipse.emf.ecore,\
org.eclipse.emf.common
-runfw: org.eclipse.osgi;version='[3.10.2.v20150203-1939,3.10.2.v20150203-1939]'
-runee: JavaSE-1.8
-runproperties:\
Expand Down Expand Up @@ -123,4 +127,5 @@ Test-Cases: \
specmate-emfrest-api;version=snapshot,\
specmate-migration-api;version=snapshot,\
specmate-persistency-cdo;version=snapshot,\
specmate-connectors;version=snapshot
specmate-connectors;version=snapshot,\
specmate-auth-api;version=snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,74 @@
import com.specmate.auth.api.ISessionService;
import com.specmate.common.SpecmateException;
import com.specmate.usermodel.AccessRights;
import com.specmate.usermodel.UserSession;

public class InMemorySessionServiceTest {
private static ISessionService sessionService;
private static BundleContext context;
private String baseURL = "localhost/services/rest/";

@BeforeClass
public static void init() throws Exception {
context = FrameworkUtil.getBundle(InMemorySessionServiceTest.class).getBundleContext();
sessionService = getSessionService();
}

@Test
public void testIsAuthorized() throws SpecmateException {
String projectName = "testIsAuthorized";
String token = sessionService.create(AccessRights.ALL, AccessRights.ALL, projectName);
assertTrue(sessionService.isAuthorized(token, baseURL + projectName + "/resource1"));
assertTrue(sessionService.isAuthorized(token, baseURL + projectName + "/resource1/resource2"));
assertTrue(sessionService.isAuthorized(token, baseURL + projectName + "/"));
assertFalse(sessionService.isAuthorized(token, baseURL + projectName));
assertFalse(sessionService.isAuthorized(token, baseURL));
assertFalse(sessionService.isAuthorized(token, baseURL.substring(0, baseURL.length() - 1)));
UserSession session = sessionService.create(AccessRights.ALL, AccessRights.ALL, projectName);
assertTrue(sessionService.isAuthorized(session.getId(), baseURL + projectName + "/resource1"));
assertTrue(sessionService.isAuthorized(session.getId(), baseURL + projectName + "/resource1/resource2"));
assertTrue(sessionService.isAuthorized(session.getId(), baseURL + projectName + "/"));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + projectName));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL.substring(0, baseURL.length() - 1)));
}

@Test
public void testRegexInjection() throws SpecmateException {
String token = sessionService.create(AccessRights.ALL, AccessRights.ALL, "testRegexInjection");
assertFalse(sessionService.isAuthorized(token, baseURL + "project/resource1"));
assertFalse(sessionService.isAuthorized(token, baseURL + "project/"));
assertFalse(sessionService.isAuthorized(token, baseURL + "project"));
token = sessionService.create(AccessRights.ALL, AccessRights.ALL, "");
assertFalse(sessionService.isAuthorized(token, baseURL + "pro/resource1"));
sessionService.delete(token);
token = sessionService.create(AccessRights.ALL, AccessRights.ALL, "?");
assertFalse(sessionService.isAuthorized(token, baseURL + "p/resource1"));
sessionService.delete(token);
token = sessionService.create(AccessRights.ALL, AccessRights.ALL, ".*");
assertFalse(sessionService.isAuthorized(token, baseURL + "pr/resource1"));
sessionService.delete(token);
token = sessionService.create(AccessRights.ALL, AccessRights.ALL, ".+");
assertFalse(sessionService.isAuthorized(token, baseURL + "pro/resource1"));
UserSession session = sessionService.create(AccessRights.ALL, AccessRights.ALL, "testRegexInjection");
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "project/resource1"));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "project/"));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "project"));

session = sessionService.create(AccessRights.ALL, AccessRights.ALL, "");
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "pro/resource1"));
sessionService.delete(session.getId());

session = sessionService.create(AccessRights.ALL, AccessRights.ALL, "?");
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "p/resource1"));
sessionService.delete(session.getId());

session = sessionService.create(AccessRights.ALL, AccessRights.ALL, ".*");
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "pr/resource1"));
sessionService.delete(session.getId());

session = sessionService.create(AccessRights.ALL, AccessRights.ALL, ".+");
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "pro/resource1"));
}

@Test
public void testDeleteSession() throws SpecmateException {
boolean thrown = false;
String projectName = "testDeleteSession";
String token = sessionService.create(AccessRights.ALL, AccessRights.ALL, projectName);
assertTrue(sessionService.isAuthorized(token, baseURL + projectName + "/resource1"));
sessionService.delete(token);
UserSession session = sessionService.create(AccessRights.ALL, AccessRights.ALL, projectName);
assertTrue(sessionService.isAuthorized(session.getId(), baseURL + projectName + "/resource1"));
sessionService.delete(session.getId());
try {
assertFalse(sessionService.isAuthorized(token, baseURL + projectName + "/resource1"));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + projectName + "/resource1"));
} catch (SpecmateException e) {
thrown = true;
}

assertTrue(thrown);
}

private static ISessionService getSessionService() throws Exception {
Filter sessionFilter = context.createFilter("(impl=volatile)");
ServiceTracker<ISessionService, ISessionService> sessionTracker = new ServiceTracker<>(context,
sessionFilter, null);
ServiceTracker<ISessionService, ISessionService> sessionTracker = new ServiceTracker<>(context, sessionFilter,
null);
sessionTracker.open();
ISessionService sessionService;
try {
Expand Down
8 changes: 4 additions & 4 deletions bundles/specmate-auth/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
specmate-config-api;version=latest,\
org.apache.servicemix.bundles.junit,\
specmate-connectors;version=latest,\
specmate-model-support;version=latest
specmate-model-support;version=latest,\
specmate-auth-api;version=latest
Private-Package: \
com.specmate.auth.internal
Export-Package: \
com.specmate.auth.api,\
com.specmate.auth.config
Export-Package: com.specmate.auth.config
Bundle-Version: 0.0.0.${tstamp}
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
package com.specmate.auth.config;

import java.util.Dictionary;
import java.util.Hashtable;

import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import com.specmate.common.OSGiUtil;
import com.specmate.common.SpecmateException;
import com.specmate.common.config.SessionServiceImplementationConfig;
import com.specmate.config.api.IConfigService;

@Component(immediate = true)
public class AuthenticationServiceConfig {
public class AuthenticationServiceConfig extends SessionServiceImplementationConfig {
/** The PID of the authentication service */
public static final String PID = "com.specmate.auth.AuthenticationServiceImpl";

/** Config key for deciding whether the sessions should be persisted or not */
public static final String SESSION_PERSISTENT = "session.persistent";

/** The configuration admin instance */
private ConfigurationAdmin configurationAdmin;

/** The config service instance */
private IConfigService configService;

@Override
@Activate
public void activate() throws SpecmateException {
Dictionary<String, Object> properties = new Hashtable<>();
boolean isPersistentSession = Boolean.parseBoolean(configService.getConfigurationProperty(SESSION_PERSISTENT));

if (isPersistentSession) {
properties.put("SessionService.target", "(impl=persistent)");
} else {
properties.put("SessionService.target", "(impl=volatile)");
}

OSGiUtil.configureService(configurationAdmin, PID, properties);
configureSessionImplementation();
}

@Override
public String getPID() {
return PID;
}

/** Service reference for config admin */

@Reference
@Override
public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
this.configurationAdmin = configurationAdmin;
}

/** Service reference for config service */
@Reference
@Override
public void setConfigurationService(IConfigService configService) {
this.configService = configService;
}
Expand Down
Loading

0 comments on commit 439f0a4

Please sign in to comment.