Search in sources :

Example 26 with Client

use of com.aliyun.ons20190214.Client in project service-proxy by membrane.

the class TokenFlow method getResponse.

@Override
public Outcome getResponse() throws IOException {
    Client client;
    synchronized (session) {
        client = authServer.getClientList().getClient(session.getUserAttributes().get("client_id"));
    }
    String grantTypes = client.getGrantTypes();
    if (!grantTypes.contains("implicit")) {
        exc.setResponse(OAuth2Util.createParameterizedJsonErrorResponse(exc, new ReusableJsonGenerator(), "error", "invalid_grant_type"));
        return Outcome.RETURN;
    }
    return respondWithTokenAndRedirect(exc, generateAccessToken(client), authServer.getTokenGenerator().getTokenType(), session);
}
Also used : ReusableJsonGenerator(com.predic8.membrane.core.interceptor.oauth2.ReusableJsonGenerator) Client(com.predic8.membrane.core.interceptor.oauth2.Client)

Example 27 with Client

use of com.aliyun.ons20190214.Client in project stream-services-2.0 by Backbase.

the class DbsWebClientConfiguration method dbsWebClient.

/**
 * Default Reactive Web Client to be used when interacting with DBS Services. Requires OAuth2 client credentials set
 * in application.yml
 *
 * @param objectMapper                          The Jackson Object mapper to register serialization and deserialization json
 *                                              content.
 * @param reactiveOAuth2AuthorizedClientManager Client Manager managing OAuth2 tokens
 * @param builder                               THe Web Client Builder which is already preconfigured using MicroMeter
 *                                              instrumentation.
 * @return Preconfigured Web Client
 */
@Bean
public WebClient dbsWebClient(ObjectMapper objectMapper, ReactiveOAuth2AuthorizedClientManager reactiveOAuth2AuthorizedClientManager, WebClient.Builder builder, DbsWebClientConfigurationProperties dbsWebClientConfigurationProperties) {
    ServerOAuth2AuthorizedClientExchangeFilterFunction oauth2ClientFilter = new ServerOAuth2AuthorizedClientExchangeFilterFunction(reactiveOAuth2AuthorizedClientManager);
    oauth2ClientFilter.setDefaultClientRegistrationId(dbsWebClientConfigurationProperties.getDefaultClientRegistrationId());
    builder.defaultHeader("Content-Type", MediaType.APPLICATION_JSON.toString()).defaultHeader("Accept", MediaType.APPLICATION_JSON.toString()).filter((clientRequest, exchangeFunction) -> {
        final ClientRequest newRequest = Optional.ofNullable(dbsWebClientConfigurationProperties.getAdditionalHeaders()).map(additionalHeaders -> {
            log.debug("Adding additional headers: {} from configuration  Request: {}", additionalHeaders, clientRequest.url());
            return ClientRequest.from(clientRequest).headers(httpHeaders -> httpHeaders.addAll(additionalHeaders)).build();
        }).orElse(clientRequest);
        return Mono.subscriberContext().flatMap(context -> {
            Optional<MultiValueMap<String, String>> forwardHeaders = context.<MultiValueMap<String, String>>getOrEmpty(CONTEXT_KEY_FORWARDED_HEADERS);
            log.debug("context contains headers? " + forwardHeaders.isPresent());
            log.debug("forward headers:" + forwardHeaders.map(MultiValueMap::toString).orElse("null"));
            ClientRequest contextRequest = context.<MultiValueMap<String, String>>getOrEmpty("headers").map(headers -> {
                log.debug("Adding additional headers: {} from Reactive subscriber context to Request: {}", headers, clientRequest.url());
                return ClientRequest.from(newRequest).headers(httpHeaders -> httpHeaders.addAll(headers)).build();
            }).orElse(newRequest);
            return exchangeFunction.exchange(contextRequest);
        });
    }).filter(new CsrfClientExchangeFilterFunction()).filter(oauth2ClientFilter);
    if (log.isDebugEnabled()) {
        HttpClient httpClient = HttpClient.create().wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL);
        builder.clientConnector(new ReactorClientHttpConnector(httpClient));
    }
    // ensure correct exchange strategy is installed
    ExchangeStrategies strategies = ExchangeStrategies.builder().codecs(clientDefaultCodecsConfigurer -> {
        Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON);
        Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON);
        clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(encoder);
        clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(decoder);
    }).build();
    builder.exchangeStrategies(strategies);
    return builder.build();
}
Also used : java.util(java.util) DbsWebClientConfigurationProperties(com.backbase.stream.webclient.configuration.DbsWebClientConfigurationProperties) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ServerOAuth2AuthorizedClientExchangeFilterFunction(org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) org.springframework.web.reactive.function.client(org.springframework.web.reactive.function.client) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) OAuth2ClientProperties(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties) OAuth2ClientPropertiesRegistrationAdapter(org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter) DateFormat(java.text.DateFormat) ResponseCookie(org.springframework.http.ResponseCookie) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector) AdvancedByteBufFormat(reactor.netty.transport.logging.AdvancedByteBufFormat) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ReactiveClientRegistrationRepository(org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository) MediaType(org.springframework.http.MediaType) org.springframework.security.oauth2.client(org.springframework.security.oauth2.client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MultiValueMap(org.springframework.util.MultiValueMap) Mono(reactor.core.publisher.Mono) ClientRegistration(org.springframework.security.oauth2.client.registration.ClientRegistration) Configuration(org.springframework.context.annotation.Configuration) InMemoryReactiveClientRegistrationRepository(org.springframework.security.oauth2.client.registration.InMemoryReactiveClientRegistrationRepository) Slf4j(lombok.extern.slf4j.Slf4j) LogLevel(io.netty.handler.logging.LogLevel) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat) Bean(org.springframework.context.annotation.Bean) HttpClient(reactor.netty.http.client.HttpClient) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) HttpClient(reactor.netty.http.client.HttpClient) ServerOAuth2AuthorizedClientExchangeFilterFunction(org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction) MultiValueMap(org.springframework.util.MultiValueMap) ReactorClientHttpConnector(org.springframework.http.client.reactive.ReactorClientHttpConnector) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Bean(org.springframework.context.annotation.Bean)

