use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class DefaultIdentityProviderImplTestCase method testGetRoleIdsOfUser.
@Test
public void testGetRoleIdsOfUser() throws Exception {
SCIMServiceStub scimServiceStub = Mockito.mock(SCIMServiceStub.class);
UserNameMapper userNameMapper = Mockito.mock(UserNameMapperImpl.class);
DefaultIdentityProviderImpl idpImpl = new DefaultIdentityProviderImpl(scimServiceStub, userNameMapper);
String validUserId = "a42b4760-120d-432e-8042-4a7f12e3346c";
String roleName1 = "subscriber";
String roleId1 = "fb5aaf9c-1fdf-4b2d-86bc-6e3203b99618";
String roleName2 = "manager";
String roleId2 = "097435bc-c460-402b-9137-8ab65fd28c3e";
String roleName3 = "engineer";
String roleId3 = "ac093278-9343-466c-8a71-af47921a575b";
List<String> roleIds = new ArrayList<>();
roleIds.add(roleId1);
roleIds.add(roleId2);
roleIds.add(roleId3);
String successResponseBody = "{\"emails\":[{\"type\":\"home\",\"value\":\"john_home.com\"},{\"type\":\"work\"" + ",\"value\":\"john_work.com\"}],\"meta\":{\"created\":\"2017-06-02T10:12:26\",\"location\":" + "\"https://localhost:9443/wso2/scim/Users/" + validUserId + "\",\"lastModified\":" + "\"2017-06-02T10:12:26\"},\"schemas\":[\"urn:scim:schemas:core:1.0\"],\"name\":{\"familyName\":" + "\"Smith\",\"givenName\":\"John\"},\"groups\":[{\"display\":\"" + roleName1 + "\",\"value\":\"" + roleId1 + "\"},{\"display\":\"" + roleName2 + "\",\"value\":\"" + roleId2 + "\"},{\"display\":\"" + roleName3 + "\",\"value\":\"" + roleId3 + "\"}],\"id\":\"" + validUserId + "\",\"userName\":" + "\"John\"}";
Response successfulResponse = Response.builder().status(APIMgtConstants.HTTPStatusCodes.SC_200_OK).headers(new HashMap<>()).body(successResponseBody.getBytes()).build();
Mockito.when(scimServiceStub.getUser(validUserId)).thenReturn(successfulResponse);
List<String> roles = idpImpl.getRoleIdsOfUser(validUserId);
Assert.assertEquals(roleIds.size(), roles.size());
roles.forEach(roleId -> Assert.assertTrue(roleIds.contains(roleId)));
// Error case - When response is null
String invalidUserIdResponseNull = "invalidUserId_Response_Null";
Mockito.when(scimServiceStub.getUser(invalidUserIdResponseNull)).thenReturn(null);
try {
idpImpl.getRoleIdsOfUser(invalidUserIdResponseNull);
} catch (IdentityProviderException ex) {
Assert.assertEquals(ex.getMessage(), "Error occurred while retrieving user with Id " + invalidUserIdResponseNull + ". Error : Response is null.");
}
// Error case - When the request did not return a 200 OK response
String invalidUserIdNot200OK = "invalidUserId_Not_200_OK";
String errorResponseBody = "{\"Errors\":[{\"code\":\"404\",\"description\":\"User not found in the user " + "store.\"}]}";
Response errorResponse = Response.builder().status(APIMgtConstants.HTTPStatusCodes.SC_404_NOT_FOUND).headers(new HashMap<>()).body(errorResponseBody.getBytes()).build();
Mockito.when(scimServiceStub.getUser(invalidUserIdNot200OK)).thenReturn(errorResponse);
try {
idpImpl.getRoleIdsOfUser(invalidUserIdNot200OK);
} catch (IdentityProviderException ex) {
Assert.assertEquals(ex.getMessage(), "Error occurred while retrieving role Ids of user with Id " + invalidUserIdNot200OK + ". Error : User not found in the user store.");
}
// Error case - When response body is empty
String invalidUserIdResponseEmpty = "invalidUserId_Response_Empty";
Response emptyResponse = Response.builder().status(APIMgtConstants.HTTPStatusCodes.SC_200_OK).headers(new HashMap<>()).body("".getBytes()).build();
Mockito.when(scimServiceStub.getUser(invalidUserIdResponseEmpty)).thenReturn(emptyResponse);
try {
idpImpl.getRoleIdsOfUser(invalidUserIdResponseEmpty);
} catch (IdentityProviderException ex) {
Assert.assertEquals(ex.getMessage(), "Error occurred while retrieving user with user Id " + invalidUserIdResponseEmpty + " from SCIM endpoint. Response body is null or empty.");
}
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class NotificationTestCase method testNotificationExecutor.
@Test
public void testNotificationExecutor() throws Exception {
Properties properties = Mockito.mock(Properties.class);
NotificationDTO notificationDTO = Mockito.mock(NotificationDTO.class);
Mockito.when(notificationDTO.getTitle()).thenReturn("Title");
Mockito.when(notificationDTO.getType()).thenReturn("ApiNewVersion");
Mockito.when(notificationDTO.getMessage()).thenReturn("Message");
Mockito.when(notificationDTO.getProperties()).thenReturn(properties);
APIMConfigurations apimConfigurations = Mockito.mock(APIMConfigurations.class);
NotificationConfigurations notificationConfigurations = Mockito.mock(NotificationConfigurations.class);
PowerMockito.mockStatic(APIMConfigurations.class);
PowerMockito.when(apimConfigurations.getNotificationConfigurations()).thenReturn(notificationConfigurations);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
Set subscriber = new HashSet();
subscriber.add("User");
Mockito.when((Set<String>) notificationDTO.getProperty(NotifierConstants.SUBSCRIBERS_PER_API)).thenReturn(subscriber);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
PowerMockito.when(apiManagerFactory.getIdentityProvider()).thenReturn(identityProvider);
PowerMockito.when(identityProvider.getIdOfUser("User")).thenReturn("1111");
PowerMockito.when(identityProvider.getEmailOfUser("1111")).thenReturn("admin@gmail.com");
new NotificationExecutor().sendAsyncNotifications(notificationDTO);
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class AbstractAPIManager method addSubscriber.
public void addSubscriber(String username, String groupingId) throws APIManagementException {
Subscriber subscriber = new Subscriber(username);
subscriber.setSubscribedDate(new Date());
try {
int tenantId = getTenantManager().getTenantId(getTenantDomain(username));
subscriber.setEmail(StringUtils.EMPTY);
subscriber.setTenantId(tenantId);
apiMgtDAO.addSubscriber(subscriber, groupingId);
if (APIUtil.isDefaultApplicationCreationEnabled() && !APIUtil.isDefaultApplicationCreationDisabledForTenant(getTenantDomain(username))) {
// Add a default application once subscriber is added
addDefaultApplicationForSubscriber(subscriber);
}
} catch (APIManagementException e) {
String msg = "Error while adding the subscriber " + subscriber.getName();
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Error while adding the subscriber " + subscriber.getName();
throw new APIManagementException(msg, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class SubscriptionCreationApprovalWorkflowExecutor method execute.
/**
* Execute the Application Creation workflow approval process.
*
* @param workflowDTO
*/
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing Subscription Creation Webservice Workflow.. ");
}
SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
String message = "Approve API " + subsWorkflowDTO.getApiName() + " - " + subsWorkflowDTO.getApiVersion() + " subscription creation request from subscriber - " + subsWorkflowDTO.getSubscriber() + " for the application - " + subsWorkflowDTO.getApplicationName();
workflowDTO.setWorkflowDescription(message);
workflowDTO.setProperties("apiName", subsWorkflowDTO.getApiName());
workflowDTO.setProperties("apiVersion", subsWorkflowDTO.getApiVersion());
workflowDTO.setProperties("subscriber", subsWorkflowDTO.getSubscriber());
workflowDTO.setProperties("applicationName", subsWorkflowDTO.getApplicationName());
super.execute(workflowDTO);
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class PersistenceHelper method getSampleAPIArtifactForTenant.
public static GenericArtifact getSampleAPIArtifactForTenant() throws GovernanceException {
GenericArtifact artifact = new GenericArtifactImpl(new QName("", "PizzaShackAPI", ""), "application/vnd.wso2-api+xml");
artifact.setAttribute("overview_endpointSecured", "false");
artifact.setAttribute("overview_transports", "http,https");
artifact.setAttribute("URITemplate_authType3", "Application & Application User");
artifact.setAttribute("overview_wadl", null);
artifact.setAttribute("URITemplate_authType4", "Application & Application User");
artifact.setAttribute("overview_authorizationHeader", "Authorization");
artifact.setAttribute("URITemplate_authType1", "Application & Application User");
artifact.setAttribute("overview_visibleTenants", null);
artifact.setAttribute("URITemplate_authType2", "Application & Application User");
artifact.setAttribute("overview_wsdl", null);
artifact.setAttribute("overview_apiSecurity", "oauth2,oauth_basic_auth_api_key_mandatory");
artifact.setAttribute("URITemplate_authType0", "Application & Application User");
artifact.setAttribute("overview_keyManagers", "[\"all\"]");
artifact.setAttribute("overview_environments", "Default");
artifact.setAttribute("overview_context", "/t/wso2.com/pizzashack/1.0.0");
artifact.setAttribute("overview_visibility", "restricted");
artifact.setAttribute("overview_isLatest", "true");
artifact.setAttribute("overview_outSequence", "log_out_message");
artifact.setAttribute("overview_provider", "admin-AT-wso2.com");
artifact.setAttribute("apiCategories_categoryName", "testcategory");
artifact.setAttribute("overview_thumbnail", "/t/wso2.com/t/wso2.com/registry/resource/_system/governance/apimgt/applicationdata/provider/admin-AT-wso2.com/PizzaShackAPI/1.0.0/icon");
artifact.setAttribute("overview_contextTemplate", "/t/wso2.com/pizzashack/{version}");
artifact.setAttribute("overview_description", "This is a simple API for Pizza Shack online pizza delivery store.");
artifact.setAttribute("overview_technicalOwner", "John Doe");
artifact.setAttribute("overview_type", "HTTP");
artifact.setAttribute("overview_technicalOwnerEmail", "architecture@pizzashack.com");
artifact.setAttribute("URITemplate_httpVerb4", "DELETE");
artifact.setAttribute("overview_inSequence", "log_in_message");
artifact.setAttribute("URITemplate_httpVerb2", "GET");
artifact.setAttribute("URITemplate_httpVerb3", "PUT");
artifact.setAttribute("URITemplate_httpVerb0", "POST");
artifact.setAttribute("URITemplate_httpVerb1", "GET");
artifact.setAttribute("labels_labelName", "gwlable");
artifact.setAttribute("overview_businessOwner", "Jane Roe");
artifact.setAttribute("overview_version", "1.0.0");
artifact.setAttribute("overview_endpointConfig", "{\"endpoint_type\":\"http\",\"sandbox_endpoints\":{\"url\":\"https://localhost:9443/am/sample/pizzashack/v1/api/\"}," + "\"endpoint_security\":{\"production\":{\"password\":\"admin\",\"tokenUrl\":null,\"clientId\":null," + "\"clientSecret\":null,\"customParameters\":\"{}\",\"additionalProperties\":{},\"type\":\"BASIC\"," + "\"grantType\":null,\"enabled\":true,\"uniqueIdentifier\":null,\"username\":\"admin\"}," + "\"sandbox\":{\"password\":null,\"tokenUrl\":null,\"clientId\":null,\"clientSecret\":null," + "\"customParameters\":\"{}\",\"additionalProperties\":{},\"type\":null,\"grantType\":null,\"enabled\":false," + "\"uniqueIdentifier\":null,\"username\":null}},\"production_endpoints\":" + "{\"url\":\"https://localhost:9443/am/sample/pizzashack/v1/api/\"}}");
artifact.setAttribute("overview_tier", "Bronze||Silver||Gold||Unlimited");
artifact.setAttribute("overview_sandboxTps", "1000");
artifact.setAttribute("overview_apiOwner", "admin@wso2.com");
artifact.setAttribute("overview_businessOwnerEmail", "marketing@pizzashack.com");
artifact.setAttribute("isMonetizationEnabled", "false");
artifact.setAttribute("overview_implementation", "ENDPOINT");
artifact.setAttribute("overview_deployments", "null");
artifact.setAttribute("overview_redirectURL", null);
artifact.setAttribute("monetizationProperties", "{}");
artifact.setAttribute("overview_name", "PizzaShackAPI");
artifact.setAttribute("overview_subscriptionAvailability", "current_tenant");
artifact.setAttribute("overview_productionTps", "1000");
artifact.setAttribute("overview_cacheTimeout", "300");
artifact.setAttribute("overview_visibleRoles", "admin,internal/subscriber");
artifact.setAttribute("overview_testKey", null);
artifact.setAttribute("overview_corsConfiguration", "{\"corsConfigurationEnabled\":true,\"accessControlAllowOrigins\":[\"*\"]," + "\"accessControlAllowCredentials\":false,\"accessControlAllowHeaders\":[\"authorization\"," + "\"Access-Control-Allow-Origin\",\"Content-Type\",\"SOAPAction\",\"apikey\",\"testKey\"]," + "\"accessControlAllowMethods\":[\"GET\",\"PUT\",\"POST\",\"DELETE\",\"PATCH\",\"OPTIONS\"]}");
artifact.setAttribute("overview_advertiseOnly", "false");
artifact.setAttribute("overview_versionType", "context");
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setAttribute("overview_endpointPpassword", null);
artifact.setAttribute("overview_tenants", null);
artifact.setAttribute("overview_endpointAuthDigest", "false");
artifact.setAttribute("overview_faultSequence", "json_fault");
artifact.setAttribute("overview_responseCaching", "Enabled");
artifact.setAttribute("URITemplate_urlPattern4", "/order/{orderId}");
artifact.setAttribute("overview_isDefaultVersion", "true");
artifact.setAttribute("URITemplate_urlPattern2", "/order/{orderId}");
artifact.setAttribute("URITemplate_urlPattern3", "/order/{orderId}");
artifact.setAttribute("URITemplate_urlPattern0", "/order");
artifact.setAttribute("URITemplate_urlPattern1", "/menu");
artifact.setAttribute("overview_enableStore", "true");
artifact.setAttribute("overview_enableSchemaValidation", "true");
artifact.setAttribute("overview_endpointUsername", null);
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setId("88e758b7-6924-4e9f-8882-431070b6492b");
return artifact;
}
Aggregations