|
18 | 18 | import static org.springframework.data.config.ParsingUtils.*;
|
19 | 19 | import static org.springframework.data.mongodb.config.MongoParsingUtils.*;
|
20 | 20 |
|
| 21 | +import java.util.Collections; |
| 22 | +import java.util.HashSet; |
| 23 | +import java.util.Set; |
| 24 | + |
21 | 25 | import org.springframework.beans.factory.BeanDefinitionStoreException;
|
22 | 26 | import org.springframework.beans.factory.config.BeanDefinition;
|
23 | 27 | import org.springframework.beans.factory.parsing.BeanComponentDefinition;
|
|
47 | 51 | * @author Viktor Khoroshko
|
48 | 52 | */
|
49 | 53 | public class MongoDbFactoryParser extends AbstractBeanDefinitionParser {
|
| 54 | + private static final Set<String> MONGO_URI_ALLOWED_ADDITIONAL_ATTRIBUTES; |
| 55 | + |
| 56 | + static { |
| 57 | + Set<String> mongoUriAllowedAdditionalAttributes = new HashSet<String>(); |
| 58 | + mongoUriAllowedAdditionalAttributes.add("id"); |
| 59 | + mongoUriAllowedAdditionalAttributes.add("write-concern"); |
| 60 | + |
| 61 | + MONGO_URI_ALLOWED_ADDITIONAL_ATTRIBUTES = Collections.unmodifiableSet(mongoUriAllowedAdditionalAttributes); |
| 62 | + } |
50 | 63 |
|
51 | 64 | /*
|
52 | 65 | * (non-Javadoc)
|
@@ -74,10 +87,14 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
|
74 | 87 | BeanDefinition mongoUri = getMongoUri(element);
|
75 | 88 |
|
76 | 89 | if (mongoUri != null) {
|
77 |
| - if (element.hasAttribute("mongo-ref") || element.hasAttribute("dbname") |
78 |
| - || element.hasAttribute("authentication-dbname") |
79 |
| - || element.hasAttribute("port") || element.hasAttribute("host") |
80 |
| - || element.hasAttribute("username") || element.hasAttribute("password")) { |
| 90 | + int allowedAttributesCount = 1; |
| 91 | + for (String attribute : MONGO_URI_ALLOWED_ADDITIONAL_ATTRIBUTES) { |
| 92 | + if (element.hasAttribute(attribute)) { |
| 93 | + allowedAttributesCount++; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + if (element.getAttributes().getLength() > allowedAttributesCount) { |
81 | 98 | parserContext.getReaderContext().error("Configure either Mongo URI or details individually!",
|
82 | 99 | parserContext.extractSource(element));
|
83 | 100 | }
|
|
0 commit comments