SOLR-8385: Narrow StreamFactory.withFunctionName clazz parameter to prevent misconfiguration

This commit is contained in:
Kevin Risden 2016-10-06 18:36:39 -05:00
parent 8225569b15
commit 6aa28bd655
4 changed files with 31 additions and 31 deletions

View File

@ -254,6 +254,7 @@ Other Changes
* SOLR-9589: Remove jackson dependency from SolrJ (Ishan Chattopadhyaya, noble)
* SOLR-8385: Narrow StreamFactory.withFunctionName clazz parameter to prevent misconfiguration (Jason Gerlowski, Kevin Risden)
================== 6.2.1 ==================

View File

@ -80,8 +80,8 @@ public class GraphHandler extends RequestHandlerBase implements SolrCoreAware, P
* </lst>
* */
String defaultCollection = null;
String defaultZkhost = null;
String defaultCollection;
String defaultZkhost;
CoreContainer coreContainer = core.getCoreDescriptor().getCoreContainer();
this.coreName = core.getName();
@ -140,7 +140,8 @@ public class GraphHandler extends RequestHandlerBase implements SolrCoreAware, P
if(null != functionMappingsObj){
NamedList<?> functionMappings = (NamedList<?>)functionMappingsObj;
for(Entry<String,?> functionMapping : functionMappings){
Class<?> clazz = core.getResourceLoader().findClass((String)functionMapping.getValue(), Expressible.class);
Class<? extends Expressible> clazz = core.getResourceLoader().findClass((String)functionMapping.getValue(),
Expressible.class);
streamFactory.withFunctionName(functionMapping.getKey(), clazz);
}
}

View File

