-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: fabrizio.guerrini <fabrizio.guerrini@C11-C9GE23PFRDO.dir.svc.accenture.com>
- Loading branch information
Showing
51 changed files
with
10,408 additions
and
1,389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/it/pagopa/swclient/mil/preset/bean/Role.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package it.pagopa.swclient.mil.preset.bean; | ||
|
||
public enum Role { | ||
|
||
NODO("Nodo"), | ||
NOTICE_PAYER("NoticePayer"), | ||
INSTITUTION_PORTAL("InstitutionPortal"), | ||
SERVICE_LIST_REQUESTER("ServiceListRequester"), | ||
SLAVE_POS("SlavePos"); | ||
|
||
public final String label; | ||
|
||
Role(String label) { | ||
this.label = label; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/it/pagopa/swclient/mil/preset/utils/AuthenticationFailedExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package it.pagopa.swclient.mil.preset.utils; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.security.AuthenticationFailedException; | ||
import it.pagopa.swclient.mil.preset.ErrorCode; | ||
import jakarta.annotation.Priority; | ||
import jakarta.ws.rs.Priorities; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
@Priority(Priorities.AUTHENTICATION) | ||
public class AuthenticationFailedExceptionMapper implements ExceptionMapper<AuthenticationFailedException> { | ||
|
||
@Context | ||
ContainerRequestContext context; | ||
|
||
@Override | ||
public Response toResponse(AuthenticationFailedException exception) { | ||
Log.errorf("[%s] Error unauthorized - %s", ErrorCode.ERROR_UNAUTHORIZED, context.getHeaders()); | ||
return Response.status(Response.Status.UNAUTHORIZED).build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/it/pagopa/swclient/mil/preset/utils/ForbiddenExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package it.pagopa.swclient.mil.preset.utils; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.security.ForbiddenException; | ||
import it.pagopa.swclient.mil.preset.ErrorCode; | ||
import jakarta.annotation.Priority; | ||
import jakarta.ws.rs.Priorities; | ||
import jakarta.ws.rs.container.ContainerRequestContext; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
@Priority(Priorities.AUTHENTICATION) | ||
public class ForbiddenExceptionMapper implements ExceptionMapper<ForbiddenException> { | ||
|
||
@Context | ||
ContainerRequestContext context; | ||
|
||
@Override | ||
public Response toResponse(ForbiddenException exception) { | ||
Log.errorf("[%s] Error forbidden - %s", ErrorCode.ERROR_FORBIDDEN, context.getHeaders()); | ||
return Response.status(Response.Status.FORBIDDEN).build(); | ||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...n/java/it/pagopa/swclient/mil/preset/validation/constraints/AcquirerIdNotNullForRole.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package it.pagopa.swclient.mil.preset.validation.constraints; | ||
|
||
import it.pagopa.swclient.mil.preset.bean.Role; | ||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Documented | ||
@Retention(RUNTIME) | ||
@Target(TYPE) | ||
@Constraint(validatedBy = { | ||
AcquirerIdNotNullForRoleValidator.class | ||
}) | ||
public @interface AcquirerIdNotNullForRole { | ||
|
||
String message() default ""; | ||
|
||
Role[] roles() default {}; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.../pagopa/swclient/mil/preset/validation/constraints/AcquirerIdNotNullForRoleValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package it.pagopa.swclient.mil.preset.validation.constraints; | ||
|
||
import it.pagopa.swclient.mil.preset.bean.UnsubscribeHeaders; | ||
import jakarta.inject.Inject; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import org.eclipse.microprofile.jwt.JsonWebToken; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class AcquirerIdNotNullForRoleValidator implements ConstraintValidator<AcquirerIdNotNullForRole, UnsubscribeHeaders> { | ||
|
||
@Inject | ||
JsonWebToken jwt; | ||
|
||
List<String> roles; | ||
|
||
@Override | ||
public void initialize(AcquirerIdNotNullForRole constraintAnnotation) { | ||
roles = Arrays.stream(constraintAnnotation.roles()).map(r -> r.label).toList(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(UnsubscribeHeaders unsubscribeHeaders, ConstraintValidatorContext context) { | ||
String acquirerId = unsubscribeHeaders.getAcquirerId(); | ||
return (jwt.getGroups().stream().noneMatch(roles::contains) || acquirerId != null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
.../it/pagopa/swclient/mil/preset/validation/constraints/ChannelNotNullForRoleValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* | ||
*/ | ||
package it.pagopa.swclient.mil.preset.validation.constraints; | ||
|
||
import org.eclipse.microprofile.jwt.JsonWebToken; | ||
|
||
import it.pagopa.swclient.mil.preset.bean.UnsubscribeHeaders; | ||
import jakarta.inject.Inject; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class ChannelNotNullForRoleValidator implements ConstraintValidator<ChannelNotNullForRole, UnsubscribeHeaders> { | ||
|
||
@Inject | ||
JsonWebToken jwt; | ||
|
||
List<String> roles; | ||
|
||
@Override | ||
public void initialize(ChannelNotNullForRole constraintAnnotation) { | ||
roles = Arrays.stream(constraintAnnotation.roles()).map(r -> r.label).toList(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(UnsubscribeHeaders unsubscribeHeaders, ConstraintValidatorContext context) { | ||
String channel = unsubscribeHeaders.getChannel(); | ||
return (jwt.getGroups().stream().noneMatch(roles::contains) || channel != null); | ||
|
||
} | ||
} |
Oops, something went wrong.