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;
}
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;
}
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());
}
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());
}
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());
}
Aggregations