use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class BDBPreferenceStoreFactoryService method createInstance.
@Override
public PreferenceStore createInstance(final ConfiguredObject<?> parent, final Map<String, Object> preferenceStoreAttributes) {
final Object path = preferenceStoreAttributes.get(PATH);
if (path == null || !(path instanceof String)) {
throw new IllegalConfigurationException("BDBPreferenceStore requires path");
}
final String storePath = (String) path;
return new BDBPreferenceStore(parent, storePath);
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class PrincipalDatabaseAuthenticationManagerTest method testInitialiseWhenPasswordFileNotFound.
public void testInitialiseWhenPasswordFileNotFound() throws Exception {
PasswordCredentialManagingAuthenticationProvider mockAuthProvider = mock(PasswordCredentialManagingAuthenticationProvider.class);
when(mockAuthProvider.getContextValue(Integer.class, AbstractScramAuthenticationManager.QPID_AUTHMANAGER_SCRAM_ITERATION_COUNT)).thenReturn(4096);
_principalDatabase = new PlainPasswordFilePrincipalDatabase(mockAuthProvider);
setupManager(true);
try {
_manager.initialise();
fail("Initialisiation should fail when users file does not exist");
} catch (IllegalConfigurationException e) {
assertTrue(e.getCause() instanceof FileNotFoundException);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AclFileParser method parseAcl.
private static void parseAcl(Integer number, List<String> args, final RuleSetCreator ruleSetCreator, final int line) {
if (args.size() < 3) {
throw new IllegalConfigurationException(String.format(NOT_ENOUGH_ACL_MSG, line));
}
String text = args.get(0);
RuleOutcome outcome;
try {
outcome = RuleOutcome.valueOf(text.replace('-', '_').toUpperCase());
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Not a valid permission: " + text, e);
}
String identity = args.get(1);
LegacyOperation operation = LegacyOperation.valueOf(args.get(2).toUpperCase());
if (number != null && !ruleSetCreator.isValidNumber(number)) {
throw new IllegalConfigurationException(String.format(BAD_ACL_RULE_NUMBER_MSG, line));
}
if (args.size() == 3) {
ruleSetCreator.addRule(number, identity, outcome, operation);
} else {
ObjectType object = ObjectType.valueOf(args.get(3).toUpperCase());
AclRulePredicates predicates = toRulePredicates(args.subList(4, args.size()), line);
ruleSetCreator.addRule(number, identity, outcome, operation, object, predicates);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AclFileParser method parse.
public static RuleSet parse(final Reader configReader, EventLoggerProvider eventLogger) {
RuleSetCreator ruleSetCreator = new RuleSetCreator();
int line = 0;
try (Reader fileReader = configReader) {
LOGGER.debug("About to load ACL file");
StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(fileReader));
// setup the tokenizer
tokenizer.resetSyntax();
// single line comments
tokenizer.commentChar(COMMENT);
// return EOL as a token
tokenizer.eolIsSignificant(true);
// equals is a token
tokenizer.ordinaryChar('=');
// continuation character (when followed by EOL)
tokenizer.ordinaryChar(CONTINUATION);
// double quote
tokenizer.quoteChar('"');
// single quote
tokenizer.quoteChar('\'');
// whitespace (to be ignored) TODO properly
tokenizer.whitespaceChars('\u0000', '\u0020');
// unquoted token characters [a-z]
tokenizer.wordChars('a', 'z');
// [A-Z]
tokenizer.wordChars('A', 'Z');
// [0-9]
tokenizer.wordChars('0', '9');
// underscore
tokenizer.wordChars('_', '_');
// dash
tokenizer.wordChars('-', '-');
// dot
tokenizer.wordChars('.', '.');
// star
tokenizer.wordChars('*', '*');
// at
tokenizer.wordChars('@', '@');
// colon
tokenizer.wordChars(':', ':');
// parse the acl file lines
Stack<String> stack = new Stack<>();
int current;
do {
current = tokenizer.nextToken();
line = tokenizer.lineno() - 1;
switch(current) {
case StreamTokenizer.TT_EOF:
case StreamTokenizer.TT_EOL:
if (stack.isEmpty()) {
// blank line
break;
}
// pull out the first token from the bottom of the stack and check arguments exist
String first = stack.firstElement();
stack.removeElementAt(0);
if (stack.isEmpty()) {
throw new IllegalConfigurationException(String.format(NOT_ENOUGH_TOKENS_MSG, line));
}
// check for and parse optional initial number for ACL lines
Integer number = null;
if (first != null && first.matches("\\d+")) {
// set the acl number and get the next element
number = Integer.valueOf(first);
first = stack.firstElement();
stack.removeElementAt(0);
}
if (ACL.equalsIgnoreCase(first)) {
parseAcl(number, stack, ruleSetCreator, line);
} else if (number == null) {
if ("GROUP".equalsIgnoreCase(first)) {
throw new IllegalConfigurationException(String.format("GROUP keyword not supported at " + "line %d. Groups should defined " + "via a Group Provider, not in " + "the ACL file.", line));
} else if (CONFIG.equalsIgnoreCase(first)) {
parseConfig(stack, ruleSetCreator, line);
} else {
throw new IllegalConfigurationException(String.format(UNRECOGNISED_INITIAL_MSG, first, line));
}
} else {
throw new IllegalConfigurationException(String.format(NUMBER_NOT_ALLOWED_MSG, first, line));
}
// reset stack, start next line
stack.clear();
break;
case StreamTokenizer.TT_NUMBER:
stack.push(Integer.toString(Double.valueOf(tokenizer.nval).intValue()));
break;
case StreamTokenizer.TT_WORD:
// token
stack.push(tokenizer.sval);
break;
default:
if (tokenizer.ttype == CONTINUATION) {
int next = tokenizer.nextToken();
line = tokenizer.lineno() - 1;
if (next == StreamTokenizer.TT_EOL) {
// continue reading next line
break;
}
// invalid location for continuation character (add one to line because we ate the EOL)
throw new IllegalConfigurationException(String.format(PREMATURE_CONTINUATION_MSG, line + 1));
} else if (tokenizer.ttype == '\'' || tokenizer.ttype == '"') {
// quoted token
stack.push(tokenizer.sval);
} else {
// single character
stack.push(Character.toString((char) tokenizer.ttype));
}
}
} while (current != StreamTokenizer.TT_EOF);
if (!stack.isEmpty()) {
throw new IllegalConfigurationException(String.format(PREMATURE_EOF_MSG, line));
}
} catch (IllegalArgumentException iae) {
throw new IllegalConfigurationException(String.format(PARSE_TOKEN_FAILED_MSG, line), iae);
} catch (IOException ioe) {
throw new IllegalConfigurationException(CANNOT_LOAD_MSG, ioe);
}
return ruleSetCreator.createRuleSet(eventLogger);
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AclFileAccessControlProviderImpl method reloadAclFile.
private void reloadAclFile() {
try {
recreateAccessController();
LOGGER.debug("Calling changeAttributes to try to force update");
// force the change listener to fire, causing the parent broker to update its cache
changeAttributes(Collections.<String, Object>emptyMap());
getEventLogger().message(AccessControlMessages.LOADED(String.valueOf(getPath()).startsWith("data:") ? "data:..." : getPath()));
} catch (RuntimeException e) {
throw new IllegalConfigurationException(e.getMessage(), e);
}
}
Aggregations