Search in sources :

Example 1 with Certificate

use of io.gravitee.am.model.Certificate in project gravitee-access-management by gravitee-io.

the class JdbcCertificateRepository method toEntity.

protected Certificate toEntity(JdbcCertificate entity) {
    Certificate cert = mapper.map(entity, Certificate.class);
    if (cert != null && cert.getMetadata() != null && cert.getMetadata().containsKey("file")) {
        Object file = cert.getMetadata().get("file");
        if (file instanceof String) {
            // file value should be Byte[] but Jackson serialize it in B64
            byte[] data = Base64.getDecoder().decode((String) file);
            cert.getMetadata().put("file", data);
        }
    }
    return cert;
}
Also used : RandomString(io.gravitee.am.common.utils.RandomString) Certificate(io.gravitee.am.model.Certificate) JdbcCertificate(io.gravitee.am.repository.jdbc.management.api.model.JdbcCertificate)

Example 2 with Certificate

use of io.gravitee.am.model.Certificate in project gravitee-access-management by gravitee-io.

the class MongoCertificateRepository method convert.

private Certificate convert(CertificateMongo certificateMongo) {
    if (certificateMongo == null) {
        return null;
    }
    Certificate certificate = new Certificate();
    certificate.setId(certificateMongo.getId());
    certificate.setName(certificateMongo.getName());
    certificate.setType(certificateMongo.getType());
    certificate.setConfiguration(certificateMongo.getConfiguration());
    certificate.setDomain(certificateMongo.getDomain());
    if (certificateMongo.getMetadata() != null) {
        // convert bson binary type back to byte array
        Map<String, Object> metadata = certificateMongo.getMetadata().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue() instanceof Binary ? ((Binary) e.getValue()).getData() : e.getValue()));
        certificate.setMetadata(metadata);
    }
    certificate.setCreatedAt(certificateMongo.getCreatedAt());
    certificate.setUpdatedAt(certificateMongo.getUpdatedAt());
    certificate.setExpiresAt(certificateMongo.getExpiresAt());
    return certificate;
}
Also used : Document(org.bson.Document) Certificate(io.gravitee.am.model.Certificate) Binary(org.bson.types.Binary) Date(java.util.Date) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Collectors(java.util.stream.Collectors) RandomString(io.gravitee.am.common.utils.RandomString) Component(org.springframework.stereotype.Component) CertificateMongo(io.gravitee.am.repository.mongodb.management.internal.model.CertificateMongo) Map(java.util.Map) CertificateRepository(io.gravitee.am.repository.management.api.CertificateRepository) PostConstruct(javax.annotation.PostConstruct) Filters.eq(com.mongodb.client.model.Filters.eq) io.reactivex(io.reactivex) RandomString(io.gravitee.am.common.utils.RandomString) Binary(org.bson.types.Binary) Map(java.util.Map) Certificate(io.gravitee.am.model.Certificate)

Example 3 with Certificate

use of io.gravitee.am.model.Certificate in project gravitee-access-management by gravitee-io.

the class CertificateResourceTest method shouldGetCertificate_wrongDomain.

@Test
public void shouldGetCertificate_wrongDomain() {
    final String domainId = "domain-id";
    final Domain mockDomain = new Domain();
    mockDomain.setId(domainId);
    final String certificateId = "certificate-id";
    final Certificate mockCertificate = new Certificate();
    mockCertificate.setId(certificateId);
    mockCertificate.setName("certificate-name");
    mockCertificate.setDomain("wrong-domain");
    doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
    doReturn(Maybe.just(mockCertificate)).when(certificateService).findById(certificateId);
    final Response response = target("domains").path(domainId).path("certificates").path(certificateId).request().get();
    assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Domain(io.gravitee.am.model.Domain) Certificate(io.gravitee.am.model.Certificate) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest) Test(org.junit.Test)

Example 4 with Certificate

use of io.gravitee.am.model.Certificate in project gravitee-access-management by gravitee-io.

the class CertificatesResourceTest method shouldCreate.

@Test
public void shouldCreate() {
    final String domainId = "domain-1";
    final Domain mockDomain = new Domain();
    mockDomain.setId(domainId);
    NewCertificate newCertificate = new NewCertificate();
    newCertificate.setName("certificate-name");
    newCertificate.setType("certificate-type");
    newCertificate.setConfiguration("certificate-configuration");
    Certificate certificate = new Certificate();
    certificate.setId("certificate-id");
    certificate.setName("certificate-name");
    doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
    doReturn(Maybe.just("certificate-schema")).when(certificatePluginService).getSchema(anyString());
    doReturn(Single.just(certificate)).when(certificateService).create(eq(domainId), any(), any());
    final Response response = target("domains").path(domainId).path("certificates").request().post(Entity.json(newCertificate));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) NewCertificate(io.gravitee.am.service.model.NewCertificate) Domain(io.gravitee.am.model.Domain) Certificate(io.gravitee.am.model.Certificate) NewCertificate(io.gravitee.am.service.model.NewCertificate) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 5 with Certificate

