Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #31

Draft
wants to merge 72 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8354815
Created default file ms.conf in the src/test/resources/private/ folder
wassoares Jul 15, 2019
32988f3
Fixed tests of the WhiteListTest class, with changes made in the Whit…
wassoares Jul 15, 2019
dad145f
Fixed tests of the VersionTest class, with changes made in the Versio…
wassoares Jul 15, 2019
e543036
Fixed indentation of the Version class
wassoares Jul 15, 2019
15c01b1
Added more test in the VersionTest class for coverage of the Version …
wassoares Jul 15, 2019
27f9a7b
Fixed indentation of the WhiteList and WhiteList classes
wassoares Jul 15, 2019
a86f0e5
Refactor reading data from files to standardize code
ANKerD Jul 18, 2019
f2c1f36
Refactor tests due to changes in code
ANKerD Jul 19, 2019
f5fd114
Removed unused imports
ANKerD Jul 22, 2019
38247cb
Merge pull request #13 from fogbow/refactor-file-reading
thiagomanel Jul 22, 2019
a701261
Fixed pom.xml to exclude logging dependency in springboot
fubica Apr 14, 2020
05c3447
Refactored Messages
fubica Jun 18, 2020
4963a03
Merge pull request #19 from fogbow/fix-messages
fubica Jun 18, 2020
4f00ebd
Update dependencies to match master branch
jadsonluan Jun 22, 2020
aa680be
Merge pull request #20 from fogbow/update-dependencies
fubica Jun 22, 2020
c649042
Added authorization basic structure
armstrongmsg Nov 18, 2020
67f9e62
Added tests to AllowOnlyPermission
armstrongmsg Nov 18, 2020
c7c30f2
Added tests to RoleAttributionManager and WhiteList
armstrongmsg Nov 18, 2020
a847273
Added AllowAllExceptPermission type
armstrongmsg Nov 19, 2020
5943721
Added tests for WhiteList and changed canPerformOperation signature
armstrongmsg Nov 19, 2020
b8211b5
Added tests for DefaultAuthorizationPlugin
armstrongmsg Nov 19, 2020
4b6834d
Added default constructor to fix problem on membership call
armstrongmsg Nov 19, 2020
c8b61d0
Added some TODOs
armstrongmsg Nov 19, 2020
6099897
Moved MembershipService interface to core package
armstrongmsg Nov 19, 2020
323d20a
Some more TODOs
armstrongmsg Nov 19, 2020
3dce376
Created interface RoleManager
armstrongmsg Nov 19, 2020
3a358af
Moved service startup to Main and some refactoring
armstrongmsg Nov 19, 2020
20f1c44
Refactored isAuthorized endpoint code
armstrongmsg Nov 19, 2020
21795c5
Added default role management to RoleAttributionManager
armstrongmsg Nov 20, 2020
188ca02
Added complete version of authorization algorithm
armstrongmsg Nov 20, 2020
697515f
Added user role setting to RoleAttributionManager
armstrongmsg Nov 20, 2020
b42e314
Implemented correct communication with RAS on authorization
armstrongmsg Nov 24, 2020
6c69964
Added requests methods used by RAS
armstrongmsg Nov 24, 2020
8697e4b
Updated pom with build info
armstrongmsg Nov 26, 2020
d67fde8
Updated pom with build info
armstrongmsg Nov 26, 2020
4c2d662
Added tests for no permissions case to AllowOnlyPermission
armstrongmsg Nov 28, 2020
ef3a504
Added test for no operation case for AllowAllExceptPermission
armstrongmsg Nov 28, 2020
ca9de0e
Refactored RoleAttributionManager
armstrongmsg Nov 28, 2020
e00530e
Added some TODOs
armstrongmsg Nov 28, 2020
fbd6de1
Added option for provider only authorization
armstrongmsg Dec 4, 2020
20122dd
Removed code related to role-based authorization
armstrongmsg Dec 4, 2020
ab07bc5
Improved documentation
armstrongmsg Dec 4, 2020
f74db29
Merge pull request #35 from fogbow/new_membership_arch
fubica Dec 5, 2020
be8a73e
Adding new provider authorization based on two authorization types
armstrongmsg Dec 9, 2020
ab3f2a1
Fixed issue with empty providers list
armstrongmsg Dec 10, 2020
10df65b
Added messages to exceptions in BlackList and WhiteList
armstrongmsg Dec 10, 2020
7334a4d
Adding documentation
armstrongmsg Dec 10, 2020
d4f64b8
Removed unused classes and interface
armstrongmsg Dec 10, 2020
d9a2ad1
Updated template configuration file
armstrongmsg Dec 10, 2020
7724a36
Changed MembershipService implementations names
armstrongmsg Dec 13, 2020
a5d5d8b
Updated AllowList name on tests
armstrongmsg Dec 13, 2020
ca22d0f
Merge pull request #36 from fogbow/two_provider_lists
fubica Dec 13, 2020
acd5383
Adding reload operation and admin management
armstrongmsg Dec 16, 2020
6b92836
Added addProvider operation
armstrongmsg Dec 16, 2020
c1c94c1
Adding addTarget and addRequester operations
armstrongmsg Dec 17, 2020
3fff462
Some refactoring
armstrongmsg Dec 17, 2020
0cd2730
Added removeTarget and removeRequester operations
armstrongmsg Dec 17, 2020
06ebafd
Some refactoring and tests
armstrongmsg Dec 17, 2020
2dc4fdb
Adding removerProvider operation
armstrongmsg Dec 17, 2020
7d9add4
Adding tests to ApplicationFacade
armstrongmsg Dec 18, 2020
33ca75d
Added documentation and logs
armstrongmsg Dec 18, 2020
5569285
Adding documentation to tests
armstrongmsg Dec 19, 2020
8d409b9
Adding operation that changes the used MembershipService type
armstrongmsg Dec 21, 2020
9d223d4
Changed AdminOperation class name to MsOperation
armstrongmsg Dec 21, 2020
5444d54
Merged add and delete operations, passing provider info in the body
armstrongmsg Dec 21, 2020
d320643
Changed addProvider and updateProvider signatures
armstrongmsg Dec 22, 2020
f929b78
Fixed some constant strings
armstrongmsg Dec 22, 2020
3b38ef2
Added more tests
armstrongmsg Dec 22, 2020
fba4c06
Added documentation
armstrongmsg Dec 22, 2020
b9ad466
Merge pull request #38 from fogbow/ms_admin_operations
fubica Dec 22, 2020
10d3bd4
Added required methods to AdminAuthorizationPlugin
armstrongmsg Dec 29, 2020
c33b7d4
Merge pull request #39 from fogbow/ras_admin_operations
fubica Jan 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 58 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<powermock.version>1.7.4</powermock.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
Expand All @@ -34,8 +35,14 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -60,19 +67,63 @@
<version>2.8.0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>fogbow</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<groupId>fogbow</groupId>
<artifactId>fogbow-as</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<excludes>
<exclude>examples/</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/cloud/fogbow/ms/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cloud.fogbow.ms;

