Updated KC client lib RED-8431
This commit is contained in:
parent
631fe2bc1f
commit
2fc8c9fc65
@ -2,7 +2,7 @@ version: '2'
|
||||
|
||||
services:
|
||||
keycloak:
|
||||
image: quay.io/keycloak/keycloak:20.0
|
||||
image: quay.io/keycloak/keycloak:latest
|
||||
command: start-dev
|
||||
environment:
|
||||
KEYCLOAK_ADMIN: admin
|
||||
|
||||
@ -5,6 +5,7 @@ plugins {
|
||||
id("org.springframework.boot") version "3.1.5"
|
||||
id("io.spring.dependency-management") version "1.1.0"
|
||||
id("org.sonarqube") version "4.0.0.2929"
|
||||
id("io.freefair.lombok") version "8.4"
|
||||
pmd
|
||||
`maven-publish`
|
||||
checkstyle
|
||||
@ -101,9 +102,9 @@ dependencies {
|
||||
implementation("net.logstash.logback:logstash-logback-encoder:7.4")
|
||||
implementation("ch.qos.logback:logback-classic")
|
||||
implementation("org.postgresql:postgresql:42.5.4")
|
||||
implementation("com.google.guava:guava:31.1-jre")
|
||||
implementation("com.google.guava:guava:33.0.0-jre")
|
||||
implementation("org.liquibase:liquibase-core:4.17.2")
|
||||
implementation("org.keycloak:keycloak-admin-client:21.0.1")
|
||||
implementation("org.keycloak:keycloak-admin-client:23.0.6")
|
||||
implementation("org.springframework.boot:spring-boot-starter-amqp")
|
||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||
implementation("org.springframework.retry:spring-retry")
|
||||
@ -113,26 +114,21 @@ dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
implementation("org.apache.commons:commons-lang3:3.12.0")
|
||||
implementation("commons-validator:commons-validator:1.7")
|
||||
implementation("commons-validator:commons-validator:1.8.0")
|
||||
implementation("org.springframework.boot:spring-boot-configuration-processor")
|
||||
implementation("com.iqser.red.commons:storage-commons:2.43.0")
|
||||
implementation("com.iqser.red.commons:storage-commons:2.45.0")
|
||||
implementation("jakarta.mail:jakarta.mail-api:2.1.2")
|
||||
implementation("org.eclipse.angus:angus-mail:2.0.2")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation("org.springframework.cloud:spring-cloud-starter-openfeign")
|
||||
testImplementation("org.projectlombok:lombok")
|
||||
compileOnly("org.projectlombok:lombok")
|
||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||
annotationProcessor("org.projectlombok:lombok")
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
testImplementation("org.springframework.amqp:spring-rabbit-test")
|
||||
testImplementation("org.testcontainers:postgresql:1.18.3")
|
||||
testImplementation("com.github.dasniko:testcontainers-keycloak:2.5.0")
|
||||
testImplementation("org.testcontainers:testcontainers:1.19.0")
|
||||
testImplementation("org.testcontainers:junit-jupiter:1.19.0")
|
||||
testAnnotationProcessor("org.projectlombok:lombok")
|
||||
|
||||
testImplementation("org.testcontainers:postgresql:1.19.4")
|
||||
testImplementation("org.testcontainers:testcontainers:1.19.4")
|
||||
testImplementation("org.testcontainers:junit-jupiter:1.19.4")
|
||||
testImplementation("com.github.dasniko:testcontainers-keycloak:3.2.0")
|
||||
}
|
||||
|
||||
extra["springCloudVersion"] = "2022.0.2"
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
package com.knecon.fforesight.tenantusermanagement.controller;
|
||||
|
||||
import javax.ws.rs.BadRequestException;
|
||||
import javax.ws.rs.ForbiddenException;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -11,8 +8,10 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.knecon.fforesight.keycloakcommons.security.KeycloakSecurity;
|
||||
import com.knecon.fforesight.tenantusermanagement.model.ErrorMessage;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import jakarta.ws.rs.ForbiddenException;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class ControllerAdvice {
|
||||
|
||||
@ -4,8 +4,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.ForbiddenException;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -17,6 +15,8 @@ import com.knecon.fforesight.tenantusermanagement.api.external.UserPreferenceRes
|
||||
import com.knecon.fforesight.tenantusermanagement.permissions.UserManagementPermissions;
|
||||
import com.knecon.fforesight.tenantusermanagement.service.UserService;
|
||||
|
||||
import jakarta.ws.rs.ForbiddenException;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RestController
|
||||
|
||||
@ -7,9 +7,12 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.ws.rs.BadRequestException;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import com.knecon.fforesight.tenantusermanagement.model.SMTPResponse;
|
||||
|
||||
@ -25,8 +28,10 @@ import jakarta.mail.internet.MimeBodyPart;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import jakarta.mail.internet.MimeMultipart;
|
||||
import jakarta.mail.internet.MimeUtility;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -36,6 +41,7 @@ public class EmailService {
|
||||
private final String AUTHENTICATION_UNSUCCESSFUL = "Authentication unsuccessful";
|
||||
private final String WRONG_USERNAME_PASSWORD = "Username and Password not accepted";
|
||||
|
||||
|
||||
public SMTPResponse.SMTPResponseBuilder send(Map<String, String> config, String address, String subject, String textBody) {
|
||||
|
||||
Transport transport = null;
|
||||
@ -93,11 +99,11 @@ public class EmailService {
|
||||
|
||||
msg.setReplyTo(new Address[]{toInternetAddress(from, fromDisplayName)});
|
||||
|
||||
if (isNotBlank(replyTo)) {
|
||||
if (StringUtils.isNotBlank(replyTo)) {
|
||||
msg.setReplyTo(new Address[]{toInternetAddress(replyTo, replyToDisplayName)});
|
||||
}
|
||||
|
||||
if (isNotBlank(envelopeFrom)) {
|
||||
if (StringUtils.isNotBlank(envelopeFrom)) {
|
||||
props.setProperty("mail.smtp.from", envelopeFrom);
|
||||
}
|
||||
|
||||
@ -121,9 +127,9 @@ public class EmailService {
|
||||
.statusCode(200);
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage().contains(AUTHENTICATION_UNSUCCESSFUL) || e.getMessage().contains(WRONG_USERNAME_PASSWORD)) {
|
||||
throw new BadRequestException(AUTHENTICATION_UNSUCCESSFUL);
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, AUTHENTICATION_UNSUCCESSFUL);
|
||||
} else {
|
||||
throw new BadRequestException(e.getMessage());
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage(), e);
|
||||
}
|
||||
} finally {
|
||||
if (transport != null) {
|
||||
@ -136,13 +142,14 @@ public class EmailService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected InternetAddress toInternetAddress(String email, String displayName) throws UnsupportedEncodingException, AddressException, BadRequestException {
|
||||
|
||||
if (email == null || "".equals(email.trim())) {
|
||||
throw new BadRequestException("Please provide a valid address");
|
||||
if (StringUtils.isBlank(email)) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Please provide a valid address");
|
||||
}
|
||||
|
||||
if (displayName == null || "".equals(displayName.trim())) {
|
||||
if (StringUtils.isBlank(displayName)) {
|
||||
return new InternetAddress(email);
|
||||
}
|
||||
|
||||
@ -163,9 +170,4 @@ public class EmailService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isNotBlank(String str) {
|
||||
|
||||
return str != null && !"".equals(str.trim());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -14,9 +14,9 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
|
||||
import com.knecon.fforesight.tenantcommons.model.UpdateDetailsRequest;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
|
||||
@ -1,11 +1,10 @@
|
||||
package com.knecon.fforesight.tenantusermanagement.service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.tenantcommons.TenantProvider;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -23,7 +22,7 @@ public class UserCacheBuilder {
|
||||
|
||||
try {
|
||||
tenantManagementService.getTenants().forEach(tenant -> userService.getAllUsers(tenant.getTenantId()));
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
log.debug("Cold start");
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,11 +8,10 @@ import java.util.TreeSet;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.ws.rs.ClientErrorException;
|
||||
import javax.ws.rs.NotAuthorizedException;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import jakarta.ws.rs.ClientErrorException;
|
||||
import jakarta.ws.rs.NotAuthorizedException;
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.apache.commons.validator.routines.EmailValidator;
|
||||
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
|
||||
import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl;
|
||||
@ -23,6 +22,7 @@ import org.keycloak.admin.client.resource.UsersResource;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -334,7 +334,7 @@ public class UserService {
|
||||
try {
|
||||
getTenantUsersResource().get(userId).toRepresentation();
|
||||
return true;
|
||||
} catch (javax.ws.rs.NotFoundException e) {
|
||||
} catch (NotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -487,7 +487,7 @@ public class UserService {
|
||||
realmRole = realmService.realm(TenantContext.getTenantId()).roles().get(role).toRepresentation();
|
||||
} catch (NotFoundException e) {
|
||||
log.warn("The realm role {} is not found.", role);
|
||||
throw new NotFoundException("The realm role " + role + " is not found.", e);
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "The realm role " + role + " is not found.", e);
|
||||
}
|
||||
return realmRole;
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import org.keycloak.representations.idm.RoleRepresentation;
|
||||
|
||||
public final class KeyCloakTestContainer {
|
||||
|
||||
private static final String IMAGE_VERSION = "quay.io/keycloak/keycloak:21.0.0";
|
||||
private static final String IMAGE_VERSION = "quay.io/keycloak/keycloak:23.0.6";
|
||||
private static KeycloakContainer keycloak;
|
||||
|
||||
|
||||
|
||||
@ -4,13 +4,12 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ws.rs.BadRequestException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.knecon.fforesight.tenantcommons.TenantContext;
|
||||
import com.knecon.fforesight.tenantusermanagement.properties.TenantUserManagementProperties;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user