Skip to content

Commit

Permalink
Fixed Pattern constraint validator messages
Browse files Browse the repository at this point in the history
- Pattern uses {jakarta.validation.constraints.Pattern.message} by default

Signed-off-by: David Matějček <dmatej@seznam.cz>
  • Loading branch information
dmatej committed Apr 3, 2022
1 parent 87243bd commit d2d04c4
Show file tree
Hide file tree
Showing 37 changed files with 1,001 additions and 740 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,23 +18,26 @@
package org.glassfish.ha.commands;

import com.sun.enterprise.config.serverbeans.Domain;
import java.util.*;

import jakarta.validation.constraints.Pattern;

import java.util.ArrayList;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.CommandLock;

import org.jvnet.hk2.annotations.Service;
import org.glassfish.hk2.api.PerLookup;

import jakarta.validation.constraints.Pattern;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.api.admin.*;
import org.glassfish.api.admin.RestEndpoint;
import org.glassfish.api.admin.RestEndpoints;
import org.glassfish.ha.store.spi.BackingStoreFactoryRegistry;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;

/**
* The list-persistence-types command lists different kinds of persistence options for session data
Expand All @@ -51,10 +55,12 @@
})
public class ListPersistenceTypesCommand implements AdminCommand {

@Param(name="type", optional=false, primary=false)
private static final String CONTAINER_TYPES = "(ejb|web)";

@Param(name = "type", optional = false, primary = false)
@I18n("list.persistence.types.container")
@Pattern(regexp = "(ejb|web)")
private String containerType = "";
@Pattern(regexp = CONTAINER_TYPES, message = "Valid values: " + CONTAINER_TYPES)
private final String containerType = "";

private Logger logger;
private static final String EOL = "\n";
Expand Down Expand Up @@ -89,7 +95,7 @@ public void execute(AdminCommandContext context) {
output = output.substring(0, output.length()-1);
}
Properties extraProperties = new Properties();
extraProperties.put("types", new ArrayList<String>(allPersistenceTypes));
extraProperties.put("types", new ArrayList<>(allPersistenceTypes));

report.setExtraProperties(extraProperties);
report.setMessage(output);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,26 +18,27 @@
package org.glassfish.connectors.config;

import com.sun.enterprise.config.serverbeans.Resource;
import org.glassfish.resourcebase.resources.ResourceDeploymentOrder;
import org.glassfish.resourcebase.resources.ResourceTypeOrder;
import org.jvnet.hk2.config.*;

import jakarta.validation.constraints.Pattern;

import java.beans.PropertyVetoException;
import java.util.List;

import org.glassfish.api.admin.RestRedirect;
import org.glassfish.api.admin.RestRedirects;
import org.glassfish.api.admin.config.PropertiesDesc;
import org.glassfish.quality.ToDo;
import org.glassfish.resourcebase.resources.ResourceDeploymentOrder;
import org.glassfish.resourcebase.resources.ResourceTypeOrder;
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.Configured;
import org.jvnet.hk2.config.DuckTyped;
import org.jvnet.hk2.config.Element;
import org.jvnet.hk2.config.types.Property;
import org.jvnet.hk2.config.types.PropertyBag;
import org.glassfish.api.admin.RestRedirects;
import org.glassfish.api.admin.RestRedirect;
import static org.glassfish.config.support.Constants.NAME_REGEX;

import org.glassfish.quality.ToDo;

import jakarta.validation.constraints.Pattern;
/**
*
*/
import static org.glassfish.config.support.Constants.NAME_REGEX;

/* @XmlType(name = "", propOrder = {
"property"
Expand All @@ -56,23 +58,25 @@
@ResourceTypeOrder(deploymentOrder= ResourceDeploymentOrder.RESOURCEADAPTERCONFIG_RESOURCE)
public interface ResourceAdapterConfig extends ConfigBeanProxy, Resource, PropertyBag {

String PATTERN_RA_NAME = "[^',][^',\\\\]*";

/**
* Gets the value of the name property.
*
* @return possible object is
* {@link String }
*/
@Attribute
@Pattern(regexp=NAME_REGEX)
public String getName();
@Pattern(regexp = NAME_REGEX, message = "Pattern: " + NAME_REGEX)
String getName();

/**
* Sets the value of the name property.
*
* @param value allowed object is
* {@link String }
* {@link String }
*/
public void setName(String value) throws PropertyVetoException;
void setName(String value) throws PropertyVetoException;

