Search in sources :

Example 1 with KeyManagerWellKnownResponseDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO in project carbon-apimgt by wso2.

the class KeyManagerMappingUtil method fromOpenIdConnectConfigurationToKeyManagerConfiguration.

public static KeyManagerWellKnownResponseDTO fromOpenIdConnectConfigurationToKeyManagerConfiguration(OpenIdConnectConfiguration openIdConnectConfiguration) {
    KeyManagerWellKnownResponseDTO keyManagerWellKnownResponseDTO = new KeyManagerWellKnownResponseDTO();
    if (openIdConnectConfiguration != null) {
        keyManagerWellKnownResponseDTO.setValid(true);
        KeyManagerDTO keyManagerDto = new KeyManagerDTO();
        keyManagerDto.setIssuer(openIdConnectConfiguration.getIssuer());
        keyManagerDto.setIntrospectionEndpoint(openIdConnectConfiguration.getIntrospectionEndpoint());
        keyManagerDto.setClientRegistrationEndpoint(openIdConnectConfiguration.getRegistrationEndpoint());
        keyManagerDto.setAuthorizeEndpoint(openIdConnectConfiguration.getAuthorizeEndpoint());
        keyManagerDto.setTokenEndpoint(openIdConnectConfiguration.getTokenEndpoint());
        keyManagerDto.setRevokeEndpoint(openIdConnectConfiguration.getRevokeEndpoint());
        keyManagerDto.setEnabled(true);
        keyManagerDto.setEnableTokenGeneration(true);
        keyManagerDto.setEnableMapOAuthConsumerApps(true);
        keyManagerDto.setEnableOAuthAppCreation(true);
        keyManagerDto.setEnableSelfValidationJWT(true);
        keyManagerDto.setAvailableGrantTypes(openIdConnectConfiguration.getGrantTypesSupported());
        if (StringUtils.isNotEmpty(openIdConnectConfiguration.getJwksEndpoint())) {
            KeyManagerCertificatesDTO keyManagerCertificatesDTO = new KeyManagerCertificatesDTO();
            keyManagerCertificatesDTO.setType(KeyManagerCertificatesDTO.TypeEnum.JWKS);
            keyManagerCertificatesDTO.setValue(openIdConnectConfiguration.getJwksEndpoint());
            keyManagerDto.setCertificates(keyManagerCertificatesDTO);
        }
        keyManagerWellKnownResponseDTO.setValue(keyManagerDto);
    }
    return keyManagerWellKnownResponseDTO;
}
Also used : KeyManagerCertificatesDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerCertificatesDTO) KeyManagerWellKnownResponseDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO) KeyManagerDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO)

Example 2 with KeyManagerWellKnownResponseDTO

use of org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO in project carbon-apimgt by wso2.

the class KeyManagersApiServiceImpl method keyManagersDiscoverPost.

@Override
public Response keyManagersDiscoverPost(String url, String type, MessageContext messageContext) throws APIManagementException {
    if (StringUtils.isNotEmpty(url)) {
        Gson gson = new GsonBuilder().serializeNulls().create();
        OpenIDConnectDiscoveryClient openIDConnectDiscoveryClient = Feign.builder().client(new ApacheFeignHttpClient(APIUtil.getHttpClient(url))).encoder(new GsonEncoder(gson)).decoder(new GsonDecoder(gson)).errorDecoder(new KMClientErrorDecoder()).target(OpenIDConnectDiscoveryClient.class, url);
        OpenIdConnectConfiguration openIdConnectConfiguration = openIDConnectDiscoveryClient.getOpenIdConnectConfiguration();
        if (openIdConnectConfiguration != null) {
            KeyManagerWellKnownResponseDTO keyManagerWellKnownResponseDTO = KeyManagerMappingUtil.fromOpenIdConnectConfigurationToKeyManagerConfiguration(openIdConnectConfiguration);
            keyManagerWellKnownResponseDTO.getValue().setWellKnownEndpoint(url);
            keyManagerWellKnownResponseDTO.getValue().setType(type);
            return Response.ok().entity(keyManagerWellKnownResponseDTO).build();
        }
    }
    return Response.ok(new KeyManagerWellKnownResponseDTO()).build();
}
Also used : KMClientErrorDecoder(org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder) GsonEncoder(feign.gson.GsonEncoder) OpenIdConnectConfiguration(org.wso2.carbon.apimgt.impl.kmclient.model.OpenIdConnectConfiguration) OpenIDConnectDiscoveryClient(org.wso2.carbon.apimgt.impl.kmclient.model.OpenIDConnectDiscoveryClient) GsonBuilder(com.google.gson.GsonBuilder) KeyManagerWellKnownResponseDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO) GsonDecoder(feign.gson.GsonDecoder) Gson(com.google.gson.Gson) ApacheFeignHttpClient(org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient)

Aggregations

KeyManagerWellKnownResponseDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerWellKnownResponseDTO)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 GsonDecoder (feign.gson.GsonDecoder)1 GsonEncoder (feign.gson.GsonEncoder)1 ApacheFeignHttpClient (org.wso2.carbon.apimgt.impl.kmclient.ApacheFeignHttpClient)1 KMClientErrorDecoder (org.wso2.carbon.apimgt.impl.kmclient.KMClientErrorDecoder)1 OpenIDConnectDiscoveryClient (org.wso2.carbon.apimgt.impl.kmclient.model.OpenIDConnectDiscoveryClient)1 OpenIdConnectConfiguration (org.wso2.carbon.apimgt.impl.kmclient.model.OpenIdConnectConfiguration)1 KeyManagerCertificatesDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerCertificatesDTO)1 KeyManagerDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.KeyManagerDTO)1