Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] fix: PEN-11 json cfg validator #4960

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
Expand Down Expand Up @@ -109,7 +110,7 @@ public void list(
@ApiResponse(responseCode = "500", description = "Internal server error")
public void create(
@PathParam("organizationId") String organizationId,
NewReporter newReporter,
@Valid NewReporter newReporter,
@Suspended final AsyncResponse response) {

User authenticatedUser = getAuthenticatedUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void create(
@PathParam("organizationId") String organizationId,
@PathParam("environmentId") String environmentId,
@PathParam("domain") String domain,
NewReporter newReporter,
@Valid NewReporter newReporter,
@Suspended final AsyncResponse response) {

User authenticatedUser = getAuthenticatedUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.gravitee.am.model.ReferenceType;
import io.gravitee.am.model.alert.AlertNotifier;
import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

Expand All @@ -35,6 +36,7 @@ public class NewAlertNotifier {
private boolean enabled;

@NotNull
@JsonString
private String configuration;

public AlertNotifier toAlertNotifier(ReferenceType refType, String refId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -32,6 +33,7 @@ public class NewAuthenticationDeviceNotifier {
private String name;

@NotNull
@JsonString
private String configuration;

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -35,6 +36,7 @@ public class NewBotDetection {
private String name;

@NotNull
@JsonString
private String configuration;

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -30,6 +31,7 @@ public class NewCertificate {
private String name;

@NotNull
@JsonString
private String configuration;

public String getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -32,6 +33,7 @@ public class NewDeviceIdentifier {
private String name;

@NotNull
@JsonString
private String configuration;

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

Expand All @@ -31,6 +32,7 @@ public class NewExtensionGrant {
private String name;

@NotNull
@JsonString
private String configuration;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -35,6 +36,7 @@ public class NewFactor {
private String name;

@NotNull
@JsonString
private String configuration;

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

import java.util.List;
Expand All @@ -34,6 +35,7 @@ public class NewIdentityProvider {
private String name;

@NotNull
@JsonString
private String configuration;

private List<String> domainWhitelist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

Expand All @@ -36,6 +37,7 @@ public class NewReporter {
private String name;

@NotNull
@JsonString(message = "configuration must be json form")
private String configuration;

private boolean inherited;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -32,6 +33,7 @@ public class NewServiceResource {
private String type;

@NotNull
@JsonString
private String configuration;

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -27,6 +28,7 @@ public class UpdateAuthenticationDeviceNotifier {
private String name;

@NotNull
@JsonString
private String configuration;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -27,6 +28,7 @@ public class UpdateBotDetection {
private String name;

@NotNull
@JsonString
private String configuration;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -27,6 +28,7 @@ public class UpdateCertificate {
private String name;

@NotNull
@JsonString
private String configuration;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -27,6 +28,7 @@ public class UpdateDeviceIdentifier {
private String name;

@NotNull
@JsonString
private String configuration;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

Expand All @@ -28,6 +29,7 @@ public class UpdateExtensionGrant {
private String name;

@NotNull
@JsonString
private String configuration;

@Pattern(regexp = "[A-Za-z][A-Za-z0-9+\\-.]*:(?://(?:(?:[A-Za-z0-9\\-._~!$&'()*+,;=:]|%[0-9A-Fa-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}|::(?:[0-9A-Fa-f]{1,4}:){5}|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}|(?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}|(?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:|(?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::)(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)|[Vv][0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[A-Za-z0-9\\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*)(?::[0-9]*)?(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*|/(?:(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*)?|(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*|)(?:\\?(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*)?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -27,6 +28,7 @@ public class UpdateFactor {
private String name;

@NotNull
@JsonString
private String configuration;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -34,6 +35,7 @@ public class UpdateIdentityProvider {
private String name;

@NotNull
@JsonString
private String configuration;

private Map<String, String> mappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

Expand All @@ -31,6 +32,7 @@ public class UpdateReporter {
private String name;

@NotNull
@JsonString
private String configuration;

private boolean inherited;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.gravitee.am.service.model;

import io.gravitee.am.service.validators.jsonstring.JsonString;
import jakarta.validation.constraints.NotNull;

/**
Expand All @@ -27,6 +28,7 @@ public class UpdateServiceResource {
private String name;

@NotNull
@JsonString
private String configuration;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.am.service.validators.jsonstring;

import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Constraint(validatedBy = JsonStringValidator.class)
public @interface JsonString {

String message() default "Malformed json";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};
}
Loading