/**
* Gets the value of the threadPoolIds property.
Expand All @@ -81,47 +85,50 @@ public interface ResourceAdapterConfig extends ConfigBeanProxy, Resource, Proper
* {@link String }
*/
@Attribute
public String getThreadPoolIds();
String getThreadPoolIds();

/**
* Sets the value of the threadPoolIds property.
*
* @param value allowed object is
* {@link String }
* {@link String }
*/
public void setThreadPoolIds(String value) throws PropertyVetoException;
void setThreadPoolIds(String value) throws PropertyVetoException;

/**
* Gets the value of the resourceAdapterName property.
*
* @return possible object is
* {@link String }
*/
@Attribute(key=true)
@Pattern(regexp="[^',][^',\\\\]*")
public String getResourceAdapterName();
@Attribute(key = true)
@Pattern(regexp = PATTERN_RA_NAME, message = "Pattern: " + PATTERN_RA_NAME)
String getResourceAdapterName();

/**
* Sets the value of the resourceAdapterName property.
*
* @param value allowed object is
* {@link String }
* {@link String }
*/
public void setResourceAdapterName(String value) throws PropertyVetoException;
void setResourceAdapterName(String value) throws PropertyVetoException;

/**
Properties as per {@link org.jvnet.hk2.config.types.PropertyBag}
* Properties as per {@link org.jvnet.hk2.config.types.PropertyBag}
*/
@ToDo(priority=ToDo.Priority.IMPORTANT, details="Provide PropertyDesc for legal props" )
@PropertiesDesc(props={})
@Override
@ToDo(priority = ToDo.Priority.IMPORTANT, details = "Provide PropertyDesc for legal props")
@PropertiesDesc(props = {})
@Element
List<Property> getProperty();

@Override
@DuckTyped
String getIdentity();

class Duck {
public static String getIdentity(ResourceAdapterConfig resource){

public static String getIdentity(ResourceAdapterConfig resource) {
return resource.getResourceAdapterName();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -16,17 +17,18 @@

package org.glassfish.connectors.config;

import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.Configured;
import org.jvnet.hk2.config.Element;
import org.jvnet.hk2.config.ConfigBeanProxy;
import static org.glassfish.config.support.Constants.NAME_REGEX;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;

import java.beans.PropertyVetoException;
import java.util.List;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.Configured;
import org.jvnet.hk2.config.Element;

import static org.glassfish.config.support.Constants.NAME_REGEX;

/**
* Perform mapping from principal received during Servlet/EJB authentication,
Expand All @@ -49,52 +51,53 @@ public interface SecurityMap extends ConfigBeanProxy {
* @return possible object is
* {@link String }
*/
@Attribute(key=true)
@Attribute(key = true)
@NotNull
@Pattern(regexp=NAME_REGEX)
public String getName();
@Pattern(regexp = NAME_REGEX, message = "Pattern: " + NAME_REGEX)
String getName();

/**
* Sets the value of the name property.
*
* @param value allowed object is
* {@link String }
* {@link String }
*/
public void setName(String value) throws PropertyVetoException;
void setName(String value) throws PropertyVetoException;

/**
* Gets the value of the backendPrincipal property.
*
* @return possible object is
* {@link BackendPrincipal }
*/
@Element(required=true)
public BackendPrincipal getBackendPrincipal();
@Element(required = true)
BackendPrincipal getBackendPrincipal();

/**
* Sets the value of the backendPrincipal property.
*
* @param value allowed object is
* {@link BackendPrincipal }
* {@link BackendPrincipal }
*/
public void setBackendPrincipal(BackendPrincipal value) throws PropertyVetoException;
void setBackendPrincipal(BackendPrincipal value) throws PropertyVetoException;

/**
* get the list of principals to be mapped to backend-principal
*
* @return list of principals
*/
@Element
public List<String> getPrincipal();
List<String> getPrincipal();

void setPrincipal(List<String> principals) throws PropertyVetoException;


/**
* get the list of user-groups to be mapped to backend principal
*
* @return list of user-groups
*/
@Element
public List<String> getUserGroup();
List<String> getUserGroup();

void setUserGroup(List<String> userGroups) throws PropertyVetoException;
}

0 comments on commit d2d04c4

Please sign in to comment.