Example 28 with Client

use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.

the class MembersManagerImpl method getMember.

@Override
@Transactional
public Member getMember(String memberId) {
    Member member = new Member();
    String orcid = memberId;
    if (!OrcidStringUtils.isValidOrcid(memberId)) {
        Map<String, String> ids = emailManager.findOricdIdsByCommaSeparatedEmails(memberId);
        // Check if it is using the email
        if (ids != null && ids.containsKey(memberId)) {
            orcid = ids.get(memberId);
        } else {
            // Check if can find it by name
            try {
                orcid = profileEntityManager.findByCreditName(memberId);
            } catch (Exception e) {
                member.getErrors().add(getMessage("manage_member.email_not_found"));
                orcid = null;
            }
        }
    }
    if (PojoUtil.isEmpty(orcid)) {
        member.getErrors().add(getMessage("manage_member.email_not_found"));
    } else {
        if (profileEntityManager.orcidExists(orcid)) {
            MemberType groupType = profileEntityManager.getGroupType(orcid);
            if (groupType != null) {
                ProfileEntity memberProfile = profileDao.find(orcid);
                member = Member.fromProfileEntity(memberProfile);
                Set<Client> clients = clientManagerReadOnly.getClients(orcid);
                List<org.orcid.pojo.ajaxForm.Client> clientsList = new ArrayList<org.orcid.pojo.ajaxForm.Client>();
                clients.forEach(c -> {
                    clientsList.add(org.orcid.pojo.ajaxForm.Client.fromModelObject(c));
                });
                member.setClients(clientsList);
            } else {
                member.getErrors().add(getMessage("manage_members.orcid_is_not_a_member"));
            }
        } else {
            member.getErrors().add(getMessage("manage_members.orcid_doesnt_exists"));
        }
    }
    return member;
}
Also used : ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) MemberType(org.orcid.jaxb.model.clientgroup.MemberType) Client(org.orcid.jaxb.model.client_v2.Client) Member(org.orcid.pojo.ajaxForm.Member) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with Client

use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method toClientListTest.

@Test
public void toClientListTest() {
    ClientDetailsEntity entity1 = getClientDetailsEntity();
    List<ClientDetailsEntity> entities = new ArrayList<ClientDetailsEntity>();
    entities.add(entity1);
    Set<Client> clients = adapter.toClientList(entities);
    assertEquals(1, clients.size());
    for (Client client : clients) {
        assertEquals(getClient(), client);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

Example 30 with Client

use of com.aliyun.ons20190214.Client in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method getClient.

private Client getClient() {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description");
    client.setGroupProfileId("group-profile-id");
    client.setId("id");
    client.setName("client-name");
    client.setWebsite("client-website");
    client.setAuthenticationProviderId("authentication-provider-id");
    Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
    ClientRedirectUri rUri1 = new ClientRedirectUri();
    Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
    scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
    rUri1.setPredefinedClientScopes(scopes1);
    rUri1.setRedirectUri("redirect-uri-1");
    rUri1.setRedirectUriType("type-1");
    rUri1.setUriActType("uri-act-type-1");
    rUri1.setUriGeoArea("uri-geo-area-1");
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2");
    rUri2.setRedirectUriType("type-2");
    rUri2.setUriActType("uri-act-type-2");
    rUri2.setUriGeoArea("uri-geo-area-2");
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3");
    rUri3.setRedirectUriType("type-3");
    rUri3.setUriActType("uri-act-type-3");
    rUri3.setUriGeoArea("uri-geo-area-3");
    clientRedirectUris.add(rUri1);
    clientRedirectUris.add(rUri2);
    clientRedirectUris.add(rUri3);
    client.setClientRedirectUris(clientRedirectUris);
    return client;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) HashSet(java.util.HashSet)

Aggregations

Client (org.orcid.jaxb.model.client_v2.Client)18 Test (org.junit.Test)13 Client (com.aliyun.dysmsapi20170525.Client)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 Client (com.predic8.membrane.core.interceptor.oauth2.Client)9 Config (com.aliyun.teaopenapi.models.Config)6 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)5 BaseTest (org.orcid.core.BaseTest)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 NoResponse (com.predic8.membrane.core.interceptor.oauth2.request.NoResponse)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)2 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2