@ -69,7 +69,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,
private StreamFactory streamFactory = new StreamFactory();
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private String coreName;
private Map<String, DaemonStream> daemons = new HashMap();
private Map<String, DaemonStream> daemons = new HashMap<>();
@Override
public PermissionNameProvider.Name getPermissionName(AuthorizationContext request) {
@ -88,8 +88,8 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,
* </lst>
* */
String defaultCollection = null;
String defaultZkhost = null;
String defaultCollection;
String defaultZkhost;
CoreContainer coreContainer = core.getCoreDescriptor().getCoreContainer();
this.coreName = core.getName();
@ -158,7 +158,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,
if(null != functionMappingsObj){
NamedList<?> functionMappings = (NamedList<?>)functionMappingsObj;
for(Entry<String,?> functionMapping : functionMappings){
Class<?> clazz = core.getResourceLoader().findClass((String)functionMapping.getValue(), Expressible.class);
Class<? extends Expressible> clazz = core.getResourceLoader().findClass((String)functionMapping.getValue(), Expressible.class);
streamFactory.withFunctionName(functionMapping.getKey(), clazz);
}
}
@ -186,7 +186,7 @@ public class StreamHandler extends RequestHandlerBase implements SolrCoreAware,
return;
}
TupleStream tupleStream = null;
TupleStream tupleStream;
try {
tupleStream = this.streamFactory.constructStream(params.get("expr"));

View File

@ -42,12 +42,12 @@ import org.apache.solr.client.solrj.io.stream.metrics.Metric;
public class StreamFactory implements Serializable {
private transient HashMap<String,String> collectionZkHosts;
private transient HashMap<String,Class> functionNames;
private transient HashMap<String,Class<? extends Expressible>> functionNames;
private transient String defaultZkHost;
public StreamFactory(){
collectionZkHosts = new HashMap<String,String>();
functionNames = new HashMap<String,Class>();
collectionZkHosts = new HashMap<>();
functionNames = new HashMap<>();
}
public StreamFactory withCollectionZkHost(String collectionName, String zkHost){
@ -71,10 +71,10 @@ public class StreamFactory implements Serializable {
return null;
}
public Map<String,Class> getFunctionNames(){
public Map<String,Class<? extends Expressible>> getFunctionNames(){
return functionNames;
}
public StreamFactory withFunctionName(String functionName, Class clazz){
public StreamFactory withFunctionName(String functionName, Class<? extends Expressible> clazz){
this.functionNames.put(functionName, clazz);
return this;
}
@ -100,7 +100,7 @@ public class StreamFactory implements Serializable {
}
public List<StreamExpressionNamedParameter> getNamedOperands(StreamExpression expression){
List<StreamExpressionNamedParameter> namedParameters = new ArrayList<StreamExpressionNamedParameter>();
List<StreamExpressionNamedParameter> namedParameters = new ArrayList<>();
for(StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpressionNamedParameter.class)){
namedParameters.add((StreamExpressionNamedParameter)parameter);
}
@ -119,7 +119,7 @@ public class StreamFactory implements Serializable {
}
public List<StreamExpression> getExpressionOperands(StreamExpression expression){
List<StreamExpression> namedParameters = new ArrayList<StreamExpression>();
List<StreamExpression> namedParameters = new ArrayList<>();
for(StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpression.class)){
namedParameters.add((StreamExpression)parameter);
}
@ -127,7 +127,7 @@ public class StreamFactory implements Serializable {
return namedParameters;
}
public List<StreamExpression> getExpressionOperands(StreamExpression expression, String functionName){
List<StreamExpression> namedParameters = new ArrayList<StreamExpression>();
List<StreamExpression> namedParameters = new ArrayList<>();
for(StreamExpressionParameter parameter : getOperandsOfType(expression, StreamExpression.class)){
StreamExpression expressionOperand = (StreamExpression)parameter;
if(expressionOperand.getFunctionName().equals(functionName)){
@ -138,7 +138,7 @@ public class StreamFactory implements Serializable {
return namedParameters;
}
public List<StreamExpressionParameter> getOperandsOfType(StreamExpression expression, Class ... clazzes){
List<StreamExpressionParameter> parameters = new ArrayList<StreamExpressionParameter>();
List<StreamExpressionParameter> parameters = new ArrayList<>();
parameterLoop:
for(StreamExpressionParameter parameter : expression.getParameters()){
@ -155,7 +155,7 @@ public class StreamFactory implements Serializable {
}
public List<StreamExpression> getExpressionOperandsRepresentingTypes(StreamExpression expression, Class ... clazzes){
List<StreamExpression> matchingStreamExpressions = new ArrayList<StreamExpression>();
List<StreamExpression> matchingStreamExpressions = new ArrayList<>();
List<StreamExpression> allStreamExpressions = getExpressionOperands(expression);
parameterLoop:
@ -215,10 +215,9 @@ public class StreamFactory implements Serializable {
public TupleStream constructStream(StreamExpression expression) throws IOException{
String function = expression.getFunctionName();
if(functionNames.containsKey(function)){
Class clazz = functionNames.get(function);
Class<? extends Expressible> clazz = functionNames.get(function);
if(Expressible.class.isAssignableFrom(clazz) && TupleStream.class.isAssignableFrom(clazz)){
TupleStream stream = (TupleStream)createInstance(functionNames.get(function), new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
return stream;
return (TupleStream)createInstance(functionNames.get(function), new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
}
}
@ -231,10 +230,9 @@ public class StreamFactory implements Serializable {
public Metric constructMetric(StreamExpression expression) throws IOException{
String function = expression.getFunctionName();
if(functionNames.containsKey(function)){
Class clazz = functionNames.get(function);
Class<? extends Expressible> clazz = functionNames.get(function);
if(Expressible.class.isAssignableFrom(clazz) && Metric.class.isAssignableFrom(clazz)){
Metric metric = (Metric)createInstance(functionNames.get(function), new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
return metric;
return (Metric)createInstance(functionNames.get(function), new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
}
}
@ -272,7 +270,7 @@ public class StreamFactory implements Serializable {
else if(null == rightFieldName){
rightFieldName = part.trim();
}
else if(null == order){
else {
order = part.trim();
break; // we're done, stop looping
}
@ -334,7 +332,7 @@ public class StreamFactory implements Serializable {
public StreamOperation constructOperation(StreamExpression expression) throws IOException{
String function = expression.getFunctionName();
if(functionNames.containsKey(function)){
Class clazz = functionNames.get(function);
Class<? extends Expressible> clazz = functionNames.get(function);
if(Expressible.class.isAssignableFrom(clazz) && StreamOperation.class.isAssignableFrom(clazz)){
return (StreamOperation)createInstance(functionNames.get(function), new Class[]{ StreamExpression.class, StreamFactory.class }, new Object[]{ expression, this});
}
@ -360,8 +358,8 @@ public class StreamFactory implements Serializable {
}
}
public String getFunctionName(Class clazz) throws IOException{
for(Entry<String,Class> entry : functionNames.entrySet()){
public String getFunctionName(Class<? extends Expressible> clazz) throws IOException{
for(Entry<String,Class<? extends Expressible>> entry : functionNames.entrySet()){
if(entry.getValue() == clazz){
return entry.getKey();
}
@ -375,9 +373,9 @@ public class StreamFactory implements Serializable {
if("null".equals(lower)){ return null; }
if("true".equals(lower) || "false".equals(lower)){ return Boolean.parseBoolean(lower); }
try{ return Long.valueOf(original); } catch(Exception e){};
try{ if (original.matches(".{1,8}")){ return Float.valueOf(original); }} catch(Exception e){};
try{ if (original.matches(".{1,17}")){ return Double.valueOf(original); }} catch(Exception e){};
try{ return Long.valueOf(original); } catch(Exception ignored){};
try{ if (original.matches(".{1,8}")){ return Float.valueOf(original); }} catch(Exception ignored){};
try{ if (original.matches(".{1,17}")){ return Double.valueOf(original); }} catch(Exception ignored){};
// is a string
return original;