import org.apache.log4j.Logger;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import cloud.fogbow.common.constants.FogbowConstants;
import cloud.fogbow.common.exceptions.ConfigurationErrorException;
import cloud.fogbow.common.exceptions.FatalErrorException;
import cloud.fogbow.common.plugins.authorization.AuthorizationPlugin;
import cloud.fogbow.common.util.ServiceAsymmetricKeysHolder;
import cloud.fogbow.ms.core.ApplicationFacade;
import cloud.fogbow.ms.core.MembershipService;
import cloud.fogbow.ms.core.PluginInstantiator;
import cloud.fogbow.ms.core.PropertiesHolder;
import cloud.fogbow.ms.core.authorization.MsOperation;

@Component
public class Main implements ApplicationRunner {
private final Logger LOGGER = Logger.getLogger(Main.class);

@Override
public void run(ApplicationArguments args) throws ConfigurationErrorException {
try {
String publicKeyFilePath = PropertiesHolder.getInstance().getProperty(FogbowConstants.PUBLIC_KEY_FILE_PATH);
String privateKeyFilePath = PropertiesHolder.getInstance().getProperty(FogbowConstants.PRIVATE_KEY_FILE_PATH);
ServiceAsymmetricKeysHolder.getInstance().setPublicKeyFilePath(publicKeyFilePath);
ServiceAsymmetricKeysHolder.getInstance().setPrivateKeyFilePath(privateKeyFilePath);

AuthorizationPlugin<MsOperation> authorizationPlugin = PluginInstantiator.getAuthorizationPlugin();
MembershipService membershipService = PluginInstantiator.getMembershipService();

ApplicationFacade.getInstance().setMembershipService(membershipService);
ApplicationFacade.getInstance().setAuthorizationPlugin(authorizationPlugin);

} catch (FatalErrorException errorException) {
LOGGER.fatal(errorException.getMessage(), errorException);
tryExit();
}
}

private void tryExit() {
if (!Boolean.parseBoolean(System.getenv("SKIP_TEST_ON_TRAVIS")))
System.exit(1);
}
}
14 changes: 0 additions & 14 deletions src/main/java/cloud/fogbow/ms/MembershipService.java

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/java/cloud/fogbow/ms/api/http/CommonKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cloud.fogbow.ms.api.http;

