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 15 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
17 changes: 14 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -42,6 +42,17 @@
<scope>test</scope>
</dependency>

<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>log4j</groupId>
<artifactId>log4j</artifactId>
Expand All @@ -51,13 +62,13 @@
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
<version>2.9.2</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -32,11 +31,7 @@ public class Membership {
private MembershipService membershipService;

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

/**
Expand All @@ -54,7 +49,7 @@ public ResponseEntity<MembersList> 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
56 changes: 14 additions & 42 deletions src/main/java/cloud/fogbow/ms/api/http/request/Version.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package cloud.fogbow.ms.api.http.request;

import cloud.fogbow.common.util.HomeDir;
import cloud.fogbow.common.constants.ApiDocumentation;
import cloud.fogbow.ms.api.http.response.VersionNumber;
import cloud.fogbow.ms.constants.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import cloud.fogbow.ms.core.PropertiesHolder;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import cloud.fogbow.common.constants.ApiDocumentation;
import cloud.fogbow.ms.api.http.response.VersionNumber;
import cloud.fogbow.ms.constants.ConfigurationPropertyDefaults;
import cloud.fogbow.ms.constants.ConfigurationPropertyKeys;
import cloud.fogbow.ms.constants.SystemConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
Expand All @@ -28,45 +24,21 @@ public class Version {

public static final String VERSION_ENDPOINT = SystemConstants.SERVICE_BASE_ENDPOINT + "version";

private final Logger LOGGER = Logger.getLogger(Version.class);

@ApiOperation(value = ApiDocumentation.Version.GET_OPERATION)
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<VersionNumber> getVersion() throws FileNotFoundException {
public ResponseEntity<VersionNumber> getVersion() {
String versionNumber = getVersionNumber();
return new ResponseEntity<VersionNumber>(new VersionNumber(versionNumber), HttpStatus.OK);
}

public String getVersionNumber() throws FileNotFoundException {
String path = HomeDir.getPath();
return getVersionNumber(path + SystemConstants.CONF_FILE_NAME);
}

// Used in tests only
protected String getVersionNumber(String filePath) throws FileNotFoundException {
return SystemConstants.API_VERSION_NUMBER + "-" + readBuildFromFile(filePath);
public String getVersionNumber() {
return SystemConstants.API_VERSION_NUMBER + "-" + readBuildNumber();
}

private String readBuildFromFile(String membershipConfPath) throws FileNotFoundException {
Properties properties = new Properties();
InputStream input = new FileInputStream(membershipConfPath);
String build = "empty";

try {
properties.load(input);

build = properties.getProperty(ConfigurationPropertyKeys.BUILD_NUMBER_KEY,
private String readBuildNumber() {
String build;
build = PropertiesHolder.getInstance().getProperty(ConfigurationPropertyKeys.BUILD_NUMBER_KEY,
ConfigurationPropertyDefaults.BUILD_NUMBER);
} catch (IOException e) {
LOGGER.warn(String.format(Messages.Warn.ERROR_READING_CONF_FILE, membershipConfPath), e);
} finally {
try {
input.close();
} catch (IOException e) {
LOGGER.warn(String.format(Messages.Warn.ERROR_CLOSING_CONF_FILE, membershipConfPath), e);
}
}

return build;
}
}
14 changes: 1 addition & 13 deletions src/main/java/cloud/fogbow/ms/constants/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ public class Messages {
public static class Exception {
}

public static class Fatal {
}

public static class Warn {
public static final String ERROR_READING_CONF_FILE = "Error trying to read configuration file: %s.";
public static final String ERROR_CLOSING_CONF_FILE = "Error trying to close configuration file: %s.";
}

public static class Info {
}

public static class Error {
public static final String CONFIGURATION_FILE_NOT_FOUND = "Configuration file not found.";
public static class Log {
public static final String INTERNAL_SERVER_ERROR = "Internal server error.";
}
}
38 changes: 38 additions & 0 deletions src/main/java/cloud/fogbow/ms/core/PropertiesHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cloud.fogbow.ms.core;

import cloud.fogbow.common.util.PropertiesUtil;
import cloud.fogbow.common.exceptions.FatalErrorException;
import cloud.fogbow.common.util.HomeDir;
import cloud.fogbow.ms.constants.SystemConstants;

import java.util.Properties;

public class PropertiesHolder {
private Properties properties;
private static PropertiesHolder instance;

private PropertiesHolder() throws FatalErrorException {
String path = HomeDir.getPath();
String configFileName = path + SystemConstants.CONF_FILE_NAME;
this.properties = PropertiesUtil.readProperties(configFileName);
}

public static synchronized PropertiesHolder getInstance() throws FatalErrorException {
if (instance == null) {
instance = new PropertiesHolder();
}
return instance;
}

public String getProperty(String propertyName) {
return properties.getProperty(propertyName);
}

public String getProperty(String propertyName, String defaultPropertyValue) {
String propertyValue = this.properties.getProperty(propertyName, defaultPropertyValue);
if (propertyValue.trim().isEmpty()) {
propertyValue = defaultPropertyValue;
}
return propertyValue;
}
}
51 changes: 12 additions & 39 deletions src/main/java/cloud/fogbow/ms/core/service/WhiteList.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,38 @@
package cloud.fogbow.ms.core.service;

import cloud.fogbow.common.util.HomeDir;
import cloud.fogbow.ms.MembershipService;
import java.util.ArrayList;
import java.util.List;

import cloud.fogbow.ms.constants.ConfigurationPropertyKeys;
import org.apache.log4j.Logger;
import cloud.fogbow.ms.constants.Messages;
import cloud.fogbow.ms.constants.SystemConstants;
import cloud.fogbow.ms.core.PropertiesHolder;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import cloud.fogbow.ms.MembershipService;

public class WhiteList implements MembershipService {

private static final Logger LOGGER = Logger.getLogger(WhiteList.class);
private static final String SEPARATOR = ",";

private List<String> membersList;

public WhiteList(String membershipConfPath) throws FileNotFoundException {
this.membersList = readMembersFromFile(membershipConfPath);
}

public WhiteList() throws FileNotFoundException {
this.membersList = readMembersFromFile(SystemConstants.CONF_FILE_NAME);
public WhiteList() {
this.membersList = readMembers();
}

/**
* Read list of XMPP members ID from membership config file.
*
*/
@Override
public List<String> listMembers() {
return this.membersList;
}

private List<String> readMembersFromFile(String membershipConfPath) throws FileNotFoundException {
Properties properties = new Properties();
InputStream input = new FileInputStream(HomeDir.getPath() + membershipConfPath);
private List<String> readMembers() {
List<String> membersList = new ArrayList<>();

try {
properties.load(input);

String membersListStr = properties.getProperty(ConfigurationPropertyKeys.MEMBERS_LIST_KEY);
for (String member : membersListStr.split(",")) {
member = member.trim();
membersList.add(member);
}
} catch (IOException e) {
LOGGER.warn(String.format(Messages.Warn.ERROR_READING_CONF_FILE, membershipConfPath), e);
} finally {
try {
input.close();
} catch (IOException e) {
LOGGER.warn(String.format(Messages.Warn.ERROR_CLOSING_CONF_FILE, membershipConfPath), e);
}
String membersListStr = PropertiesHolder.getInstance().getProperty(ConfigurationPropertyKeys.MEMBERS_LIST_KEY);
for (String member : membersListStr.split(SEPARATOR)) {
member = member.trim();
membersList.add(member);
}

return membersList;
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/template/ms.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# copy this file into src/main/resources/private
members_list=member1,member2,member3
members_list=member1,member2,member3
build_number=[testing mode]
70 changes: 51 additions & 19 deletions src/test/java/cloud/fogbow/ms/api/http/request/VersionTests.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,70 @@
package cloud.fogbow.ms.api.http.request;

import cloud.fogbow.common.util.HomeDir;
import cloud.fogbow.ms.constants.SystemConstants;
import java.io.FileNotFoundException;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import java.io.FileNotFoundException;
import cloud.fogbow.ms.constants.SystemConstants;

@RunWith(SpringRunner.class)
@WebMvcTest
public class VersionTests {
private String VALID_CONF = "ms-test.conf";
private String VALID_CONF_WITHOUT_BUILD_PROPERTY = "ms-test-nobuild.conf";
private String INVALID_CONF = "invalid.conf";

@Test
public void testVersion() throws Exception {
Version version = new Version();
private static final String BASE_ENDPOINT = "/";
private static final String BUILD_PROPERTY = "abcd";
private static final String VERSION_NUMBER_SEPARATOR = "-";

String build = version.getVersionNumber(HomeDir.getPath() + this.VALID_CONF);
@Autowired
private MockMvc mockMvc;

Assert.assertEquals(SystemConstants.API_VERSION_NUMBER + "-" + "abcd", build);
private Version version;

@Before
public void setup() {
this.version = new Version();
}

// test case: When invoking the getVersionNumber method with no parameters, it
// must use a default file and return the version number concatenated the value
// of the default file build number property.
@Test
public void testVersionWithoutBuildProperty() throws Exception {
Version version = new Version();
public void testVersionWithoutConfPath() throws Exception {
// exercise
String build = this.version.getVersionNumber();

String build = version.getVersionNumber(HomeDir.getPath() + this.VALID_CONF_WITHOUT_BUILD_PROPERTY);
// verify
Assert.assertEquals(SystemConstants.API_VERSION_NUMBER + VERSION_NUMBER_SEPARATOR + BUILD_PROPERTY, build);
}

Assert.assertTrue(build.equals(SystemConstants.API_VERSION_NUMBER + "-" + "[testing mode]"));
// test case: When executing a GET request for the "/ms/version" endpoint, it
// must invoke the getVersion method by returning the Status OK and the version
// content in format json.
@Test
public void testGetVersion() throws Exception {
// set up
String expected = getJsonResponseContent();

// exercise
this.mockMvc.perform(MockMvcRequestBuilders.get(BASE_ENDPOINT + Version.VERSION_ENDPOINT))
// verify
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.content().json(expected));
}

@Test(expected = FileNotFoundException.class)
public void testListMembersWithInvalidConfPath() throws FileNotFoundException {
Version version = new Version();
version.getVersionNumber(this.INVALID_CONF);
private String getJsonResponseContent() {
return "{\"version\":" + SystemConstants.API_VERSION_NUMBER
+ VERSION_NUMBER_SEPARATOR
+ BUILD_PROPERTY
+ "}";
}

}
Loading