broker/ACLFileParser: code formatter used
This commit is contained in:
@@ -13,29 +13,32 @@
|
|||||||
*
|
*
|
||||||
* You may elect to redistribute this code under either of these licenses.
|
* You may elect to redistribute this code under either of these licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.moquette.spi.impl.security;
|
package io.moquette.spi.impl.security;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the acl configuration file.
|
* Parses the acl configuration file. If a line starts with # it's comment. Blank lines are skipped.
|
||||||
* If a line starts with # it's comment.
|
* The format is "topic [read|write|readwrite] {topic name}"
|
||||||
* Blank lines are skipped. The format is "topic [read|write|readwrite] {topic name}"
|
|
||||||
*
|
*
|
||||||
* @author andrea
|
* @author andrea
|
||||||
* */
|
*/
|
||||||
public class ACLFileParser {
|
public class ACLFileParser {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ACLFileParser.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ACLFileParser.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the configuration from file.
|
* Parse the configuration from file.
|
||||||
* @param file to parse
|
*
|
||||||
|
* @param file
|
||||||
|
* to parse
|
||||||
* @return the collector of authorizations form reader passed into.
|
* @return the collector of authorizations form reader passed into.
|
||||||
* @throws ParseException if the format is not compliant.
|
* @throws ParseException
|
||||||
|
* if the format is not compliant.
|
||||||
*/
|
*/
|
||||||
public static AuthorizationsCollector parse(File file) throws ParseException {
|
public static AuthorizationsCollector parse(File file) throws ParseException {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
@@ -43,27 +46,37 @@ public class ACLFileParser {
|
|||||||
return AuthorizationsCollector.emptyImmutableCollector();
|
return AuthorizationsCollector.emptyImmutableCollector();
|
||||||
}
|
}
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
LOG.warn(String.format("parsing not existing file %s, so fallback on default configuration!", file.getAbsolutePath()));
|
LOG.warn(
|
||||||
|
String.format(
|
||||||
|
"parsing not existing file %s, so fallback on default configuration!",
|
||||||
|
file.getAbsolutePath()));
|
||||||
return AuthorizationsCollector.emptyImmutableCollector();
|
return AuthorizationsCollector.emptyImmutableCollector();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
FileReader reader = new FileReader(file);
|
FileReader reader = new FileReader(file);
|
||||||
return parse(reader);
|
return parse(reader);
|
||||||
} catch (FileNotFoundException fex) {
|
} catch (FileNotFoundException fex) {
|
||||||
LOG.warn(String.format("parsing not existing file %s, so fallback on default configuration!", file.getAbsolutePath()), fex);
|
LOG.warn(
|
||||||
|
String.format(
|
||||||
|
"parsing not existing file %s, so fallback on default configuration!",
|
||||||
|
file.getAbsolutePath()),
|
||||||
|
fex);
|
||||||
return AuthorizationsCollector.emptyImmutableCollector();
|
return AuthorizationsCollector.emptyImmutableCollector();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the ACL configuration file
|
* Parse the ACL configuration file
|
||||||
* @param reader to parse
|
*
|
||||||
|
* @param reader
|
||||||
|
* to parse
|
||||||
* @return the collector of authorizations form reader passed into.
|
* @return the collector of authorizations form reader passed into.
|
||||||
* @throws ParseException if the format is not compliant.
|
* @throws ParseException
|
||||||
|
* if the format is not compliant.
|
||||||
*/
|
*/
|
||||||
public static AuthorizationsCollector parse(Reader reader) throws ParseException {
|
public static AuthorizationsCollector parse(Reader reader) throws ParseException {
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
//just log and return default properties
|
// just log and return default properties
|
||||||
LOG.warn("parsing NULL reader, so fallback on default configuration!");
|
LOG.warn("parsing NULL reader, so fallback on default configuration!");
|
||||||
return AuthorizationsCollector.emptyImmutableCollector();
|
return AuthorizationsCollector.emptyImmutableCollector();
|
||||||
}
|
}
|
||||||
@@ -77,15 +90,15 @@ public class ACLFileParser {
|
|||||||
int commentMarker = line.indexOf('#');
|
int commentMarker = line.indexOf('#');
|
||||||
if (commentMarker != -1) {
|
if (commentMarker != -1) {
|
||||||
if (commentMarker == 0) {
|
if (commentMarker == 0) {
|
||||||
//skip its a comment
|
// skip its a comment
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
//it's a malformed comment
|
// it's a malformed comment
|
||||||
throw new ParseException(line, commentMarker);
|
throw new ParseException(line, commentMarker);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (line.isEmpty() || line.matches("^\\s*$")) {
|
if (line.isEmpty() || line.matches("^\\s*$")) {
|
||||||
//skip it's a black line
|
// skip it's a black line
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user