Search in sources :

Example 1 with OrganizationKeyManagerDto

use of org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto in project carbon-apimgt by wso2.

the class KeyManagerHolder method getTenantKeyManagerDto.

private static OrganizationKeyManagerDto getTenantKeyManagerDto(String tenantDomain) {
    OrganizationKeyManagerDto organizationKeyManagerDto = organizationWiseMap.get(tenantDomain);
    if (organizationKeyManagerDto == null) {
        synchronized ("KeyManagerHolder".concat(tenantDomain)) {
            if (organizationKeyManagerDto == null) {
                new KeyManagerConfigurationDataRetriever(tenantDomain).run();
                organizationKeyManagerDto = organizationWiseMap.get(tenantDomain);
            }
        }
    }
    return organizationKeyManagerDto;
}
Also used : KeyManagerConfigurationDataRetriever(org.wso2.carbon.apimgt.impl.loader.KeyManagerConfigurationDataRetriever) OrganizationKeyManagerDto(org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto)

Example 2 with OrganizationKeyManagerDto

use of org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto in project carbon-apimgt by wso2.

the class KeyManagerHolder method addKeyManagerConfiguration.

public static void addKeyManagerConfiguration(String organization, String name, String type, KeyManagerConfiguration keyManagerConfiguration) throws APIManagementException {
    String issuer = (String) keyManagerConfiguration.getParameter(APIConstants.KeyManager.ISSUER);
    OrganizationKeyManagerDto organizationKeyManagerDto = organizationWiseMap.get(organization);
    if (organizationKeyManagerDto == null) {
        organizationKeyManagerDto = new OrganizationKeyManagerDto();
    }
    if (organizationKeyManagerDto.getKeyManagerByName(name) != null) {
        log.warn("Key Manager " + name + " already initialized in tenant " + organization);
    }
    if (keyManagerConfiguration.isEnabled() && !KeyManagerConfiguration.TokenType.EXCHANGED.equals(keyManagerConfiguration.getTokenType())) {
        KeyManager keyManager = null;
        JWTValidator jwtValidator = null;
        APIManagerConfiguration apiManagerConfiguration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
        String defaultKeyManagerType = apiManagerConfiguration.getFirstProperty(APIConstants.DEFAULT_KEY_MANAGER_TYPE);
        KeyManagerConnectorConfiguration keyManagerConnectorConfiguration = ServiceReferenceHolder.getInstance().getKeyManagerConnectorConfiguration(type);
        if (keyManagerConnectorConfiguration != null) {
            if (StringUtils.isNotEmpty(keyManagerConnectorConfiguration.getImplementation())) {
                try {
                    keyManager = (KeyManager) Class.forName(keyManagerConnectorConfiguration.getImplementation()).newInstance();
                    keyManager.setTenantDomain(organization);
                    if (StringUtils.isNotEmpty(defaultKeyManagerType) && defaultKeyManagerType.equals(type)) {
                        keyManagerConfiguration.addParameter(APIConstants.KEY_MANAGER_USERNAME, apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_VALIDATOR_USERNAME));
                        keyManagerConfiguration.addParameter(APIConstants.KEY_MANAGER_PASSWORD, apiManagerConfiguration.getFirstProperty(APIConstants.API_KEY_VALIDATOR_PASSWORD));
                    }
                    keyManager.loadConfiguration(keyManagerConfiguration);
                } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
                    throw new APIManagementException("Error while loading keyManager configuration", e);
                }
            }
            jwtValidator = getJWTValidator(keyManagerConfiguration, keyManagerConnectorConfiguration.getJWTValidator());
        } else {
            if (APIConstants.KeyManager.DEFAULT_KEY_MANAGER_TYPE.equals(type)) {
                keyManager = new AMDefaultKeyManagerImpl();
                keyManager.setTenantDomain(organization);
                keyManager.loadConfiguration(keyManagerConfiguration);
                jwtValidator = getJWTValidator(keyManagerConfiguration, null);
            }
        }
        KeyManagerDto keyManagerDto = new KeyManagerDto();
        keyManagerDto.setName(name);
        keyManagerDto.setIssuer(issuer);
        keyManagerDto.setJwtValidator(jwtValidator);
        keyManagerDto.setKeyManager(keyManager);
        organizationKeyManagerDto.putKeyManagerDto(keyManagerDto);
        organizationWiseMap.put(organization, organizationKeyManagerDto);
    }
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) OrganizationKeyManagerDto(org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) AMDefaultKeyManagerImpl(org.wso2.carbon.apimgt.impl.AMDefaultKeyManagerImpl) KeyManagerConnectorConfiguration(org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) OrganizationKeyManagerDto(org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto) JWTValidator(org.wso2.carbon.apimgt.impl.jwt.JWTValidator) KeyManager(org.wso2.carbon.apimgt.api.model.KeyManager)

Aggregations

OrganizationKeyManagerDto (org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)1 KeyManagerConnectorConfiguration (org.wso2.carbon.apimgt.api.model.KeyManagerConnectorConfiguration)1 AMDefaultKeyManagerImpl (org.wso2.carbon.apimgt.impl.AMDefaultKeyManagerImpl)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 KeyManagerDto (org.wso2.carbon.apimgt.impl.dto.KeyManagerDto)1 JWTValidator (org.wso2.carbon.apimgt.impl.jwt.JWTValidator)1 KeyManagerConfigurationDataRetriever (org.wso2.carbon.apimgt.impl.loader.KeyManagerConfigurationDataRetriever)1