Skip to content

Commit

Permalink
Merged add and delete operations, passing provider info in the body
Browse files Browse the repository at this point in the history
  • Loading branch information
armstrongmsg committed Dec 21, 2020
1 parent 9d223d4 commit 5444d54
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 779 deletions.
50 changes: 11 additions & 39 deletions src/main/java/cloud/fogbow/ms/api/http/request/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -24,6 +25,7 @@
@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";
// TODO use these endpoint values
Expand Down Expand Up @@ -54,8 +56,8 @@ public ResponseEntity<Boolean> service(
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 Provider provider) throws FogbowException {
ApplicationFacade.getInstance().addProvider(systemUserToken, provider.getProvider());
@RequestBody ProviderPermission provider) throws FogbowException {
ApplicationFacade.getInstance().addProvider(systemUserToken, provider.getProvider(), provider.getTarget(), provider.getRequester());

This comment has been minimized.

Copy link
@fubica

fubica Dec 22, 2020

Collaborator

For readability purpose, I would change the signature of addProvider() and all the functions call from there, so that they receive simply the provider as a parameter. Instead of receiving the boolean that is returned by provider.getTarget() and provider.getRequester(), any method that needs to check the value of these boolean fields, should call the new methods provider.isTarget() and provider.isRequester().

This comment has been minimized.

Copy link
@armstrongmsg

armstrongmsg Dec 22, 2020

Author

Done.

return new ResponseEntity<>(HttpStatus.OK);
}

Expand All @@ -69,43 +71,13 @@ public ResponseEntity<Boolean> removeProvider(
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.ADD_TARGET)
@RequestMapping(value = "/target", method = RequestMethod.POST)
public ResponseEntity<Boolean> addTarget(
@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().addTargetProvider(systemUserToken, provider.getProvider());
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.ADD_REQUESTER)
@RequestMapping(value = "/requester", method = RequestMethod.POST)
public ResponseEntity<Boolean> addRequester(
@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().addRequesterProvider(systemUserToken, provider.getProvider());
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.REMOVE_TARGET)
@RequestMapping(value = "/target", method = RequestMethod.DELETE)
public ResponseEntity<Boolean> removeTarget(
@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().removeTargetProvider(systemUserToken, provider.getProvider());
return new ResponseEntity<>(HttpStatus.OK);
}

