Skip to content
Permalink
Browse files
Merge pull request #12 from myrle-krantz/develop
Adding some stuff useful to the provisioner.
  • Loading branch information
myrle-krantz committed May 3, 2017
2 parents 3644db1 + 5b97079 commit 4d678193d3e6b40e08c8648f34b7795940726427
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 2 deletions.
@@ -0,0 +1,23 @@
/*
* Copyright 2017 The Mifos Initiative.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.identity.api.v1.client;

/**
* @author Myrle Krantz
*/
@SuppressWarnings("WeakerAccess")
public class ApplicationPermissionAlreadyExistsException extends RuntimeException {
}
@@ -0,0 +1,23 @@
/*
* Copyright 2017 The Mifos Initiative.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.mifos.identity.api.v1.client;

/**
* @author Myrle Krantz
*/
@SuppressWarnings("WeakerAccess")
public class CallEndpointSetAlreadyExistsException extends RuntimeException {
}
@@ -155,13 +155,20 @@ Signature getApplicationSignature(@PathVariable("applicationidentifier") String
@RequestMapping(value = "/applications/{applicationidentifier}/permissions", method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
@ThrowsException(status = HttpStatus.CONFLICT, exception = ApplicationPermissionAlreadyExistsException.class)
void createApplicationPermission(@PathVariable("applicationidentifier") String applicationIdentifier, Permission permission);

@RequestMapping(value = "/applications/{applicationidentifier}/permissions", method = RequestMethod.GET,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
List<Permission> getApplicationPermissions(@PathVariable("applicationidentifier") String applicationIdentifier);

@RequestMapping(value = "/applications/{applicationidentifier}/permissions/{permissionidentifier}", method = RequestMethod.GET,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
Permission getApplicationPermission(@PathVariable("applicationidentifier") String applicationIdentifier,
@PathVariable("permissionidentifier") String permittableEndpointGroupIdentifier);

@RequestMapping(value = "/applications/{applicationidentifier}/permissions/{permissionidentifier}", method = RequestMethod.DELETE,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
@@ -171,6 +178,7 @@ void deleteApplicationPermission(@PathVariable("applicationidentifier") String a
@RequestMapping(value = "/applications/{applicationidentifier}/callendpointset", method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
@ThrowsException(status = HttpStatus.CONFLICT, exception = CallEndpointSetAlreadyExistsException.class)
void createApplicationCallEndpointSet(@PathVariable("applicationidentifier") String applicationIdentifier, CallEndpointSet callEndpointSet);

@RequestMapping(value = "/applications/{applicationidentifier}/callendpointset/{callendpointsetidentifier}", method = RequestMethod.PUT,
@@ -35,6 +35,11 @@ public class CallEndpointSet {
public CallEndpointSet() {
}

public CallEndpointSet(String identifier, List<String> permittableEndpointGroupIdentifiers) {
this.identifier = identifier;
this.permittableEndpointGroupIdentifiers = permittableEndpointGroupIdentifiers;
}

public String getIdentifier() {
return identifier;
}
@@ -67,6 +67,9 @@ public void testCreateAndDeleteApplicationPermission() throws InterruptedExcepti
{
final List<Permission> applicationPermissions = getTestSubject().getApplicationPermissions(appPlusSig.getApplicationIdentifier());
Assert.assertTrue(applicationPermissions.contains(identityManagementPermission));

final Permission applicationPermission = getTestSubject().getApplicationPermission(appPlusSig.getApplicationIdentifier(), PermittableGroupIds.IDENTITY_MANAGEMENT);
Assert.assertEquals(identityManagementPermission, applicationPermission);
}

final Permission roleManagementPermission = new Permission();
@@ -80,7 +80,7 @@ public List<PermissionType> getAllPermissionsForApplication(final String applica
return result.stream().map(ApplicationPermissionEntity::getPermission).collect(Collectors.toList());
}

private List<ApplicationPermissionEntity> getAllApplicationPermissionEntitiesForApplication(String applicationIdentifier) {
private List<ApplicationPermissionEntity> getAllApplicationPermissionEntitiesForApplication(final String applicationIdentifier) {
final Mapper<ApplicationPermissionEntity> entityMapper = tenantAwareCassandraMapperProvider.getMapper(ApplicationPermissionEntity.class);
final Session tenantSession = cassandraSessionProvider.getTenantSession();

@@ -93,4 +93,13 @@ public void delete(final String applicationIdentifier, final String permittableG
final Optional<ApplicationPermissionEntity> toDelete = tenantAwareEntityTemplate.findById(ApplicationPermissionEntity.class, applicationIdentifier, permittableGroupIdentifier);
toDelete.ifPresent(tenantAwareEntityTemplate::delete);
}
}

public Optional<PermissionType> getPermissionForApplication(
final String applicationIdentifier,
final String permittableEndpointGroupIdentifier) {

return tenantAwareEntityTemplate
.findById(ApplicationPermissionEntity.class, applicationIdentifier, permittableEndpointGroupIdentifier)
.map(ApplicationPermissionEntity::getPermission);
}
}
@@ -64,6 +64,13 @@ public List<Permission> getAllPermissionsForApplication(final String application
.collect(Collectors.toList());
}

public Optional<Permission> getPermissionForApplication(
final String applicationIdentifier,
final String permittableEndpointGroupIdentifier) {
return applicationPermissionsRepository.getPermissionForApplication(applicationIdentifier, permittableEndpointGroupIdentifier)
.map(PermissionMapper::mapToPermission);
}

public Optional<Signature> getSignatureForApplication(final String applicationIdentifier, final String timestamp) {
return applicationSignaturesRepository.get(applicationIdentifier, timestamp)
.map(SignatureMapper::mapToSignature);
@@ -128,6 +128,19 @@ public ApplicationRestController(
return ResponseEntity.ok(service.getAllPermissionsForApplication(applicationIdentifier));
}

@RequestMapping(value = "/{applicationidentifier}/permissions/{permissionidentifier}", method = RequestMethod.GET,
consumes = {MediaType.ALL_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})
@Permittable(value = AcceptedTokenType.SYSTEM)
public @ResponseBody
ResponseEntity<Permission>getApplicationPermission(@PathVariable("applicationidentifier") String applicationIdentifier,
@PathVariable("permissionidentifier") String permittableEndpointGroupIdentifier) {
return service.getPermissionForApplication(applicationIdentifier, permittableEndpointGroupIdentifier)
.map(ResponseEntity::ok)
.orElseThrow(() -> ServiceException.notFound("Application permission '"
+ applicationIdentifier + "." + permittableEndpointGroupIdentifier + "' doesn't exist."));
}

@RequestMapping(value = "/{applicationidentifier}/permissions/{permissionidentifier}", method = RequestMethod.DELETE,
consumes = {MediaType.ALL_VALUE},
produces = {MediaType.APPLICATION_JSON_VALUE})

0 comments on commit 4d67819

Please sign in to comment.