Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Implementing application call endpoint sets.
Browse files Browse the repository at this point in the history
  • Loading branch information
mifosio-04-04-2018 committed May 1, 2017
1 parent 9a1adb3 commit d7c8a19
Show file tree
Hide file tree
Showing 17 changed files with 923 additions and 19 deletions.
Expand Up @@ -168,6 +168,35 @@ Signature getApplicationSignature(@PathVariable("applicationidentifier") String
void deleteApplicationPermission(@PathVariable("applicationidentifier") String applicationIdentifier,
@PathVariable("permissionidentifier") String permittableEndpointGroupIdentifier);

@RequestMapping(value = "/applications/{applicationidentifier}/callendpointset", method = RequestMethod.POST,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
void createApplicationCallEndpointSet(@PathVariable("applicationidentifier") String applicationIdentifier, CallEndpointSet callEndpointSet);

@RequestMapping(value = "/applications/{applicationidentifier}/callendpointset/{callendpointsetidentifier}", method = RequestMethod.PUT,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
void changeApplicationCallEndpointSet(@PathVariable("applicationidentifier") String applicationIdentifier,
@PathVariable("callendpointsetidentifier") String callEndpointSetIdentifier,
CallEndpointSet callEndpointSet);

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

@RequestMapping(value = "/applications/{applicationidentifier}/callendpointset/{callendpointsetidentifier}", method = RequestMethod.GET,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
CallEndpointSet getApplicationCallEndpointSet(@PathVariable("applicationidentifier") String applicationIdentifier,
@PathVariable("callendpointsetidentifier") String callEndpointSetIdentifier);

@RequestMapping(value = "/applications/{applicationidentifier}/callendpointset/{callendpointsetidentifier}", method = RequestMethod.DELETE,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
void deleteApplicationCallEndpointSet(@PathVariable("applicationidentifier") String applicationIdentifier,
@PathVariable("callendpointsetidentifier") String callEndpointSetIdentifier);

@RequestMapping(value = "/applications/{applicationidentifier}/permissions/{permissionidentifier}/users/{useridentifier}/enabled", method = RequestMethod.PUT,
consumes = {MediaType.APPLICATION_JSON_VALUE},
produces = {MediaType.ALL_VALUE})
Expand Down
@@ -0,0 +1,75 @@
/*
* 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.domain;

import io.mifos.core.lang.validation.constraints.ValidIdentifier;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

/**
* @author Myrle Krantz
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public class CallEndpointSet {
@ValidIdentifier
private String identifier;

@NotNull
private List<String> permittableEndpointGroupIdentifiers;

public CallEndpointSet() {
}

public String getIdentifier() {
return identifier;
}

public void setIdentifier(String identifier) {
this.identifier = identifier;
}

public List<String> getPermittableEndpointGroupIdentifiers() {
return permittableEndpointGroupIdentifiers;
}

public void setPermittableEndpointGroupIdentifiers(List<String> permittableEndpointGroupIdentifiers) {
this.permittableEndpointGroupIdentifiers = permittableEndpointGroupIdentifiers;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CallEndpointSet that = (CallEndpointSet) o;
return Objects.equals(identifier, that.identifier) &&
Objects.equals(permittableEndpointGroupIdentifiers, that.permittableEndpointGroupIdentifiers);
}

@Override
public int hashCode() {
return Objects.hash(identifier, permittableEndpointGroupIdentifiers);
}

@Override
public String toString() {
return "CallEndpointSet{" +
"identifier='" + identifier + '\'' +
", permittableEndpointGroupIdentifiers=" + permittableEndpointGroupIdentifiers +
'}';
}
}
@@ -0,0 +1,73 @@
/*
* 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.events;

import java.util.Objects;

/**
* @author Myrle Krantz
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class ApplicationCallEndpointSetEvent {
private String applicationIdentifier;
private String callEndpointSetIdentifier;

public ApplicationCallEndpointSetEvent() {
}

public ApplicationCallEndpointSetEvent(String applicationIdentifier, String callEndpointSetIdentifier) {
this.applicationIdentifier = applicationIdentifier;
this.callEndpointSetIdentifier = callEndpointSetIdentifier;
}

public String getApplicationIdentifier() {
return applicationIdentifier;
}

public void setApplicationIdentifier(String applicationIdentifier) {
this.applicationIdentifier = applicationIdentifier;
}

public String getCallEndpointSetIdentifier() {
return callEndpointSetIdentifier;
}

public void setCallEndpointSetIdentifier(String callEndpointSetIdentifier) {
this.callEndpointSetIdentifier = callEndpointSetIdentifier;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ApplicationCallEndpointSetEvent that = (ApplicationCallEndpointSetEvent) o;
return Objects.equals(applicationIdentifier, that.applicationIdentifier) &&
Objects.equals(callEndpointSetIdentifier, that.callEndpointSetIdentifier);
}

@Override
public int hashCode() {
return Objects.hash(applicationIdentifier, callEndpointSetIdentifier);
}

@Override
public String toString() {
return "ApplicationCallEndpointSetEvent{" +
"applicationIdentifier='" + applicationIdentifier + '\'' +
", callEndpointSetIdentifier='" + callEndpointSetIdentifier + '\'' +
'}';
}
}
Expand Up @@ -38,6 +38,9 @@ public interface EventConstants {

String OPERATION_PUT_APPLICATION_SIGNATURE = "put-application-signature";
String OPERATION_DELETE_APPLICATION = "delete-application";
String OPERATION_POST_APPLICATION_CALLENDPOINTSET = "post-application-callendpointset";
String OPERATION_PUT_APPLICATION_CALLENDPOINTSET = "put-application-callendpointset";
String OPERATION_DELETE_APPLICATION_CALLENDPOINTSET = "delete-application-callendpointset";
String OPERATION_POST_APPLICATION_PERMISSION = "post-application-permission";
String OPERATION_DELETE_APPLICATION_PERMISSION = "delete-application-permission";
String OPERATION_PUT_APPLICATION_PERMISSION_USER_ENABLED = "put-application-permission-user-enabled";
Expand All @@ -56,6 +59,9 @@ public interface EventConstants {

String SELECTOR_PUT_APPLICATION_SIGNATURE = OPERATION_HEADER + " = '" + OPERATION_PUT_APPLICATION_SIGNATURE + "'";
String SELECTOR_DELETE_APPLICATION = OPERATION_HEADER + " = '" + OPERATION_DELETE_APPLICATION + "'";
String SELECTOR_POST_APPLICATION_CALLENDPOINTSET = OPERATION_HEADER + " = '" + OPERATION_POST_APPLICATION_CALLENDPOINTSET + "'";
String SELECTOR_PUT_APPLICATION_CALLENDPOINTSET = OPERATION_HEADER + " = '" + OPERATION_PUT_APPLICATION_CALLENDPOINTSET + "'";
String SELECTOR_DELETE_APPLICATION_CALLENDPOINTSET = OPERATION_HEADER + " = '" + OPERATION_DELETE_APPLICATION_CALLENDPOINTSET + "'";
String SELECTOR_POST_APPLICATION_PERMISSION = OPERATION_HEADER + " = '" + OPERATION_POST_APPLICATION_PERMISSION + "'";
String SELECTOR_DELETE_APPLICATION_PERMISSION = OPERATION_HEADER + " = '" + OPERATION_DELETE_APPLICATION_PERMISSION + "'";
String SELECTOR_PUT_APPLICATION_PERMISSION_USER_ENABLED = OPERATION_HEADER + " = '" + OPERATION_PUT_APPLICATION_PERMISSION_USER_ENABLED + "'";
Expand Down
@@ -0,0 +1,62 @@
/*
* 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.domain;

import io.mifos.core.test.domain.ValidationTest;
import io.mifos.core.test.domain.ValidationTestCase;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
* @author Myrle Krantz
*/
@RunWith(Parameterized.class)
public class CallEndpointSetTest extends ValidationTest<CallEndpointSet> {

public CallEndpointSetTest(final ValidationTestCase<CallEndpointSet> testCase) {
super(testCase);
}

@Parameterized.Parameters
public static Collection testCases() {
final Collection<ValidationTestCase> ret = new ArrayList<>();

ret.add(new ValidationTestCase<CallEndpointSet>("validCase")
.adjustment(x -> {})
.valid(true));
ret.add(new ValidationTestCase<CallEndpointSet>("invalid identifier")
.adjustment(x -> x.setIdentifier(null))
.valid(false));
ret.add(new ValidationTestCase<CallEndpointSet>("null list")
.adjustment(x -> x.setPermittableEndpointGroupIdentifiers(null))
.valid(false));

return ret;
}

@Override
protected CallEndpointSet createValidTestSubject() {
final CallEndpointSet ret = new CallEndpointSet();
ret.setIdentifier("blah");
ret.setPermittableEndpointGroupIdentifiers(Collections.emptyList());
return ret;
}

}
56 changes: 52 additions & 4 deletions component-test/src/main/java/TestApplications.java
Expand Up @@ -20,11 +20,9 @@
import io.mifos.core.api.util.NotFoundException;
import io.mifos.core.lang.security.RsaKeyPairFactory;
import io.mifos.identity.api.v1.PermittableGroupIds;
import io.mifos.identity.api.v1.domain.CallEndpointSet;
import io.mifos.identity.api.v1.domain.Permission;
import io.mifos.identity.api.v1.events.ApplicationPermissionEvent;
import io.mifos.identity.api.v1.events.ApplicationPermissionUserEvent;
import io.mifos.identity.api.v1.events.ApplicationSignatureEvent;
import io.mifos.identity.api.v1.events.EventConstants;
import io.mifos.identity.api.v1.events.*;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -203,6 +201,56 @@ public void testApplicationPermissionUserApprovalProvisioning() throws Interrupt
//because neither of the users has the permission the user enabled for the application.
}

@Test
public void manageApplicationEndpointSet() throws InterruptedException {
try (final AutoUserContext ignored
= tenantApplicationSecurityEnvironment.createAutoSeshatContext()) {
final ApplicationSignatureEvent appPlusSig = setApplicationSignature();

final String endpointSetIdentifier = testEnvironment.generateUniqueIdentifer("epset");
final CallEndpointSet endpointSet = new CallEndpointSet();
endpointSet.setIdentifier(endpointSetIdentifier);
endpointSet.setPermittableEndpointGroupIdentifiers(Collections.emptyList());

getTestSubject().createApplicationCallEndpointSet(appPlusSig.getApplicationIdentifier(), endpointSet);

Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_POST_APPLICATION_CALLENDPOINTSET,
new ApplicationCallEndpointSetEvent(appPlusSig.getApplicationIdentifier(), endpointSetIdentifier)));

final List<CallEndpointSet> applicationEndpointSets = getTestSubject().getApplicationCallEndpointSets(appPlusSig.getApplicationIdentifier());
Assert.assertTrue(applicationEndpointSets.contains(endpointSet));

final CallEndpointSet storedEndpointSet = getTestSubject().getApplicationCallEndpointSet(
appPlusSig.getApplicationIdentifier(),
endpointSetIdentifier);
Assert.assertEquals(endpointSet, storedEndpointSet);

endpointSet.setPermittableEndpointGroupIdentifiers(Collections.singletonList(PermittableGroupIds.ROLE_MANAGEMENT));
getTestSubject().changeApplicationCallEndpointSet(
appPlusSig.getApplicationIdentifier(),
endpointSetIdentifier,
endpointSet);

Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_PUT_APPLICATION_CALLENDPOINTSET,
new ApplicationCallEndpointSetEvent(appPlusSig.getApplicationIdentifier(), endpointSetIdentifier)));

final CallEndpointSet storedEndpointSet2 = getTestSubject().getApplicationCallEndpointSet(
appPlusSig.getApplicationIdentifier(),
endpointSetIdentifier);
Assert.assertEquals(endpointSet, storedEndpointSet2);

final List<CallEndpointSet> applicationEndpointSets2 = getTestSubject().getApplicationCallEndpointSets(appPlusSig.getApplicationIdentifier());
Assert.assertTrue(applicationEndpointSets2.size() == 1);

getTestSubject().deleteApplicationCallEndpointSet(appPlusSig.getApplicationIdentifier(), endpointSetIdentifier);
Assert.assertTrue(eventRecorder.wait(EventConstants.OPERATION_DELETE_APPLICATION_CALLENDPOINTSET,
new ApplicationCallEndpointSetEvent(appPlusSig.getApplicationIdentifier(), endpointSetIdentifier)));

final List<CallEndpointSet> applicationEndpointSets3 = getTestSubject().getApplicationCallEndpointSets(appPlusSig.getApplicationIdentifier());
Assert.assertTrue(applicationEndpointSets3.isEmpty());
}
}