@ApiOperation(value = ApiDocumentation.Admin.REMOVE_REQUESTER)
@RequestMapping(value = "/requester", method = RequestMethod.DELETE)
public ResponseEntity<Boolean> removeRequester(
@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().removeRequesterProvider(systemUserToken, provider.getProvider());
@ApiOperation(value = ApiDocumentation.Admin.UPDATE_PROVIDER)
@RequestMapping(value = "/provider", 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.getProvider(), provider.getTarget(), provider.getRequester());
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cloud.fogbow.ms.api.parameters;

public class ProviderPermission {
private String provider;
private boolean target;
private boolean requester;

public String getProvider() {
return provider;
}

public boolean getTarget() {
return target;
}

public boolean getRequester() {
return requester;
}

This comment has been minimized.

Copy link
@fubica

fubica Dec 22, 2020

Collaborator

See previous comment. I'd change the get methods for isTarget and isRequester methods. I believe it will make the code that call these methods easier to read.

This comment has been minimized.

Copy link
@armstrongmsg

armstrongmsg Dec 22, 2020

Author

Done.

}
10 changes: 1 addition & 9 deletions src/main/java/cloud/fogbow/ms/constants/ApiDocumentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ public static class Admin {
public static final String RELOAD = "Reloads service configuration.";
public static final String ADD_PROVIDER = "Adds given provider to the list of known providers.";
public static final String REMOVE_PROVIDER = "Removes given provider from all the lists of providers kept by the service.";
public static final String ADD_TARGET = "Adds given provider to the list of targets, used by the MembershipService "
+ "to authorize remote operations.";
public static final String REMOVE_TARGET = "Removes given provider from the list of targets, used by the MembershipService "
+ "to authorize remote operations.";
public static final String ADD_REQUESTER = "Adds given provider to the list of requesters, used by the MembershipService "
+ "to authorized operations from other providers";
public static final String REMOVE_REQUESTER = "Removes given provider from the list of requesters, used by the MembershipService "
+ "to authorized operations from other providers";
public static final String UPDATE_PROVIDER = "Updates permission information for the given provider.";
public static final String SERVICE = "Changes membership service plugin to the given class name";

}
}
1 change: 1 addition & 0 deletions src/main/java/cloud/fogbow/ms/constants/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static class Exception {
public static final String PROVIDER_IS_ALREADY_A_MEMBER = "Provider is already a member.";
public static final String PROVIDER_IS_ALREADY_A_REQUESTER = "Provider is already a requester.";
public static final String PROVIDER_IS_ALREADY_A_TARGET = "Provider is already a target.";
public static final String PROVIDER_MUST_BE_TARGET_REQUESTER_OR_BOTH = "Provider must be target, requester, or both.";
public static final String UNABLE_TO_FIND_CLASS_S = "Unable to find class %s.";
public static final String USER_IS_NOT_ADMIN = "Not-admin user trying to perform admin-only operation.";
}
Expand Down
111 changes: 30 additions & 81 deletions src/main/java/cloud/fogbow/ms/core/ApplicationFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@ public MembershipService getMembershipService() {
public void setAuthorizationPlugin(AuthorizationPlugin<MsOperation> authorizationPlugin) {
this.authorizationPlugin = authorizationPlugin;
}

public void addProvider(String userToken, String provider) throws FogbowException {
LOGGER.info(String.format(Messages.Log.ADDING_NEW_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.addMember(provider);
} finally {
finishReloading();
}
public void addProvider(String userToken, String provider, boolean target, boolean requester) throws FogbowException {
LOGGER.info(String.format(Messages.Log.REMOVING_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.addMember(provider, target, requester);
} finally {
finishReloading();
}
}

public void removeProvider(String userToken, String provider) throws FogbowException {
Expand All @@ -125,74 +125,23 @@ public void removeProvider(String userToken, String provider) throws FogbowExcep
finishReloading();
}
}

public void addTargetProvider(String userToken, String provider) throws FogbowException {
LOGGER.info(String.format(Messages.Log.ADDING_TARGET_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.addTarget(provider);
} finally {
finishReloading();
}

}

public void addRequesterProvider(String userToken, String provider) throws FogbowException {
LOGGER.info(String.format(Messages.Log.ADDING_REQUESTER_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.addRequester(provider);
} finally {
finishReloading();
}

}

public void removeTargetProvider(String userToken, String provider) throws FogbowException {
LOGGER.info(String.format(Messages.Log.REMOVING_TARGET_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.removeTarget(provider);
} finally {
finishReloading();
}
}

public void removeRequesterProvider(String userToken, String provider) throws FogbowException {
LOGGER.info(String.format(Messages.Log.REMOVING_REQUESTER_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.removeRequester(provider);
} finally {
finishReloading();
}

}

public void updateProvider(String userToken, String provider, boolean target, boolean requester) throws FogbowException {
LOGGER.info(String.format(Messages.Log.REMOVING_PROVIDER, provider));

RSAPublicKey asPublicKey = MSPublicKeysHolder.getInstance().getAsPublicKey();
SystemUser systemUser = AuthenticationUtil.authenticate(asPublicKey, userToken);
this.authorizationPlugin.isAuthorized(systemUser, new MsOperation());

setAsReloading();

try {
this.membershipService.updateMember(provider, target, requester);
} finally {
finishReloading();
}
}

public void reload(String userToken) throws FogbowException {
LOGGER.info(Messages.Log.RELOADING_CONFIGURATION);

Expand Down
19 changes: 9 additions & 10 deletions src/main/java/cloud/fogbow/ms/core/MembershipService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ public interface MembershipService {
*/
public boolean isMember(String provider);

// TODO documentation
public boolean isTargetAuthorized(String provider);

// TODO documentation
public boolean isRequesterAuthorized(String provider);

public void addMember(String provider) throws ConfigurationErrorException;

public void addTarget(String provider) throws ConfigurationErrorException;

public void addRequester(String provider) throws ConfigurationErrorException;

public void removeTarget(String provider) throws ConfigurationErrorException;

public void removeRequester(String provider) throws ConfigurationErrorException;

// TODO documentation
public void addMember(String provider, boolean target, boolean requester) throws ConfigurationErrorException;

// TODO documentation
public void updateMember(String provider, boolean target, boolean requester) throws ConfigurationErrorException;

// TODO documentation
public void removeMember(String provider) throws ConfigurationErrorException;
}
2 changes: 2 additions & 0 deletions src/main/java/cloud/fogbow/ms/core/service/AllowList.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public AllowList() throws ConfigurationErrorException {
this.membersList = readMembers();
this.targetMembers = readTargetMembers();
this.requesterMembers = readRequesterMembers();

validateMembersList();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/cloud/fogbow/ms/core/service/BlockList.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public BlockList() throws ConfigurationErrorException {
membersList = readMembers();
targetMembers = readTargetMembers();
requesterMembers = readRequesterMembers();

validateMembersList();
}

/**
Expand Down
Loading

0 comments on commit 5444d54

Please sign in to comment.