use of org.wso2.carbon.identity.application.common.model.IdentityProvider in project carbon-apimgt by wso2.
the class APIAdminImpl method updateClaims.
private void updateClaims(IdentityProvider idp, Object claims) {
if (claims != null) {
ClaimConfig claimConfig = new ClaimConfig();
List<ClaimMapping> claimMappings = new ArrayList<>();
List<org.wso2.carbon.identity.application.common.model.Claim> idpClaims = new ArrayList<>();
JsonArray claimArray = (JsonArray) claims;
claimConfig.setLocalClaimDialect(false);
for (JsonElement claimMappingEntry : claimArray) {
if (claimMappingEntry instanceof JsonObject) {
JsonElement idpClaimUri = ((JsonObject) claimMappingEntry).get("remoteClaim");
JsonElement localClaimUri = ((JsonObject) claimMappingEntry).get("localClaim");
ClaimMapping internalMapping = new ClaimMapping();
org.wso2.carbon.identity.application.common.model.Claim remoteClaim = new org.wso2.carbon.identity.application.common.model.Claim();
remoteClaim.setClaimUri(idpClaimUri.getAsString());
org.wso2.carbon.identity.application.common.model.Claim localClaim = new org.wso2.carbon.identity.application.common.model.Claim();
localClaim.setClaimUri(localClaimUri.getAsString());
internalMapping.setRemoteClaim(remoteClaim);
internalMapping.setLocalClaim(localClaim);
claimMappings.add(internalMapping);
idpClaims.add(remoteClaim);
}
}
claimConfig.setClaimMappings(claimMappings.toArray(new ClaimMapping[0]));
claimConfig.setIdpClaims(idpClaims.toArray(new org.wso2.carbon.identity.application.common.model.Claim[0]));
idp.setClaimConfig(claimConfig);
}
}
use of org.wso2.carbon.identity.application.common.model.IdentityProvider in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIIdentityProviderException.
@Test(description = "IdentityProviderException when updating API when getting permissions of logged in user")
public void testUpdateAPIIdentityProviderException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(ALTERNATIVE_USER, identityProvider, apiDAO);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
Mockito.when(identityProvider.getIdOfUser(ALTERNATIVE_USER)).thenThrow(IdentityProviderException.class);
try {
apiPublisher.updateAPI(api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while calling SCIM endpoint to retrieve user " + ALTERNATIVE_USER + "'s information");
}
//
}
use of org.wso2.carbon.identity.application.common.model.IdentityProvider in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIException.
@Test(description = "Exception when updating API")
public void testUpdateAPIException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy apiPolicy = new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY);
apiPolicy.setUuid(UUID.randomUUID().toString());
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(apiPolicy);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
// APIMgtDAOException
Mockito.doThrow(new APIMgtDAOException("Error occurred while updating the API - " + api.getName())).when(apiDAO).updateAPI(uuid, api.build());
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
try {
apiPublisher.updateAPI(api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while updating the API - " + api.getName());
}
// ParseException
try {
apiPublisher.updateAPI(api.apiPermission("data{{]"));
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while parsing the permission json from swagger - " + api.getName());
}
// GatewayException
Mockito.doThrow(GatewayException.class).when(gateway).updateAPI(api.apiPermission("").build());
try {
apiPublisher.updateAPI(api.apiPermission(""));
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while updating API - " + api.getName() + " in gateway");
}
// Error path
// When Parse Exception is thrown during getAPIByUUID - replacing group ids with names
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.apiPermission("data{{]").build());
try {
apiPublisher.updateAPI(api.apiPermission("data{{]"));
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while parsing the permission json string for API " + api.getName());
}
}
use of org.wso2.carbon.identity.application.common.model.IdentityProvider in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWithContextChange.
@Test(description = "Test UpdateAPI with context changed")
public void testUpdateAPIWithContextChange() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO);
API.APIBuilder api = SampleTestObjectCreator.createDefaultAPI();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api.build());
Mockito.when(identityProvider.getRoleId(ADMIN_ROLE)).thenReturn(ADMIN_ROLE_ID);
Mockito.when(identityProvider.getRoleId(DEVELOPER_ROLE)).thenReturn(DEVELOPER_ROLE_ID);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
apiPublisher.updateAPI(api.context("test"));
Mockito.verify(apiDAO, Mockito.times(1)).updateAPI(uuid, api.context("test").build());
}
use of org.wso2.carbon.identity.application.common.model.IdentityProvider in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateDedicatedGateway.
@Test(description = "Update dedicated gateway")
public void testUpdateDedicatedGateway() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + uuid;
Mockito.when(labelDAO.getLabelByName(autoGenLabelName)).thenReturn(null);
Mockito.when(labelDAO.getLabelIdByNameAndType(Mockito.anyString(), Mockito.anyString())).thenReturn(UUID.randomUUID().toString());
APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, labelDAO, gatewaySourceGenerator);
DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, true, api.getCreatedBy());
apiPublisher.updateDedicatedGateway(dedicatedGateway);
Mockito.verify(labelDAO, Mockito.times(1)).addLabels(Mockito.anyList());
}
Aggregations