fix #835 add max input size
This commit is contained in:
parent
237748c646
commit
9d256dc7b4
11 changed files with 162 additions and 25 deletions
|
@ -20,6 +20,7 @@ import javax.validation.constraints.Size;
|
|||
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
|
@ -35,7 +36,7 @@ public class CreateForm {
|
|||
@Size(max = 10000)
|
||||
public String token;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String permissions;
|
||||
|
||||
@Size(max = 10000)
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.validation.constraints.Size;
|
|||
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
|
@ -40,13 +41,13 @@ public class CreateForm {
|
|||
public String name;
|
||||
|
||||
@Required
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String handlerName;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String handlerParameter;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String handlerScript;
|
||||
|
||||
@Required
|
||||
|
@ -57,7 +58,7 @@ public class CreateForm {
|
|||
@Size(max = 5)
|
||||
public String available;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String permissions;
|
||||
|
||||
@Required
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.codelibs.fess.app.web.admin.elevateword;
|
|||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
|
@ -39,7 +40,7 @@ public class CreateForm {
|
|||
|
||||
public String targetLabel;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String permissions;
|
||||
|
||||
@Required
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.validation.constraints.Size;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.codelibs.fess.validation.UriType;
|
||||
import org.codelibs.fess.validation.UriTypeValidator.ProtocolType;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
|
@ -44,22 +45,22 @@ public class CreateForm {
|
|||
|
||||
@Required
|
||||
@UriType(protocolType = ProtocolType.FILE)
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String paths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String includedPaths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String excludedPaths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String includedDocPaths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String excludedDocPaths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String configParameter;
|
||||
|
||||
@Min(value = 0)
|
||||
|
@ -92,7 +93,7 @@ public class CreateForm {
|
|||
@Size(max = 5)
|
||||
public String available;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String permissions;
|
||||
|
||||
@Required
|
||||
|
|
|
@ -21,6 +21,7 @@ import javax.validation.constraints.Size;
|
|||
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
|
@ -38,7 +39,7 @@ public class CreateForm {
|
|||
public String term;
|
||||
|
||||
@Required
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String query;
|
||||
|
||||
@Required
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.validation.constraints.Size;
|
|||
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
|
@ -44,13 +45,13 @@ public class CreateForm {
|
|||
@Pattern(regexp = "^[a-zA-Z0-9_-| ]+$")
|
||||
public String value;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String includedPaths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String excludedPaths;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String permissions;
|
||||
|
||||
@Min(value = 0)
|
||||
|
|
|
@ -22,6 +22,7 @@ import javax.validation.constraints.Size;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CronExpression;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
import org.lastaflute.web.validation.theme.conversion.ValidateTypeFailure;
|
||||
|
||||
|
@ -49,7 +50,7 @@ public class CreateForm {
|
|||
@Size(max = 100)
|
||||
public String scriptType;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String scriptData;
|
||||
|
||||
public String crawler;
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.codelibs.core.lang.StringUtil;
|
|||
import org.codelibs.fess.Constants;
|
||||
import org.codelibs.fess.app.web.CrudMode;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.validation.CustomSize;
|
||||
import org.codelibs.fess.validation.UriType;
|
||||
import org.codelibs.fess.validation.UriTypeValidator.ProtocolType;
|
||||
import org.lastaflute.web.validation.Required;
|
||||
|
@ -46,22 +47,22 @@ public class CreateForm {
|
|||
|
||||
@Required
|
||||
@UriType(protocolType = ProtocolType.WEB)
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String urls;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String includedUrls;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String excludedUrls;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String includedDocUrls;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String excludedDocUrls;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String configParameter;
|
||||
|
||||
@Min(value = 0)
|
||||
|
@ -98,7 +99,7 @@ public class CreateForm {
|
|||
@Size(max = 5)
|
||||
public String available;
|
||||
|
||||
@Size(max = 4000)
|
||||
@CustomSize(maxKey = "form.admin.max.input.size")
|
||||
public String permissions;
|
||||
|
||||
@Required
|
||||
|
|
56
src/main/java/org/codelibs/fess/validation/CustomSize.java
Normal file
56
src/main/java/org/codelibs/fess/validation/CustomSize.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright 2012-2016 CodeLibs Project and the Others.
|
||||
*
|
||||
* 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 org.codelibs.fess.validation;
|
||||
|
||||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
|
||||
import static java.lang.annotation.ElementType.CONSTRUCTOR;
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.Payload;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
|
||||
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = CustomSizeValidator.class)
|
||||
public @interface CustomSize {
|
||||
|
||||
String message() default "{javax.validation.constraints.Size.message}";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
Class<? extends Payload>[] payload() default {};
|
||||
|
||||
/**
|
||||
* @return name of size the element must be higher or equal to
|
||||
*/
|
||||
String minKey() default StringUtil.EMPTY;
|
||||
|
||||
/**
|
||||
* @return name of size the element must be lower or equal to
|
||||
*/
|
||||
String maxKey() default StringUtil.EMPTY;
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright 2012-2016 CodeLibs Project and the Others.
|
||||
*
|
||||
* 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 org.codelibs.fess.validation;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext;
|
||||
|
||||
public class CustomSizeValidator implements ConstraintValidator<CustomSize, String> {
|
||||
private int min = 0;
|
||||
private int max = Integer.MAX_VALUE;
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
public void initialize(final CustomSize constraintAnnotation) {
|
||||
FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final String minKey = constraintAnnotation.minKey();
|
||||
if (StringUtil.isNotBlank(minKey)) {
|
||||
min = Integer.parseInt(fessConfig.get(minKey));
|
||||
}
|
||||
final String maxKey = constraintAnnotation.maxKey();
|
||||
if (StringUtil.isNotBlank(maxKey)) {
|
||||
max = Integer.parseInt(fessConfig.get(maxKey));
|
||||
}
|
||||
message = constraintAnnotation.message();
|
||||
validateParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final String value, final ConstraintValidatorContext context) {
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
|
||||
hibernateContext.disableDefaultConstraintViolation();
|
||||
hibernateContext.addExpressionVariable("min", min).addExpressionVariable("max", max).buildConstraintViolationWithTemplate(message)
|
||||
.addConstraintViolation();
|
||||
int length = value.length();
|
||||
return length >= min && length <= max;
|
||||
}
|
||||
|
||||
private void validateParameters() {
|
||||
if (min < 0) {
|
||||
throw new IllegalArgumentException("The min parameter cannot be negative.");
|
||||
}
|
||||
if (max < 0) {
|
||||
throw new IllegalArgumentException("The max parameter cannot be negative.");
|
||||
}
|
||||
if (max < min) {
|
||||
throw new IllegalArgumentException("The length cannot be negative.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -282,6 +282,8 @@ index.backup.targets=.fess_basic_config.bulk,.fess_config.bulk,.fess_user.bulk,s
|
|||
# ========================================================================================
|
||||
# Web
|
||||
# =====
|
||||
form.admin.max.input.size=4000
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Permission
|
||||
# ------
|
||||
|
|
Loading…
Add table
Reference in a new issue