Skip to content
Permalink
Browse files
Improved logging, and identity access.
  • Loading branch information
mifosio-04-04-2018 committed Jun 1, 2017
1 parent 82481c6 commit 2f2b1e0a2770c38c4864095c5ad569a1da2b54ce
Showing 2 changed files with 12 additions and 2 deletions.
@@ -25,9 +25,12 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;

/**
* @author Myrle Krantz
*/
@@ -40,5 +43,6 @@ public interface ApplicationPermissionRequestCreator {
produces = {MediaType.ALL_VALUE})
@ThrowsException(status = HttpStatus.CONFLICT, exception = ApplicationPermissionAlreadyExistsException.class)
@Permittable(groupId = io.mifos.identity.api.v1.PermittableGroupIds.APPLICATION_SELF_MANAGEMENT)
void createApplicationPermission(@PathVariable("applicationidentifier") String applicationIdentifier, Permission permission);
void createApplicationPermission(@PathVariable("applicationidentifier") String applicationIdentifier,
@RequestBody @Valid Permission permission);
}
@@ -89,19 +89,25 @@ public BeatPublisherService(
public Optional<String> requestPermissionForBeats(final String tenantIdentifier, final String applicationIdentifier) {
try (final AutoTenantContext ignored = new AutoTenantContext(tenantIdentifier)) {
try (final AutoUserContext ignored2 = new AutoUserContext(properties.getUser(), "")) {
logger.info("Requesting permission to send beats to application '{}' under tenant '{}'.", applicationIdentifier, tenantIdentifier);

final String consumerPermittableGroupIdentifier = PermittableGroupIds.forApplication(applicationIdentifier);
final Permission publishBeatPermission = new Permission();
publishBeatPermission.setAllowedOperations(Collections.singleton(AllowedOperation.CHANGE));
publishBeatPermission.setPermittableEndpointGroupIdentifier(consumerPermittableGroupIdentifier);
try {
applicationPermissionRequestCreator.createApplicationPermission(rhythmApplicationName.toString(), publishBeatPermission);
}
catch (final ApplicationPermissionAlreadyExistsException ignored3) { }
catch (final ApplicationPermissionAlreadyExistsException e) {
logger.debug("Failed to request permission for application {}, in tenant {} because the request already exists. {} was thrown.", applicationIdentifier, tenantIdentifier, e);
}

logger.debug("Successfully requested permission to send beats to application '{}' under tenant '{}'.", applicationIdentifier, tenantIdentifier);
return Optional.of(consumerPermittableGroupIdentifier);
}
}
catch (final Throwable e) {
logger.warn("Failed to request permission for application {}, in tenant {}.", applicationIdentifier, tenantIdentifier, e);
return Optional.empty();
}
}

0 comments on commit 2f2b1e0

Please sign in to comment.