Search in sources :

Example 16 with KeyManagerDto

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

the class KeyManagerHolder method addGlobalJWTValidators.

public static void addGlobalJWTValidators(TokenIssuerDto tokenIssuerDto) {
    KeyManagerDto keyManagerDto = new KeyManagerDto();
    keyManagerDto.setIssuer(tokenIssuerDto.getIssuer());
    keyManagerDto.setName(APIConstants.KeyManager.DEFAULT_KEY_MANAGER);
    JWTValidator jwtValidator = new JWTValidatorImpl();
    jwtValidator.loadTokenIssuerConfiguration(tokenIssuerDto);
    keyManagerDto.setJwtValidator(jwtValidator);
    globalJWTValidatorMap.put(tokenIssuerDto.getIssuer(), keyManagerDto);
}
Also used : JWTValidatorImpl(org.wso2.carbon.apimgt.impl.jwt.JWTValidatorImpl) OrganizationKeyManagerDto(org.wso2.carbon.apimgt.impl.dto.OrganizationKeyManagerDto) KeyManagerDto(org.wso2.carbon.apimgt.impl.dto.KeyManagerDto) JWTValidator(org.wso2.carbon.apimgt.impl.jwt.JWTValidator)

Example 17 with KeyManagerDto

use of org.wso2.carbon.apimgt.impl.dto.KeyManagerDto 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)

Example 18 with KeyManagerDto

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

the class KeymanagersApiServiceImpl method toKeyManagerDTO.

public static KeyManagerDTO toKeyManagerDTO(String tenantDomain, KeyManagerConfigurationDTO keyManagerConfigurationDTO) {
    KeyManagerDTO keyManagerDTO = new KeyManagerDTO();
    keyManagerDTO.setEnabled(keyManagerConfigurationDTO.isEnabled());
    keyManagerDTO.setName(keyManagerConfigurationDTO.getName());
    keyManagerDTO.setTenantDomain(tenantDomain);
    keyManagerDTO.setType(keyManagerConfigurationDTO.getType());
    keyManagerDTO.setTokenType(KeyManagerDTO.TokenTypeEnum.fromValue(keyManagerConfigurationDTO.getTokenType()));
    keyManagerDTO.setConfiguration(keyManagerConfigurationDTO.getAdditionalProperties());
    return keyManagerDTO;
}
Also used : KeyManagerDTO(org.wso2.carbon.apimgt.internal.service.dto.KeyManagerDTO)

Example 19 with KeyManagerDto

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

the class APIAdminImpl method mergeIdpWithKeyManagerConfiguration.

private void mergeIdpWithKeyManagerConfiguration(IdentityProvider identityProvider, KeyManagerConfigurationDTO keyManagerDTO) {
    keyManagerDTO.setDisplayName(identityProvider.getDisplayName());
    keyManagerDTO.setDescription(identityProvider.getIdentityProviderDescription());
    IdentityProviderProperty[] identityProviderProperties = identityProvider.getIdpProperties();
    if (identityProviderProperties.length > 0) {
        for (IdentityProviderProperty identityProviderProperty : identityProviderProperties) {
            if (StringUtils.equals(identityProviderProperty.getName(), APIConstants.JWKS_URI)) {
                keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_TYPE, APIConstants.KeyManager.CERTIFICATE_TYPE_JWKS_ENDPOINT);
                keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_VALUE, identityProviderProperty.getValue());
            }
            if (StringUtils.equals(identityProviderProperty.getName(), IdentityApplicationConstants.IDP_ISSUER_NAME)) {
                keyManagerDTO.addProperty(APIConstants.KeyManager.ISSUER, identityProviderProperty.getValue());
            }
        }
    } else if (StringUtils.isNotBlank(identityProvider.getCertificate())) {
        keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_TYPE, APIConstants.KeyManager.CERTIFICATE_TYPE_PEM_FILE);
        keyManagerDTO.addProperty(APIConstants.KeyManager.CERTIFICATE_VALUE, identityProvider.getCertificate());
    }
    keyManagerDTO.setEnabled(identityProvider.isEnable());
    keyManagerDTO.setAlias(identityProvider.getAlias());
    ClaimConfig claimConfig = identityProvider.getClaimConfig();
    JsonArray claimArray = new JsonArray();
    for (ClaimMapping claimMapping : claimConfig.getClaimMappings()) {
        JsonObject claimMappingEntryDTO = new JsonObject();
        claimMappingEntryDTO.addProperty("localClaim", claimMapping.getLocalClaim().getClaimUri());
        claimMappingEntryDTO.addProperty("remoteClaim", claimMapping.getRemoteClaim().getClaimUri());
        claimArray.add(claimMappingEntryDTO);
    }
    keyManagerDTO.addProperty(APIConstants.KeyManager.CLAIM_MAPPING, claimArray);
}
Also used : JsonArray(com.google.gson.JsonArray) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) JsonObject(com.google.gson.JsonObject)

Example 20 with KeyManagerDto

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

the class KeyManagersApiServiceImpl method keyManagersPost.

public Response keyManagersPost(KeyManagerDTO body, MessageContext messageContext) throws APIManagementException {
    String organization = RestApiUtil.getOrganization(messageContext);
    APIAdmin apiAdmin = new APIAdminImpl();
    try {
        KeyManagerConfigurationDTO keyManagerConfigurationDTO = KeyManagerMappingUtil.toKeyManagerConfigurationDTO(organization, body);
        KeyManagerConfigurationDTO createdKeyManagerConfiguration = apiAdmin.addKeyManagerConfiguration(keyManagerConfigurationDTO);
        APIUtil.logAuditMessage(APIConstants.AuditLogConstants.KEY_MANAGER, new Gson().toJson(keyManagerConfigurationDTO), APIConstants.AuditLogConstants.CREATED, RestApiCommonUtil.getLoggedInUsername());
        URI location = new URI(RestApiConstants.KEY_MANAGERS + "/" + createdKeyManagerConfiguration.getUuid());
        return Response.created(location).entity(KeyManagerMappingUtil.toKeyManagerDTO(createdKeyManagerConfiguration)).build();
    } catch (URISyntaxException e) {
        String error = "Error while Creating Key Manager configuration in organization " + organization;
        throw new APIManagementException(error, e, ExceptionCodes.INTERNAL_ERROR);
    }
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Gson(com.google.gson.Gson) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

KeyManagerDto (org.wso2.carbon.apimgt.impl.dto.KeyManagerDto)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)15 HashMap (java.util.HashMap)13 Map (java.util.Map)13 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)13 TreeMap (java.util.TreeMap)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)5 Gson (com.google.gson.Gson)4 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)4 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)4 JsonObject (com.google.gson.JsonObject)3 ArrayList (java.util.ArrayList)3 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3 Scope (org.wso2.carbon.apimgt.api.model.Scope)3 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)3 KeyManagerDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO)3 JsonArray (com.google.gson.JsonArray)2 HashSet (java.util.HashSet)2 List (java.util.List)2