@Test
public void applicationIssuedRefreshTokenHappyCase() throws InterruptedException {
final ApplicationSignatureEvent appPlusSig;
Expand Down
Expand Up @@ -17,10 +17,7 @@

import io.mifos.core.lang.config.TenantHeaderFilter;
import io.mifos.core.test.listener.EventRecorder;
import io.mifos.identity.api.v1.events.ApplicationPermissionEvent;
import io.mifos.identity.api.v1.events.ApplicationPermissionUserEvent;
import io.mifos.identity.api.v1.events.ApplicationSignatureEvent;
import io.mifos.identity.api.v1.events.EventConstants;
import io.mifos.identity.api.v1.events.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.handler.annotation.Header;
Expand Down Expand Up @@ -95,4 +92,37 @@ public void onPutApplicationPermissionEnabledForUser(
final String payload) throws Exception {
eventRecorder.event(tenant, EventConstants.OPERATION_PUT_APPLICATION_PERMISSION_USER_ENABLED, payload, ApplicationPermissionUserEvent.class);
}
}

@JmsListener(
subscription = EventConstants.DESTINATION,
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_POST_APPLICATION_CALLENDPOINTSET
)
public void onCreateApplicationEndpointSet(
@Header(TenantHeaderFilter.TENANT_HEADER)final String tenant,
final String payload) throws Exception {
eventRecorder.event(tenant, EventConstants.OPERATION_POST_APPLICATION_CALLENDPOINTSET, payload, ApplicationCallEndpointSetEvent.class);
}

@JmsListener(
subscription = EventConstants.DESTINATION,
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_PUT_APPLICATION_CALLENDPOINTSET
)
public void onSetApplicationEndpointSet(
@Header(TenantHeaderFilter.TENANT_HEADER)final String tenant,
final String payload) throws Exception {
eventRecorder.event(tenant, EventConstants.OPERATION_PUT_APPLICATION_CALLENDPOINTSET, payload, ApplicationCallEndpointSetEvent.class);
}

@JmsListener(
subscription = EventConstants.DESTINATION,
destination = EventConstants.DESTINATION,
selector = EventConstants.SELECTOR_DELETE_APPLICATION_CALLENDPOINTSET
)
public void onDeleteApplicationEndpointSet(
@Header(TenantHeaderFilter.TENANT_HEADER)final String tenant,
final String payload) throws Exception {
eventRecorder.event(tenant, EventConstants.OPERATION_DELETE_APPLICATION_CALLENDPOINTSET, payload, ApplicationCallEndpointSetEvent.class);
}
}

0 comments on commit d7c8a19

Please sign in to comment.