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 #298 from junkerm/develop
Browse files Browse the repository at this point in the history
v.0.2.6
  • Loading branch information
junkerm authored Oct 16, 2018
2 parents 109c5ac + 7848e96 commit 65e22fa
Show file tree
Hide file tree
Showing 243 changed files with 40,809 additions and 42,868 deletions.
77,772 changes: 36,184 additions & 41,588 deletions bundles/cnf/localrepo/index.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundles/cnf/localrepo/index.xml.sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c618a3e3d022ffb786ca36b0b27aa93a3093ab723675ce07e0231bce22e9d1d2
79659d8793c884ee6d323bd0455d746ac2ff61d150aa6fc4395cbf5f24e7ab75
5 changes: 2 additions & 3 deletions bundles/cnf/releaserepo/index.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<repository increment="0" name="Release" xmlns="http://www.osgi.org/xmlns/repository/v1.0.0">
</repository>
<?xml version='1.0' encoding='UTF-8'?>
<repository xmlns="http://www.osgi.org/xmlns/repository/v1.0.0" name="Release" increment="1538979873740"/>
2 changes: 1 addition & 1 deletion bundles/cnf/releaserepo/index.xml.sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b699f269b1871b7ef42e54b5ceb7529989f9474ffa4217c696e5ad333ac8936c
588e9daeffa76506497afdf3ef329dcd7523eb8a8431ee9963eab24645a30b73
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.specmate.auth.api;

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

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

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

public void deauthenticate(String token) throws SpecmateException;
public void deauthenticate(String token) throws SpecmateException, SpecmateValidationException;

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

public String getUserName(String token) throws SpecmateException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package com.specmate.auth.api;

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