public class CommonKeys {
public static final String SYSTEM_USER_TOKEN_HEADER_KEY = "Fogbow-User-Token";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cloud.fogbow.ms.api.http;

import org.springframework.web.bind.annotation.ControllerAdvice;
import cloud.fogbow.common.http.FogbowExceptionToHttpErrorConditionTranslator;

@ControllerAdvice
public class MsExceptionToHttpErrorConditionTranslator extends FogbowExceptionToHttpErrorConditionTranslator {

}
83 changes: 83 additions & 0 deletions src/main/java/cloud/fogbow/ms/api/http/request/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package cloud.fogbow.ms.api.http.request;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cloud.fogbow.common.exceptions.FogbowException;
import cloud.fogbow.ms.api.http.CommonKeys;
import cloud.fogbow.ms.api.parameters.Provider;
import cloud.fogbow.ms.api.parameters.ProviderPermission;
import cloud.fogbow.ms.api.parameters.Service;
import cloud.fogbow.ms.constants.ApiDocumentation;
import cloud.fogbow.ms.constants.SystemConstants;
import cloud.fogbow.ms.core.ApplicationFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@CrossOrigin
@RestController
@RequestMapping(value = Admin.ADMIN_ENDPOINT)
@Api(description = ApiDocumentation.Admin.API)
// TODO add documentation for parameters
public class Admin {
public static final String ADMIN_ENDPOINT = SystemConstants.SERVICE_BASE_ENDPOINT + "admin";
public static final String RELOAD_ENDPOINT = "/reload";
public static final String SERVICE_ENDPOINT = "/service";
public static final String PROVIDER_ENDPOINT = "/provider";

@ApiOperation(value = ApiDocumentation.Admin.RELOAD)
@RequestMapping(value = RELOAD_ENDPOINT, method = RequestMethod.POST)
public ResponseEntity<Boolean> reload(
@ApiParam(value = cloud.fogbow.common.constants.ApiDocumentation.Token.SYSTEM_USER_TOKEN)
@RequestHeader(required = false, value = CommonKeys.SYSTEM_USER_TOKEN_HEADER_KEY) String systemUserToken) throws FogbowException {
ApplicationFacade.getInstance().reload(systemUserToken);
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.SERVICE)
@RequestMapping(value = SERVICE_ENDPOINT, method = RequestMethod.POST)
public ResponseEntity<Boolean> service(
@ApiParam(value = cloud.fogbow.common.constants.ApiDocumentation.Token.SYSTEM_USER_TOKEN)
@RequestHeader(required = false, value = CommonKeys.SYSTEM_USER_TOKEN_HEADER_KEY)String systemUserToken,
@RequestBody Service service) throws FogbowException {
ApplicationFacade.getInstance().updateMembershipService(systemUserToken, service.getClassName());
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.ADD_PROVIDER)
@RequestMapping(value = PROVIDER_ENDPOINT, method = RequestMethod.POST)
public ResponseEntity<Boolean> addProvider(
@ApiParam(value = cloud.fogbow.common.constants.ApiDocumentation.Token.SYSTEM_USER_TOKEN)
@RequestHeader(required = false, value = CommonKeys.SYSTEM_USER_TOKEN_HEADER_KEY) String systemUserToken,
@RequestBody ProviderPermission provider) throws FogbowException {
ApplicationFacade.getInstance().addProvider(systemUserToken, provider);
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.REMOVE_PROVIDER)
@RequestMapping(value = PROVIDER_ENDPOINT, method = RequestMethod.DELETE)
public ResponseEntity<Boolean> removeProvider(
@ApiParam(value = cloud.fogbow.common.constants.ApiDocumentation.Token.SYSTEM_USER_TOKEN)
@RequestHeader(required = false, value = CommonKeys.SYSTEM_USER_TOKEN_HEADER_KEY) String systemUserToken,
@RequestBody Provider provider) throws FogbowException {
ApplicationFacade.getInstance().removeProvider(systemUserToken, provider.getProvider());
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.UPDATE_PROVIDER)
@RequestMapping(value = PROVIDER_ENDPOINT, method = RequestMethod.PUT)
public ResponseEntity<Boolean> updateProvider(
@ApiParam(value = cloud.fogbow.common.constants.ApiDocumentation.Token.SYSTEM_USER_TOKEN)
@RequestHeader(required = false, value = CommonKeys.SYSTEM_USER_TOKEN_HEADER_KEY) String systemUserToken,
@RequestBody ProviderPermission provider) throws FogbowException {
ApplicationFacade.getInstance().updateProvider(systemUserToken, provider);
return new ResponseEntity<>(HttpStatus.OK);
}
}
44 changes: 44 additions & 0 deletions src/main/java/cloud/fogbow/ms/api/http/request/Authorization.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cloud.fogbow.ms.api.http.request;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cloud.fogbow.ms.api.http.response.Authorized;
import cloud.fogbow.ms.api.parameters.Provider;
import cloud.fogbow.ms.constants.ApiDocumentation;
import cloud.fogbow.ms.constants.SystemConstants;
import cloud.fogbow.ms.core.ApplicationFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
@RequestMapping(value = Authorization.AUTHORIZED_ENDPOINT)
@Api(description = ApiDocumentation.Authorization.API)
public class Authorization {
public static final String AUTHORIZED_ENDPOINT = SystemConstants.SERVICE_BASE_ENDPOINT + "authorized";
public static final String TARGET_AUTHORIZED_ENDPOINT = AUTHORIZED_ENDPOINT + "/target";
public static final String REQUESTER_AUTHORIZED_ENDPOINT = AUTHORIZED_ENDPOINT + "/requester";

@ApiOperation(value = ApiDocumentation.Authorization.TARGET_OPERATION)
@RequestMapping(value = "/target", method = RequestMethod.POST)
public ResponseEntity<Authorized> isTargetAuthorized(
@RequestBody Provider provider) {
boolean authorized = ApplicationFacade.getInstance().isTargetAuthorized(provider.getProvider());
return new ResponseEntity<Authorized>(new Authorized(authorized), HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Authorization.REQUESTER_OPERATION)
@RequestMapping(value = "/requester", method = RequestMethod.POST)
public ResponseEntity<Authorized> isRequesterAuthorized(
@RequestBody Provider provider) {
boolean authorized = ApplicationFacade.getInstance().isRequesterAuthorized(provider.getProvider());
return new ResponseEntity<Authorized>(new Authorized(authorized), HttpStatus.OK);
}

}
21 changes: 5 additions & 16 deletions src/main/java/cloud/fogbow/ms/api/http/request/Membership.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cloud.fogbow.ms.api.http.request;

import cloud.fogbow.ms.constants.SystemConstants;
import cloud.fogbow.ms.core.service.WhiteList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import cloud.fogbow.ms.MembershipService;

import cloud.fogbow.ms.core.ApplicationFacade;
import cloud.fogbow.ms.constants.ApiDocumentation;
import cloud.fogbow.ms.constants.Messages;
import cloud.fogbow.ms.api.http.response.MembersList;
Expand All @@ -16,7 +16,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;
import java.util.List;

@CrossOrigin
Expand All @@ -29,14 +28,8 @@ public class Membership {

private static final Logger LOGGER = Logger.getLogger(Membership.class);

private MembershipService membershipService;

public Membership() {
try {
this.membershipService = new WhiteList();
} catch (FileNotFoundException e) {
LOGGER.error(String.format(Messages.Error.CONFIGURATION_FILE_NOT_FOUND), e);
}

}

/**
Expand All @@ -45,16 +38,12 @@ public Membership() {
@ApiOperation(value = ApiDocumentation.Membership.DESCRIPTION)
@GetMapping
public ResponseEntity<MembersList> listMembers() {
if (this.membershipService == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

try {
List<String> membersId = this.membershipService.listMembers();
List<String> membersId = ApplicationFacade.getInstance().listMembers();
MembersList membersList = new MembersList(membersId);
return new ResponseEntity<MembersList>(membersList, HttpStatus.OK);
} catch (Exception e) {
LOGGER.error(Messages.Error.INTERNAL_SERVER_ERROR, e);
LOGGER.error(Messages.Log.INTERNAL_SERVER_ERROR, e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand Down
Loading