use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class SAMLGroupIDExtractorImplTest method getGroupingIdentifiersTestCase.
@Test
public void getGroupingIdentifiersTestCase() throws ParserConfigurationException, IOException, SAXException, UnmarshallingException, UserStoreException {
SAMLGroupIDExtractorImpl samlGroupIDExtractor = new SAMLGroupIDExtractorImplWrapper();
Mockito.when(DocumentBuilderFactory.newInstance()).thenReturn(documentBuilderFactory);
Mockito.when(documentBuilderFactory.newDocumentBuilder()).thenReturn(documentBuilder);
Mockito.when(documentBuilder.parse(samlGroupIDExtractor.getByteArrayInputStream("test"))).thenReturn(document);
Mockito.when(document.getDocumentElement()).thenReturn(element);
PowerMockito.mockStatic(XMLObjectProviderRegistrySupport.class);
Response response = Mockito.mock(Response.class);
List<Assertion> assertion = new ArrayList();
Subject subject = Mockito.mock(Subject.class);
NameID nameID = Mockito.mock(NameID.class);
Assertion assertion1 = Mockito.mock(Assertion.class);
assertion.add(assertion1);
Mockito.when(XMLObjectProviderRegistrySupport.getUnmarshallerFactory()).thenReturn(unmarshallerFactory);
Mockito.when(unmarshallerFactory.getUnmarshaller(element)).thenReturn(unmarshaller);
Mockito.when(unmarshaller.unmarshall(element)).thenReturn(response);
Mockito.when(response.getAssertions()).thenReturn(assertion);
Mockito.when(assertion.get(0).getSubject()).thenReturn(subject);
Mockito.when(subject.getNameID()).thenReturn(nameID);
Mockito.when(nameID.getValue()).thenReturn("user");
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
APIManagerConfigurationService apiManagerConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfig = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigService);
Mockito.when(apiManagerConfigService.getAPIManagerConfiguration()).thenReturn(apiManagerConfig);
Mockito.when(apiManagerConfig.getFirstProperty(APIConstants.API_STORE_GROUP_EXTRACTOR_CLAIM_URI)).thenReturn("http://wso2.org/claims/organization");
Mockito.when(tenantManager.getTenantId("carbon.super")).thenReturn(1234);
Mockito.when(realmService.getTenantUserRealm(1234)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Mockito.when(userStoreManager.getUserClaimValue(MultitenantUtils.getTenantAwareUsername("user"), "http://wso2.org/claims/organization", null)).thenReturn("organization");
Assert.assertEquals("carbon.super/organization", samlGroupIDExtractor.getGroupingIdentifiers("test"));
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class TestUtils method mockAPIMConfiguration.
public static ServiceReferenceHolder mockAPIMConfiguration(String propertyName, String value, int tenantId) throws RegistryException, UserStoreException, XMLStreamException {
ServiceReferenceHolder sh = mockRegistryAndUserRealm(tenantId);
APIManagerConfigurationService amConfigService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration amConfig = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(sh.getAPIManagerConfigurationService()).thenReturn(amConfigService);
PowerMockito.when(amConfigService.getAPIManagerConfiguration()).thenReturn(amConfig);
PowerMockito.when(amConfig.getFirstProperty(propertyName)).thenReturn(value);
Map<String, Environment> apiGatewayEnvironments = new HashMap<String, Environment>();
Environment env1 = new Environment();
apiGatewayEnvironments.put("PROD", env1);
// Mocking some commonly used configs
PowerMockito.when(amConfig.getApiGatewayEnvironments()).thenReturn(apiGatewayEnvironments);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
PowerMockito.when(amConfig.getFirstProperty(APIConstants.API_PUBLISHER_ENABLE_API_DOC_VISIBILITY_LEVELS)).thenReturn("true", "false");
return sh;
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class APITemplateBuilderImpl method getVelocityLogger.
public String getVelocityLogger() {
if (this.velocityLogPath != null) {
return this.velocityLogPath;
} else {
APIManagerConfigurationService config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService();
String velocityLogPath = config.getAPIManagerConfiguration().getFirstProperty(APIConstants.VELOCITY_LOGGER);
if (velocityLogPath != null && velocityLogPath.length() > 1) {
this.velocityLogPath = velocityLogPath;
} else {
this.velocityLogPath = "not-defined";
}
return this.velocityLogPath;
}
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class RESTToSOAPMsgTemplate method getVelocityLogger.
private String getVelocityLogger() {
if (this.velocityLogPath != null) {
return this.velocityLogPath;
} else {
APIManagerConfigurationService config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService();
String velocityLogPath = config.getAPIManagerConfiguration().getFirstProperty(APIConstants.VELOCITY_LOGGER);
if (velocityLogPath != null && velocityLogPath.length() > 1) {
this.velocityLogPath = velocityLogPath;
} else {
this.velocityLogPath = SOAPToRESTConstants.Template.NOT_DEFINED;
}
return this.velocityLogPath;
}
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationService in project carbon-apimgt by wso2.
the class APITokenMgtServiceComponent method activate.
@Activate
protected void activate(ComponentContext ctxt) {
try {
TokenMgtDataHolder.initData();
listener = new KeyManagerUserOperationListener();
serviceRegistration = ctxt.getBundleContext().registerService(UserOperationEventListener.class.getName(), listener, null);
log.debug("Key Manager User Operation Listener is enabled.");
APIManagerConfigurationService configurationService = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService();
boolean accessTokenBindingEnable;
String firstProperty = configurationService.getAPIManagerConfiguration().getFirstProperty(APIConstants.AccessTokenBinding.ACCESS_TOKEN_BINDING_ENABLED);
if (firstProperty != null) {
accessTokenBindingEnable = Boolean.parseBoolean(firstProperty);
} else {
accessTokenBindingEnable = false;
}
if (!accessTokenBindingEnable) {
// registering logout token revoke listener
try {
SessionDataPublisherImpl dataPublisher = new SessionDataPublisherImpl();
ctxt.getBundleContext().registerService(AuthenticationDataPublisher.class.getName(), dataPublisher, null);
log.debug("SessionDataPublisherImpl bundle is activated");
} catch (Throwable e) {
log.error("SessionDataPublisherImpl bundle activation Failed", e);
}
}
} catch (Exception e) {
log.error("Failed to initialize key management service.", e);
}
}
Aggregations