public interface ISessionService {
public UserSession create(AccessRights alm, AccessRights ppm, String userName, String projectName)
throws SpecmateException;
throws SpecmateException, SpecmateValidationException;

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 void refresh(String token) throws SpecmateException, SpecmateValidationException;

public String getUserName(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;
public void delete(String token) throws SpecmateException, SpecmateValidationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.specmate.auth.api.ISessionService;
import com.specmate.common.SpecmateException;
import com.specmate.common.SpecmateValidationException;
import com.specmate.usermodel.AccessRights;
import com.specmate.usermodel.UserSession;

Expand All @@ -29,7 +30,7 @@ public static void init() throws Exception {
}

@Test
public void testIsAuthorized() throws SpecmateException {
public void testIsAuthorized() throws SpecmateException, SpecmateValidationException {
String projectName = "testIsAuthorized";
UserSession session = sessionService.create(AccessRights.ALL, AccessRights.ALL, userName, projectName);
assertTrue(sessionService.isAuthorized(session.getId(), baseURL + projectName + "/resource1"));
Expand All @@ -41,7 +42,7 @@ public void testIsAuthorized() throws SpecmateException {
}

@Test
public void testRegexInjection() throws SpecmateException {
public void testRegexInjection() throws SpecmateException, SpecmateValidationException {
UserSession session = sessionService.create(AccessRights.ALL, AccessRights.ALL, userName, "testRegexInjection");
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "project/resource1"));
assertFalse(sessionService.isAuthorized(session.getId(), baseURL + "project/"));
Expand All @@ -64,7 +65,7 @@ public void testRegexInjection() throws SpecmateException {
}

@Test
public void testDeleteSession() throws SpecmateException {
public void testDeleteSession() throws SpecmateException, SpecmateValidationException {
boolean thrown = false;
String projectName = "testDeleteSession";
UserSession session = sessionService.create(AccessRights.ALL, AccessRights.ALL, userName, projectName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.specmate.auth.api.ISessionService;
import com.specmate.auth.config.AuthenticationServiceConfig;
import com.specmate.common.SpecmateException;
import com.specmate.common.SpecmateValidationException;
import com.specmate.connectors.api.IExportService;
import com.specmate.connectors.api.IProject;
import com.specmate.connectors.api.IProjectService;
Expand All @@ -24,7 +25,8 @@ public class AuthenticationServiceImpl implements IAuthenticationService {
private IProjectService projectService;

@Override
public UserSession authenticate(String username, String password, String projectname) throws SpecmateException {
public UserSession authenticate(String username, String password, String projectname)
throws SpecmateException, SpecmateValidationException {
IProject project = projectService.getProject(projectname);
boolean authenticated = project.getConnector().authenticate(username, password);
if (!authenticated) {
Expand All @@ -42,21 +44,22 @@ public UserSession authenticate(String username, String password, String project
}

/**
* Use this method only in tests to create a session that authorizes
* requests to all resources.
* Use this method only in tests to create a session that authorizes requests to
* all resources.
*/
@Override
public UserSession authenticate(String username, String password) throws SpecmateException {
return sessionService.create();
}

@Override
public void deauthenticate(String token) throws SpecmateException {
public void deauthenticate(String token) throws SpecmateException, SpecmateValidationException {
sessionService.delete(token);
}

@Override
public void validateToken(String token, String path, boolean refresh) throws SpecmateException {
public void validateToken(String token, String path, boolean refresh)
throws SpecmateException, SpecmateValidationException {
if (sessionService.isExpired(token)) {
sessionService.delete(token);
throw new SpecmateException("Session " + token + " is expired.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.specmate.auth.config.SessionServiceConfig;
import com.specmate.common.SpecmateException;
import com.specmate.common.SpecmateValidationException;
import com.specmate.config.api.IConfigService;
import com.specmate.connectors.api.IProjectConfigService;
import com.specmate.usermodel.AccessRights;
import com.specmate.usermodel.UserSession;
import com.specmate.usermodel.UsermodelFactory;
Expand All @@ -23,6 +25,9 @@ public abstract class BaseSessionService implements ISessionService {
protected long maxIdleMilliSeconds;
protected RandomString randomString = new RandomString();

/** Get access to the project configuration */
protected IConfigService configService;

@Activate
public void activate(Map<String, Object> properties) throws SpecmateException, SpecmateValidationException {
readConfig(properties);
Expand Down Expand Up @@ -51,6 +56,14 @@ protected UserSession createSession(AccessRights source, AccessRights target, St
session.setLastActive(new Date().getTime());
String token = randomString.nextString();
session.setId(token);

String projectLibraryKey = IProjectConfigService.PROJECT_PREFIX + projectName
+ IProjectConfigService.KEY_PROJECT_LIBRARY;
String[] libraryFolderIds = configService.getConfigurationPropertyArray(projectLibraryKey);
if (libraryFolderIds != null) {
session.getLibraryFolders().addAll(Arrays.asList(libraryFolderIds));
}

return session;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Reference;

import com.specmate.auth.api.ISessionService;
import com.specmate.auth.config.SessionServiceConfig;
import com.specmate.common.SpecmateException;
import com.specmate.config.api.IConfigService;
import com.specmate.usermodel.AccessRights;
import com.specmate.usermodel.UserSession;
import com.specmate.usermodel.UsermodelFactory;
Expand Down Expand Up @@ -86,4 +88,9 @@ private void checkSessionExists(String token) throws SpecmateException {
throw new SpecmateException("Session " + token + " does not exist.");
}
}

@Reference
public void setConfigService(IConfigService configService) {
this.configService = configService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import com.specmate.auth.config.SessionServiceConfig;
import com.specmate.common.SpecmateException;
import com.specmate.common.SpecmateValidationException;
import com.specmate.config.api.IConfigService;
import com.specmate.model.support.util.SpecmateEcoreUtil;
import com.specmate.persistency.IChange;
import com.specmate.persistency.IPersistencyService;
import com.specmate.persistency.ITransaction;
import com.specmate.persistency.IView;
Expand Down Expand Up @@ -51,10 +53,18 @@ public void deactivate() throws SpecmateException {

@Override
public UserSession create(AccessRights source, AccessRights target, String userName, String projectName)
throws SpecmateException {
throws SpecmateException, SpecmateValidationException {

UserSession session = createSession(source, target, userName, sanitize(projectName));
sessionTransaction.getResource().getContents().add(session);
sessionTransaction.commit();

sessionTransaction.doAndCommit(new IChange<Object>() {
@Override
public Object doChange() throws SpecmateException, SpecmateValidationException {
sessionTransaction.getResource().getContents().add(session);
return null;
}
});

return session;
}

Expand Down Expand Up @@ -83,21 +93,28 @@ public boolean isAuthorized(String token, String path) throws SpecmateException
}

@Override
public void refresh(String token) throws SpecmateException {
public void refresh(String token) throws SpecmateException, SpecmateValidationException {
UserSession session = (UserSession) sessionTransaction.getObjectById(getSessionID(token));
long now = new Date().getTime();
// If we let each request refresh the session, we get errors from CDO regarding
// out-of-date revision changes.
// Here we rate limit session refreshes. The better option would be to not store
// revisions of UserSession objects, but this is a setting than can be only
// applied on the
// whole repository, which we don't want.
// A third option would be to update sessions with an SQL query, circumventing
// CDO and revisions altogether.
if (session.getLastActive() - now > SESSION_REFRESH_LIMIT) {
session.setLastActive(now);
sessionTransaction.commit();
}

sessionTransaction.doAndCommit(new IChange<Object>() {
@Override
public Object doChange() throws SpecmateException, SpecmateValidationException {
// If we let each request refresh the session, we get errors from CDO regarding
// out-of-date revision changes.
// Here we rate limit session refreshes. The better option would be to not store
// revisions of UserSession objects, but this is a setting than can be only
// applied on the
// whole repository, which we don't want.
// A third option would be to update sessions with an SQL query, circumventing
// CDO and revisions altogether.
if (session.getLastActive() - now > SESSION_REFRESH_LIMIT) {
session.setLastActive(now);
}

return null;
}
});
}

@Override
Expand All @@ -111,22 +128,23 @@ public AccessRights getTargetAccessRights(String token) throws SpecmateException
}

@Override
public void delete(String token) throws SpecmateException {
public void delete(String token) throws SpecmateException, SpecmateValidationException {
UserSession session = (UserSession) sessionTransaction.getObjectById(getSessionID(token));
SpecmateEcoreUtil.detach(session);
sessionTransaction.commit();

sessionTransaction.doAndCommit(new IChange<Object>() {
@Override
public Object doChange() throws SpecmateException, SpecmateValidationException {
SpecmateEcoreUtil.detach(session);
return null;
}
});
}

@Override
public String getUserName(String token) throws SpecmateException {
return getSession(token).getUserName();
}

@Reference
public void setPersistencyService(IPersistencyService persistencyService) {
this.persistencyService = persistencyService;
}

private UserSession getSession(String token) throws SpecmateException {
String query = "UserSession.allInstances()->select(u | u.id='" + token + "')";

Expand All @@ -145,4 +163,14 @@ private UserSession getSession(String token) throws SpecmateException {
private CDOID getSessionID(String token) throws SpecmateException {
return getSession(token).cdoID();
}

@Reference
public void setPersistencyService(IPersistencyService persistencyService) {
this.persistencyService = persistencyService;
}

@Reference
public void setConfigService(IConfigService configService) {
this.configService = configService;
}
}
34 changes: 16 additions & 18 deletions bundles/specmate-config/config/specmate-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,22 @@ search.maxResults = 100

# Projects
## List of project names, each project listed here needs to be configured below
project.projects = ppmtest

## Config for project ppmtest

### Config Connector
project.ppmtest.connector.pid = com.specmate.HPServerProxyConnector
project.ppmtest.connector.hpproxy.hpConnectorHost = localhost
project.ppmtest.connector.hpproxy.hpConnectorPort = 8081
project.ppmtest.connector.hpproxy.hpConnectorTimeout = 20
project.ppmtest.connector.projectName = AZD_Anforderung
project.ppmtest.connector.connectorID = ppmtest

### Config Exporter
project.ppmtest.exporter.pid = com.specmate.HPServerProxyExporter
project.ppmtest.exporter.hpproxy.hpConnectorHost = localhost
project.ppmtest.exporter.hpproxy.hpConnectorPort = 8081
project.ppmtest.exporter.hpproxy.hpConnectorTimeout = 20
project.ppmtest.exporter.exporterID = ppmtest
# test-data needn't be configured
project.projects =

## Config for project test-data
project.test-data.library = libfolder1, libfolder2, libfolder3

project.test-data.library.libfolder1.name = Lib Folder 1
project.test-data.library.libfolder1.description = Templates for type 1 requirements

project.test-data.library.libfolder2.name = Lib Folder 2
project.test-data.library.libfolder2.description = Templates for type 2 requirements

project.test-data.library.libfolder3.name = Lib Folder 3
project.test-data.library.libfolder3.description = Templates for type 3 requirements




# User session
Expand Down
Loading

0 comments on commit 65e22fa

Please sign in to comment.