use of io.gravitee.am.model.Certificate in project gravitee-access-management by gravitee-io.

the class DomainNotificationServiceTest method shouldNotifyUserFromGroup.

@Test
public void shouldNotifyUserFromGroup() throws Exception {
    final Membership member = new Membership();
    member.setMemberType(MemberType.GROUP);
    member.setMemberId("groupId");
    when(membershipService.findByCriteria(eq(ReferenceType.DOMAIN), eq(DOMAIN_ID), any())).thenReturn(Flowable.just(member), Flowable.empty());
    final List<User> tenUsers = IntStream.range(0, 10).mapToObj(x -> {
        final User user = new User();
        user.setId("" + x);
        user.setEmail(x + "@acme.fr");
        return user;
    }).collect(Collectors.toList());
    final User singleUser = new User();
    singleUser.setId("single");
    singleUser.setEmail("single@acme.fr");
    when(groupService.findMembers(any(), any(), any(), anyInt(), anyInt())).thenReturn(Single.just(new Page<>(tenUsers, 0, 11)), Single.just(new Page<>(Arrays.asList(singleUser), 1, 11)));
    when(emailService.getFinalEmail(any(), any(), any(), any(), any())).thenReturn(new Email());
    cut.registerCertificateExpiration(certificate);
    // wait subscription execution
    Thread.sleep(1000);
    verify(notifierService, times(11)).register(any(), any(), any());
    verify(userService, never()).findById(any(), any(), any());
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Certificate(io.gravitee.am.model.Certificate) EnvironmentService(io.gravitee.am.service.EnvironmentService) DomainNotifierServiceImpl(io.gravitee.am.management.service.impl.DomainNotifierServiceImpl) Arrays(java.util.Arrays) SystemRole(io.gravitee.am.model.permissions.SystemRole) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Role(io.gravitee.am.model.Role) Maybe(io.reactivex.Maybe) RunWith(org.junit.runner.RunWith) DomainService(io.gravitee.am.service.DomainService) Environment(io.gravitee.am.model.Environment) Mockito.argThat(org.mockito.Mockito.argThat) Single(io.reactivex.Single) Flowable(io.reactivex.Flowable) After(org.junit.After) Email(io.gravitee.am.common.email.Email) ReferenceType(io.gravitee.am.model.ReferenceType) User(io.gravitee.am.model.User) GroupService(io.gravitee.am.service.GroupService) MembershipService(io.gravitee.am.service.MembershipService) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) RoleService(io.gravitee.am.service.RoleService) NotifierService(io.gravitee.node.api.notifier.NotifierService) Page(io.gravitee.am.model.common.Page) MemberType(io.gravitee.am.model.membership.MemberType) TYPE_EMAIL_NOTIFIER(io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_EMAIL_NOTIFIER) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) Membership(io.gravitee.am.model.Membership) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) OrganizationUserService(io.gravitee.am.service.OrganizationUserService) Mockito.anyInt(org.mockito.Mockito.anyInt) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) EmailNotifierConfiguration(io.gravitee.am.management.service.impl.notifications.EmailNotifierConfiguration) TYPE_UI_NOTIFIER(io.gravitee.am.management.service.impl.notifications.NotificationDefinitionUtils.TYPE_UI_NOTIFIER) User(io.gravitee.am.model.User) Email(io.gravitee.am.common.email.Email) Membership(io.gravitee.am.model.Membership) Page(io.gravitee.am.model.common.Page) Test(org.junit.Test)

Aggregations

Certificate (io.gravitee.am.model.Certificate)30 Test (org.junit.Test)16 NewCertificate (io.gravitee.am.service.model.NewCertificate)8 Domain (io.gravitee.am.model.Domain)7 Response (javax.ws.rs.core.Response)7 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)6 UpdateCertificate (io.gravitee.am.service.model.UpdateCertificate)6 Maybe (io.reactivex.Maybe)6 Date (java.util.Date)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 RandomString (io.gravitee.am.common.utils.RandomString)5 User (io.gravitee.am.identityprovider.api.User)5 DomainService (io.gravitee.am.service.DomainService)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)4 ReferenceType (io.gravitee.am.model.ReferenceType)4 CertificateNotFoundException (io.gravitee.am.service.exception.CertificateNotFoundException)4 CertificatePluginSchemaNotFoundException (io.gravitee.am.service.exception.CertificatePluginSchemaNotFoundException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)3