use of org.wso2.carbon.apimgt.api.PasswordResolver in project carbon-apimgt by wso2.
the class APIManagerComponent method activate.
@Activate
protected void activate(ComponentContext componentContext) throws Exception {
if (log.isDebugEnabled()) {
log.debug("API manager component activated");
}
try {
BundleContext bundleContext = componentContext.getBundleContext();
addRxtConfigs();
addApplicationsPermissionsToRegistry();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String filePath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "api-manager.xml";
configuration.load(filePath);
String gatewayType = configuration.getFirstProperty(APIConstants.API_GATEWAY_TYPE);
if (APIConstants.API_GATEWAY_TYPE_SYNAPSE.equalsIgnoreCase(gatewayType)) {
addDefinedSequencesToRegistry();
}
CommonConfigDeployer configDeployer = new CommonConfigDeployer();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), configDeployer, null);
TenantLoadMessageSender tenantLoadMessageSender = new TenantLoadMessageSender();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), tenantLoadMessageSender, null);
KeyMgtConfigDeployer keyMgtConfigDeployer = new KeyMgtConfigDeployer();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), keyMgtConfigDeployer, null);
// Registering Notifiers
bundleContext.registerService(Notifier.class.getName(), new SubscriptionsNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApisNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApplicationNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApplicationRegistrationNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new PolicyNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new DeployAPIInGatewayNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ScopesNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new CertificateNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new GoogleAnalyticsNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ExternalGatewayNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ExternallyDeployedApiNotifier(), null);
APIManagerConfigurationServiceImpl configurationService = new APIManagerConfigurationServiceImpl(configuration);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(configurationService);
APIMgtDBUtil.initialize();
APIMConfigService apimConfigService = new APIMConfigServiceImpl();
bundleContext.registerService(APIMConfigService.class.getName(), apimConfigService, null);
APIUtil.loadAndSyncTenantConf(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadTenantExternalStoreConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadTenantGAConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadTenantWorkFlowExtensions(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
// load self sigup configuration to the registry
APIUtil.loadTenantSelfSignUpConfigurations(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadCommonOperationPolicies(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIManagerAnalyticsConfiguration analyticsConfiguration = APIManagerAnalyticsConfiguration.getInstance();
analyticsConfiguration.setAPIManagerConfiguration(configuration);
registration = componentContext.getBundleContext().registerService(APIManagerConfigurationService.class.getName(), configurationService, null);
KeyManagerConfigurationServiceImpl keyManagerConfigurationService = new KeyManagerConfigurationServiceImpl();
registration = componentContext.getBundleContext().registerService(KeyManagerConfigurationService.class, keyManagerConfigurationService, null);
JWTValidationService jwtValidationService = new JWTValidationServiceImpl();
registration = componentContext.getBundleContext().registerService(JWTValidationService.class, jwtValidationService, null);
ServiceReferenceHolder.getInstance().setKeyManagerConfigurationService(keyManagerConfigurationService);
APIStatusObserverList.getInstance().init(configuration);
log.debug("Reading Analytics Configuration from file...");
// This method is called in two places. Mostly by the time activate hits,
// ServiceDataPublisherAdmin is not activated. Therefore, this same method is run,
// when ServiceDataPublisherAdmin is set.
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_APIMGT_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_APPLICATION_DATA_LOCATION), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_GOVERNANCE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + "/trunk"), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_PUBLISHER_APIMGT_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_APPLICATION_DATA_LOCATION), APIConstants.Permissions.API_PUBLISH, UserMgtConstants.EXECUTE_ACTION, null);
// Enabling API Publishers/Creators to make changes on life-cycle history.
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_LIFECYCLE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_LIFE_CYCLE_HISTORY), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_PUBLISHER_LIFECYCLE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_LIFE_CYCLE_HISTORY), APIConstants.Permissions.API_PUBLISH, UserMgtConstants.EXECUTE_ACTION, null);
setupImagePermissions();
GatewayArtifactsMgtDBUtil.initialize();
configureEventPublisherProperties();
configureNotificationEventPublisher();
// Load initially available api contexts at the server startup. This Cache is only use by the products other than the api-manager
/* TODO: Load Config values from apimgt.core*/
boolean apiManagementEnabled = APIUtil.isAPIManagementEnabled();
boolean loadAPIContextsAtStartup = APIUtil.isLoadAPIContextsAtStartup();
if (apiManagementEnabled && loadAPIContextsAtStartup) {
List<String> contextList = ApiMgtDAO.getInstance().getAllAvailableContexts();
Cache contextCache = APIUtil.getAPIContextCache();
for (String context : contextList) {
contextCache.put(context, Boolean.TRUE);
}
}
try {
APIUtil.createDefaultRoles(MultitenantConstants.SUPER_TENANT_ID);
} catch (APIManagementException e) {
log.error("Failed create default roles for tenant " + MultitenantConstants.SUPER_TENANT_ID, e);
} catch (Exception e) {
// The generic Exception is handled explicitly so execution does not stop during config deployment
log.error("Exception when creating default roles for tenant " + MultitenantConstants.SUPER_TENANT_ID, e);
}
// Adding default throttle policies
addDefaultAdvancedThrottlePolicies();
// Update all NULL THROTTLING_TIER values to Unlimited
boolean isNullThrottlingTierConversionEnabled = APIUtil.updateNullThrottlingTierAtStartup();
try {
if (isNullThrottlingTierConversionEnabled) {
ApiMgtDAO.getInstance().convertNullThrottlingTiers();
}
} catch (APIManagementException e) {
log.error("Failed to convert NULL THROTTLING_TIERS to Unlimited");
}
// // Initialise KeyManager.
// KeyManagerHolder.initializeKeyManager(configuration);
// Initialise sql constants
SQLConstantManagerFactory.initializeSQLConstantManager();
// Initialize PasswordResolver
PasswordResolverFactory.initializePasswordResolver();
APIUtil.init();
// Activating UserPostSelfRegistration handler componeAPITemplateBuilderImplnt
try {
registration = componentContext.getBundleContext().registerService(AbstractEventHandler.class.getName(), new UserPostSelfRegistrationHandler(), null);
} catch (Exception e) {
log.error("Error while activating UserPostSelfRegistration handler component.", e);
}
// Read the trust store
ServerConfiguration config = CarbonUtils.getServerConfiguration();
// Initialize product REST API token caches
CacheProvider.createRESTAPITokenCache();
CacheProvider.createRESTAPIInvalidTokenCache();
CacheProvider.createGatewayJWTTokenCache();
CacheProvider.createTenantConfigCache();
CacheProvider.createRecommendationsCache();
CacheProvider.createParsedSignJWTCache();
CacheProvider.createGatewayBasicAuthResourceCache();
CacheProvider.createGatewayUsernameCache();
CacheProvider.createIntrospectionCache();
// Initialize Recommendation wso2event output publisher
configureRecommendationEventPublisherProperties();
setupAccessTokenGenerator();
retrieveAndSetParentTrustStore();
if (configuration.getGatewayArtifactSynchronizerProperties().isRetrieveFromStorageEnabled()) {
if (APIConstants.GatewayArtifactSynchronizer.DB_RETRIEVER_NAME.equals(configuration.getGatewayArtifactSynchronizerProperties().getRetrieverName())) {
bundleContext.registerService(ArtifactRetriever.class.getName(), new DBRetriever(), null);
}
}
bundleContext.registerService(ScopeValidator.class, new SystemScopesIssuer(), null);
} catch (APIManagementException e) {
log.error("Error while initializing the API manager component", e);
} catch (APIManagerDatabaseException e) {
log.fatal("Error while Creating the database", e);
}
}
use of org.wso2.carbon.apimgt.api.PasswordResolver in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetSelfSignupConfigFromRegistryTenant.
@Test
public void testGetSelfSignupConfigFromRegistryTenant() throws Exception {
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(apimConfigService.getSelfSighupConfig("bar.com")).thenReturn("wsdl");
OMElement omElement = Mockito.mock(OMElement.class);
Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement);
PowerMockito.mockStatic(AXIOMUtil.class);
Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class));
PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement);
PowerMockito.mockStatic(PasswordResolverFactory.class);
PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class);
PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver);
UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("bar.com");
Assert.assertNotNull(userRegistrationConfigDTO);
}
use of org.wso2.carbon.apimgt.api.PasswordResolver in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetSelfSignupConfigFromRegistry.
@Test
public void testGetSelfSignupConfigFromRegistry() throws Exception {
System.setProperty(CARBON_HOME, "");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("foo.com");
Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE)).thenReturn(registry);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(apimConfigService.getSelfSighupConfig("foo.com")).thenReturn("wsdl");
OMElement omElement = Mockito.mock(OMElement.class);
Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement);
PowerMockito.mockStatic(AXIOMUtil.class);
Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class));
PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement);
PowerMockito.mockStatic(PasswordResolverFactory.class);
PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class);
PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver);
UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("foo.com");
Assert.assertNotNull(userRegistrationConfigDTO);
}
use of org.wso2.carbon.apimgt.api.PasswordResolver in project carbon-apimgt by wso2.
the class SelfSignUpUtil method getSignupConfigurationFromRegistry.
/**
* load configuration from the registry
*
* @param tenantDomain - The Tenant Domain
* @return - A UserRegistrationConfigDTO instance
* @throws APIManagementException
*/
private static UserRegistrationConfigDTO getSignupConfigurationFromRegistry(String tenantDomain) throws APIManagementException {
UserRegistrationConfigDTO config;
try {
String selfSighupConfig = ServiceReferenceHolder.getInstance().getApimConfigService().getSelfSighupConfig(tenantDomain);
OMElement element = AXIOMUtil.stringToOM(selfSighupConfig);
config = new UserRegistrationConfigDTO();
config.setSignUpDomain(element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_DOMAIN_ELEM)).getText());
config.setAdminUserName(APIUtil.replaceSystemProperty(element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_USERNAME)).getText()));
String encryptedPassword = element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_PASSWORD)).getText();
PasswordResolver passwordResolver = PasswordResolverFactory.getInstance();
String resovledPassword = passwordResolver.getPassword(encryptedPassword);
config.setAdminPassword(APIUtil.replaceSystemProperty(resovledPassword));
config.setSignUpEnabled(Boolean.parseBoolean(element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ENABLED)).getText()));
OMElement rolesElement = element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ROLES_ELEM));
Iterator roleListIterator = rolesElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM);
while (roleListIterator.hasNext()) {
OMElement roleElement = (OMElement) roleListIterator.next();
String tmpRole = roleElement.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ROLE_NAME_ELEMENT)).getText();
boolean tmpIsExternal = Boolean.parseBoolean(roleElement.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ROLE_IS_EXTERNAL)).getText());
config.getRoles().put(tmpRole, tmpIsExternal);
}
} catch (XMLStreamException e) {
throw new APIManagementException("Error while parsing configuration ", e);
}
return config;
}
use of org.wso2.carbon.apimgt.api.PasswordResolver in project carbon-apimgt by wso2.
the class APIUtil method getExternalStores.
/**
* Returns a set of External API Stores as defined in the underlying governance
* registry.
*
* @return a Map of tier names and Tier objects - possibly empty
* @throws APIManagementException if an error occurs when loading tiers from the registry
*/
public static Set<APIStore> getExternalStores(int tenantId) throws APIManagementException {
// First checking if ExternalStores are defined in api-manager.xml
Set<APIStore> externalAPIStores = getGlobalExternalStores();
// If defined, return Store Config provided there.
if (externalAPIStores != null && !externalAPIStores.isEmpty()) {
return externalAPIStores;
}
// Else Read the config from Tenant's Registry.
externalAPIStores = new HashSet<>();
try {
Iterator apiStoreIterator = getExternalStoresIteratorFromConfig(tenantId);
if (apiStoreIterator != null) {
while (apiStoreIterator.hasNext()) {
APIStore store = new APIStore();
OMElement storeElem = (OMElement) apiStoreIterator.next();
String type = storeElem.getAttributeValue(new QName(APIConstants.EXTERNAL_API_STORE_TYPE));
String className = storeElem.getAttributeValue(new QName(APIConstants.EXTERNAL_API_STORE_CLASS_NAME));
store.setPublisher((APIPublisher) getClassInstance(className));
// Set Store type [eg:wso2]
store.setType(type);
String name = storeElem.getAttributeValue(new QName(APIConstants.EXTERNAL_API_STORE_ID));
if (name == null) {
log.error("The ExternalAPIStore name attribute is not defined in external-api-stores.xml.");
}
// Set store name
store.setName(name);
OMElement configDisplayName = storeElem.getFirstChildWithName(new QName(APIConstants.EXTERNAL_API_STORE_DISPLAY_NAME));
String displayName = (configDisplayName != null) ? replaceSystemProperty(configDisplayName.getText()) : name;
// Set store display name
store.setDisplayName(displayName);
store.setEndpoint(replaceSystemProperty(storeElem.getFirstChildWithName(new QName(APIConstants.EXTERNAL_API_STORE_ENDPOINT)).getText()));
// Set store endpoint, which is used to publish APIs
store.setPublished(false);
if (APIConstants.WSO2_API_STORE_TYPE.equals(type)) {
OMElement password = storeElem.getFirstChildWithName(new QName(APIConstants.EXTERNAL_API_STORE_PASSWORD));
if (password != null) {
String value = password.getText();
PasswordResolver passwordResolver = PasswordResolverFactory.getInstance();
store.setPassword(replaceSystemProperty(passwordResolver.getPassword(value)));
store.setUsername(replaceSystemProperty(storeElem.getFirstChildWithName(new QName(APIConstants.EXTERNAL_API_STORE_USERNAME)).getText()));
// Set store login username
} else {
log.error("The user-credentials of API Publisher is not defined in the <ExternalAPIStore> " + "config of external-api-stores.xml.");
}
}
externalAPIStores.add(store);
}
}
} catch (ClassNotFoundException e) {
String msg = "One or more classes defined in APIConstants.EXTERNAL_API_STORE_CLASS_NAME cannot be found";
throw new APIManagementException(msg, e);
} catch (InstantiationException e) {
String msg = "One or more classes defined in APIConstants.EXTERNAL_API_STORE_CLASS_NAME cannot be load";
throw new APIManagementException(msg, e);
} catch (IllegalAccessException e) {
String msg = "One or more classes defined in APIConstants.EXTERNAL_API_STORE_CLASS_NAME cannot be access";
throw new APIManagementException(msg, e);
}
return externalAPIStores;
}
Aggregations