Search in sources :

Example 1 with UserRepository

use of io.gravitee.am.repository.management.api.UserRepository in project gravitee-access-management by gravitee-io.

the class EnrichProfilePolicy method enrichProfile.

protected Single<User> enrichProfile(ExecutionContext context) {
    UserRepository userRepository = context.getComponent(UserRepository.class);
    User user = (User) context.getAttribute("user");
    return userRepository.update(user);
}
Also used : UserRepository(io.gravitee.am.repository.management.api.UserRepository) User(io.gravitee.am.model.User)

Example 2 with UserRepository

use of io.gravitee.am.repository.management.api.UserRepository in project gravitee-access-management by gravitee-io.

the class EnrichProfilePolicyTest method shouldUpdateUser.

@Test
public void shouldUpdateUser() throws Exception {
    final CountDownLatch lock = new CountDownLatch(1);
    this.policyChain = spy(new CountDownPolicyChain(lock));
    when(configuration.getProperties()).thenReturn(Arrays.asList(new Property("myclaim", "myclaimValue"), new Property("myclaim-tpl", "{#request.params['" + REQUEST_PARAM + "']}")));
    User user = mock(User.class);
    Map<String, Object> additionalInformation = new HashMap<>();
    when(user.getAdditionalInformation()).thenReturn(additionalInformation);
    when(executionContext.getAttribute("user")).thenReturn(user);
    when(userRepository.update(any())).thenReturn(Single.just(user));
    EnrichProfilePolicy enrichProfilePolicy = new EnrichProfilePolicy(configuration);
    enrichProfilePolicy.onRequest(request, response, executionContext, policyChain);
    lock.await(1, TimeUnit.SECONDS);
    verify(policyChain, never()).failWith(any());
    verify(policyChain).doNext(any(), any());
    verify(userRepository).update(argThat(u -> u.getAdditionalInformation() != null && u.getAdditionalInformation().containsKey("myclaim") && "myclaimValue".equals(u.getAdditionalInformation().get("myclaim")) && u.getAdditionalInformation().containsKey("myclaim-tpl") && PARAM_VALUE.equals(u.getAdditionalInformation().get("myclaim-tpl"))));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) UserRepository(io.gravitee.am.repository.management.api.UserRepository) Mock(org.mockito.Mock) MultiValueMap(io.gravitee.common.util.MultiValueMap) RunWith(org.junit.runner.RunWith) RequestWrapper(io.gravitee.gateway.api.RequestWrapper) HashMap(java.util.HashMap) Single(io.reactivex.Single) EnrichProfilePolicyConfiguration(io.gravitee.am.policy.enrich.profile.configuration.EnrichProfilePolicyConfiguration) TemplateEngine(io.gravitee.el.TemplateEngine) Response(io.gravitee.gateway.api.Response) Request(io.gravitee.gateway.api.Request) Map(java.util.Map) User(io.gravitee.am.model.User) EvaluableRequest(io.gravitee.am.gateway.handler.context.EvaluableRequest) Before(org.junit.Before) SpelTemplateEngineFactory(io.gravitee.el.spel.SpelTemplateEngineFactory) ExecutionContext(io.gravitee.gateway.api.ExecutionContext) Test(org.junit.Test) LinkedMultiValueMap(io.gravitee.common.util.LinkedMultiValueMap) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) PolicyChain(io.gravitee.policy.api.PolicyChain) PolicyResult(io.gravitee.policy.api.PolicyResult) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Property(io.gravitee.am.policy.enrich.profile.configuration.Property) User(io.gravitee.am.model.User) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) Property(io.gravitee.am.policy.enrich.profile.configuration.Property) Test(org.junit.Test)

Aggregations

User (io.gravitee.am.model.User)2 UserRepository (io.gravitee.am.repository.management.api.UserRepository)2 EvaluableRequest (io.gravitee.am.gateway.handler.context.EvaluableRequest)1 EnrichProfilePolicyConfiguration (io.gravitee.am.policy.enrich.profile.configuration.EnrichProfilePolicyConfiguration)1 Property (io.gravitee.am.policy.enrich.profile.configuration.Property)1 LinkedMultiValueMap (io.gravitee.common.util.LinkedMultiValueMap)1 MultiValueMap (io.gravitee.common.util.MultiValueMap)1 TemplateEngine (io.gravitee.el.TemplateEngine)1 SpelTemplateEngineFactory (io.gravitee.el.spel.SpelTemplateEngineFactory)1 ExecutionContext (io.gravitee.gateway.api.ExecutionContext)1 Request (io.gravitee.gateway.api.Request)1 RequestWrapper (io.gravitee.gateway.api.RequestWrapper)1 Response (io.gravitee.gateway.api.Response)1 PolicyChain (io.gravitee.policy.api.PolicyChain)1 PolicyResult (io.gravitee.policy.api.PolicyResult)1 Single (io.reactivex.Single)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1