[Minor] Automated Code cleanups
This commit is contained in:
parent
f1ffa3a6db
commit
f1819edbdc
|
@ -21,7 +21,6 @@ import java.util.Locale;
|
|||
import java.util.Properties;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import li.strolch.model.Tags;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
|
|
@ -20,7 +20,6 @@ import static li.strolch.model.Tags.Json.*;
|
|||
import java.util.Properties;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import li.strolch.model.Tags;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
|
|
@ -30,7 +30,7 @@ public interface RealmHandler {
|
|||
*
|
||||
* @return the set of names of the configured {@link StrolchRealm StrolchRealms}
|
||||
*/
|
||||
public Set<String> getRealmNames();
|
||||
Set<String> getRealmNames();
|
||||
|
||||
/**
|
||||
* Returns the {@link StrolchRealm} with the given name. To get the default realm, use the constante
|
||||
|
@ -43,5 +43,5 @@ public interface RealmHandler {
|
|||
* @throws StrolchException
|
||||
* if the {@link StrolchRealm} does not exist with the given name
|
||||
*/
|
||||
public StrolchRealm getRealm(String realm);
|
||||
StrolchRealm getRealm(String realm);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import com.google.gson.JsonObject;
|
|||
import li.strolch.agent.impl.ComponentContainerImpl;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.runtime.configuration.ConfigurationParser;
|
||||
import li.strolch.runtime.configuration.RuntimeConfiguration;
|
||||
|
@ -141,14 +140,14 @@ public class StrolchAgent {
|
|||
/**
|
||||
* @see PrivilegeHandler#runAs(String, PrivilegedRunnable)
|
||||
*/
|
||||
public void runAs(String systemUser, PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||
public void runAs(String systemUser, PrivilegedRunnable runnable) throws Exception {
|
||||
getPrivilegeHandler().runAs(systemUser, runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PrivilegeHandler#runAsAgent(PrivilegedRunnable)
|
||||
*/
|
||||
public void runAsAgent(PrivilegedRunnable runnable) throws PrivilegeException, Exception {
|
||||
public void runAsAgent(PrivilegedRunnable runnable) throws Exception {
|
||||
getPrivilegeHandler().runAsAgent(runnable);
|
||||
}
|
||||
|
||||
|
@ -156,14 +155,14 @@ public class StrolchAgent {
|
|||
* @see PrivilegeHandler#runAsAgentWithResult(PrivilegedRunnableWithResult)
|
||||
*/
|
||||
public <T> T runAsWithResult(String systemUser, PrivilegedRunnableWithResult<T> runnable)
|
||||
throws PrivilegeException, Exception {
|
||||
throws Exception {
|
||||
return getPrivilegeHandler().runAsWithResult(systemUser, runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PrivilegeHandler#runAsAgentWithResult(PrivilegedRunnableWithResult)
|
||||
*/
|
||||
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws PrivilegeException, Exception {
|
||||
public <T> T runAsAgentWithResult(PrivilegedRunnableWithResult<T> runnable) throws Exception {
|
||||
return getPrivilegeHandler().runAsAgentWithResult(runnable);
|
||||
}
|
||||
|
||||
|
|
|
@ -391,7 +391,7 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName) {
|
||||
case STROLCH_BOOTSTRAP:
|
||||
|
@ -427,7 +427,7 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
switch (qName) {
|
||||
case STROLCH_BOOTSTRAP:
|
||||
|
@ -466,7 +466,7 @@ public class StrolchBootstrapper extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (this.textB != null)
|
||||
this.textB.append(ch, start, length);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ import static li.strolch.model.Tags.Json.*;
|
|||
import java.util.Properties;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.model.Tags.Json;
|
||||
|
||||
/**
|
||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||
|
|
|
@ -32,8 +32,8 @@ import li.strolch.utils.helper.StringHelper;
|
|||
public class ComponentDependencyAnalyzer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ComponentDependencyAnalyzer.class);
|
||||
private StrolchConfiguration strolchConfiguration;
|
||||
private Map<String, ComponentController> controllerMap;
|
||||
private final StrolchConfiguration strolchConfiguration;
|
||||
private final Map<String, ComponentController> controllerMap;
|
||||
|
||||
public ComponentDependencyAnalyzer(StrolchConfiguration strolchConfiguration,
|
||||
Map<String, ComponentController> controllerMap) {
|
||||
|
|
|
@ -27,10 +27,10 @@ import li.strolch.persistence.api.StrolchTransaction;
|
|||
|
||||
public class StoreToDaoElementListener implements StrolchElementListener {
|
||||
|
||||
private StrolchTransaction tx;
|
||||
private ResourceDao resourceDao;
|
||||
private OrderDao orderDao;
|
||||
private ActivityDao activityDao;
|
||||
private final StrolchTransaction tx;
|
||||
private final ResourceDao resourceDao;
|
||||
private final OrderDao orderDao;
|
||||
private final ActivityDao activityDao;
|
||||
|
||||
public StoreToDaoElementListener(StrolchTransaction tx) {
|
||||
this.tx = tx;
|
||||
|
|
|
@ -30,17 +30,17 @@ public class TransientTransaction extends AbstractTransaction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeChanges() throws Exception {
|
||||
protected void writeChanges() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollback() throws Exception {
|
||||
protected void rollback() {
|
||||
getTxResult().setState(TransactionState.ROLLED_BACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void commit() throws Exception {
|
||||
protected void commit() {
|
||||
getTxResult().setState(TransactionState.COMMITTED);
|
||||
}
|
||||
|
||||
|
|
|
@ -355,6 +355,6 @@ public class OperationsLog extends StrolchComponent {
|
|||
}
|
||||
|
||||
private interface LogTask {
|
||||
void run() throws Exception;
|
||||
void run();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,9 +68,7 @@ public class StrolchJobsHandler extends StrolchComponent {
|
|||
runAsAgent(ctx -> {
|
||||
for (String realmName : realmNames) {
|
||||
try (StrolchTransaction tx = openTx(ctx.getCertificate(), realmName, true)) {
|
||||
tx.streamResources(TYPE_STROLCH_JOB).forEach(jobRes -> {
|
||||
loadJob(jobs, jobRes, catchExceptions);
|
||||
});
|
||||
tx.streamResources(TYPE_STROLCH_JOB).forEach(jobRes -> loadJob(jobs, jobRes, catchExceptions));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1687,7 +1687,7 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
}
|
||||
}
|
||||
|
||||
protected abstract void writeChanges() throws Exception;
|
||||
protected abstract void writeChanges();
|
||||
|
||||
protected abstract void rollback() throws Exception;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public class TransactionResult {
|
|||
private TransactionState state;
|
||||
private Exception failCause;
|
||||
|
||||
private long startNanos;
|
||||
private final long startNanos;
|
||||
private Date startTime;
|
||||
private long txDuration;
|
||||
private long closeDuration;
|
||||
|
@ -216,23 +216,16 @@ public class TransactionResult {
|
|||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
switch (this.state) {
|
||||
case OPEN:
|
||||
sb.append("TX is still open after ");
|
||||
break;
|
||||
case COMMITTED:
|
||||
sb.append("TX was completed after ");
|
||||
break;
|
||||
case ROLLED_BACK:
|
||||
sb.append("TX was rolled back after ");
|
||||
break;
|
||||
case FAILED:
|
||||
sb.append("TX has failed after ");
|
||||
break;
|
||||
default:
|
||||
case OPEN -> sb.append("TX is still open after ");
|
||||
case COMMITTED -> sb.append("TX was completed after ");
|
||||
case ROLLED_BACK -> sb.append("TX was rolled back after ");
|
||||
case FAILED -> sb.append("TX has failed after ");
|
||||
default -> {
|
||||
sb.append("TX is in unhandled state ");
|
||||
sb.append(this.state);
|
||||
sb.append(" after ");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append(StringHelper.formatNanoDuration(this.txDuration));
|
||||
sb.append(" with close operation taking ");
|
||||
|
|
|
@ -148,7 +148,7 @@ public class DefaultPolicyHandler extends StrolchComponent implements PolicyHand
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> Class<T> visit(KeyPolicyDef policyDef) throws ClassNotFoundException {
|
||||
public <T> Class<T> visit(KeyPolicyDef policyDef) {
|
||||
Class<?> clazz = this.classByTypeMap.getElement(policyDef.getType(), policyDef.getValue());
|
||||
if (clazz == null)
|
||||
throw new StrolchPolicyException(MessageFormat.format("No policy is configured for {0}", policyDef));
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ReloadPoliciesJob extends StrolchJob {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void execute(PrivilegeContext ctx) throws Exception {
|
||||
protected void execute(PrivilegeContext ctx) {
|
||||
PolicyHandler policyHandler = getContainer().getComponent(PolicyHandler.class);
|
||||
policyHandler.reloadPolicies();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class ReloadPrivilegeHandlerJob extends StrolchJob {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void execute(PrivilegeContext ctx) throws Exception {
|
||||
protected void execute(PrivilegeContext ctx) {
|
||||
getContainer().getPrivilegeHandler().reloadConfiguration();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class StrolchPolicyFileParser extends DefaultHandler {
|
|||
public static final String KEY = "Key";
|
||||
public static final String CLASS = "Class";
|
||||
|
||||
private PolicyModel policyModel;
|
||||
private final PolicyModel policyModel;
|
||||
private PolicyType policyType;
|
||||
|
||||
public StrolchPolicyFileParser() {
|
||||
|
@ -46,45 +46,34 @@ public class StrolchPolicyFileParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
switch (qName) {
|
||||
case POLICY_TYPE:
|
||||
|
||||
case POLICY_TYPE -> {
|
||||
String type = attributes.getValue(TYPE);
|
||||
String api = attributes.getValue(API);
|
||||
|
||||
DBC.PRE.assertNotEmpty(TYPE + " not defined on a " + POLICY_TYPE, type);
|
||||
DBC.PRE.assertNotEmpty(API + " not defined on a " + POLICY_TYPE, api);
|
||||
|
||||
this.policyType = new PolicyType(type, api);
|
||||
this.policyModel.getPolicyTypes().put(type, policyType);
|
||||
|
||||
break;
|
||||
|
||||
case POLICY:
|
||||
|
||||
}
|
||||
case POLICY -> {
|
||||
String key = attributes.getValue(KEY);
|
||||
String clazz = attributes.getValue(CLASS);
|
||||
|
||||
DBC.PRE.assertNotEmpty(KEY + " not defined on a " + POLICY_TYPE, key);
|
||||
DBC.PRE.assertNotEmpty(CLASS + " not defined on a " + POLICY_TYPE, clazz);
|
||||
|
||||
this.policyType.getPolicyByKeyMap().put(key, clazz);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
switch (qName) {
|
||||
case POLICY_TYPE:
|
||||
this.policyType = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case POLICY_TYPE -> this.policyType = null;
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,7 +82,7 @@ public class StrolchPolicyFileParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
public class PolicyModel {
|
||||
private Map<String, PolicyType> policyTypes;
|
||||
private final Map<String, PolicyType> policyTypes;
|
||||
|
||||
public PolicyModel() {
|
||||
this.policyTypes = new HashMap<>();
|
||||
|
@ -105,9 +94,9 @@ public class StrolchPolicyFileParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
public class PolicyType {
|
||||
private String type;
|
||||
private String api;
|
||||
private Map<String, String> policyByKeyMap;
|
||||
private final String type;
|
||||
private final String api;
|
||||
private final Map<String, String> policyByKeyMap;
|
||||
|
||||
public PolicyType(String type, String api) {
|
||||
super();
|
||||
|
|
|
@ -196,7 +196,7 @@ public class ConfigurationSaxParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (this.valueBuffer != null)
|
||||
this.valueBuffer.append(ch, start, length);
|
||||
}
|
||||
|
@ -209,15 +209,14 @@ public class ConfigurationSaxParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (qName.equals(APPLICATION_NAME)) {
|
||||
this.valueBuffer = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if (qName.equals(APPLICATION_NAME)) {
|
||||
String applicationName = this.valueBuffer.toString();
|
||||
this.configurationBuilder.runtimeBuilder().setApplicationName(applicationName);
|
||||
|
@ -233,15 +232,14 @@ public class ConfigurationSaxParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
switch (qName) {
|
||||
case NAME, API, IMPL, DEPENDS -> this.valueBuffer = new StringBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
switch (qName) {
|
||||
case NAME -> {
|
||||
String name = this.valueBuffer.toString();
|
||||
|
@ -275,8 +273,7 @@ public class ConfigurationSaxParser extends DefaultHandler {
|
|||
private String propertyName;
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (this.propertyName != null) {
|
||||
String msg = "Opening another tag {0} although {1} is still open!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, this.propertyName, qName);
|
||||
|
@ -288,7 +285,7 @@ public class ConfigurationSaxParser extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if (this.propertyName == null || !this.propertyName.equals(qName)) {
|
||||
String msg = "Previous tag {0} was not closed before new tag {1}!"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, this.propertyName, qName);
|
||||
|
|
|
@ -32,7 +32,7 @@ public class RuntimeConfiguration extends AbstractionConfiguration {
|
|||
private final File dataPath;
|
||||
private final File tempPath;
|
||||
|
||||
private Locale locale;
|
||||
private final Locale locale;
|
||||
|
||||
public RuntimeConfiguration(String applicationName, String environment, Map<String, String> configurationValues,
|
||||
File configPathF, File dataPathF, File tempPathF) {
|
||||
|
|
|
@ -48,7 +48,7 @@ public class ModelPrivilege implements PrivilegePolicy {
|
|||
Object object = restrictable.getPrivilegeValue();
|
||||
|
||||
// DefaultPrivilege policy expects the privilege value to be a string
|
||||
if (!(object instanceof StrolchRootElement)) {
|
||||
if (!(object instanceof StrolchRootElement rootElement)) {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages
|
||||
.getString("Privilege.illegalArgument.nonstrolchrootelement"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, restrictable.getClass().getSimpleName());
|
||||
|
@ -59,7 +59,6 @@ public class ModelPrivilege implements PrivilegePolicy {
|
|||
if (privilege.isAllAllowed())
|
||||
return true;
|
||||
|
||||
StrolchRootElement rootElement = (StrolchRootElement) object;
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, rootElement.getType(), assertHasPrivilege);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ import li.strolch.privilege.model.PrivilegeContext;
|
|||
|
||||
public interface PrivilegedRunnableWithResult<T> {
|
||||
|
||||
public T run(PrivilegeContext ctx) throws Exception;
|
||||
T run(PrivilegeContext ctx);
|
||||
}
|
|
@ -17,7 +17,7 @@ public class StrolchSystemActionWithResult<T> extends SystemActionWithResult<T>
|
|||
|
||||
public static final Logger logger = LoggerFactory.getLogger(StrolchSystemAction.class);
|
||||
|
||||
private PrivilegedRunnableWithResult<T> runnable;
|
||||
private final PrivilegedRunnableWithResult<T> runnable;
|
||||
|
||||
public StrolchSystemActionWithResult(PrivilegedRunnableWithResult<T> runnable) {
|
||||
this.runnable = runnable;
|
||||
|
|
|
@ -6,7 +6,7 @@ import li.strolch.utils.dbc.DBC;
|
|||
|
||||
public class TransactedRestrictable extends SimpleRestrictable {
|
||||
|
||||
private StrolchTransaction tx;
|
||||
private final StrolchTransaction tx;
|
||||
|
||||
public TransactedRestrictable(StrolchTransaction tx, String name, Object value) {
|
||||
super(name, value);
|
||||
|
|
|
@ -31,7 +31,7 @@ public class StrolchEnum {
|
|||
|
||||
private String name;
|
||||
private String locale;
|
||||
private Map<String, String> values;
|
||||
private final Map<String, String> values;
|
||||
|
||||
private Locale localeL;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ExpressionsSupport {
|
|||
}
|
||||
|
||||
public static <T extends StrolchRootElement> ExpressionBuilder name() {
|
||||
return element -> element.getName();
|
||||
return StrolchElement::getName;
|
||||
}
|
||||
|
||||
public static <T extends StrolchRootElement> SearchExpression<T> date(SearchPredicate predicate) {
|
||||
|
@ -252,15 +252,12 @@ public class ExpressionsSupport {
|
|||
return null;
|
||||
|
||||
StrolchRootElement relation;
|
||||
switch (param.getInterpretation()) {
|
||||
case INTERPRETATION_RESOURCE_REF:
|
||||
return tx.getResourceBy((StringParameter) param);
|
||||
case INTERPRETATION_ORDER_REF:
|
||||
return tx.getOrderBy((StringParameter) param);
|
||||
case INTERPRETATION_ACTIVITY_REF:
|
||||
return tx.getActivityBy((StringParameter) param);
|
||||
}
|
||||
return switch (param.getInterpretation()) {
|
||||
case INTERPRETATION_RESOURCE_REF -> tx.getResourceBy((StringParameter) param);
|
||||
case INTERPRETATION_ORDER_REF -> tx.getOrderBy((StringParameter) param);
|
||||
case INTERPRETATION_ACTIVITY_REF -> tx.getActivityBy((StringParameter) param);
|
||||
default -> null;
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,13 +252,13 @@ public class SearchBuilder {
|
|||
return searchResult.orderById(descending);
|
||||
|
||||
switch (orderBy) {
|
||||
case Tags.Json.ID:
|
||||
case Tags.Json.ID -> {
|
||||
return searchResult.orderById(descending);
|
||||
case Tags.Json.NAME:
|
||||
}
|
||||
case Tags.Json.NAME -> {
|
||||
return searchResult.orderByName(descending);
|
||||
default:
|
||||
logger.warn("Unhandled ordering " + orderBy);
|
||||
break;
|
||||
}
|
||||
default -> logger.warn("Unhandled ordering " + orderBy);
|
||||
}
|
||||
|
||||
return searchResult;
|
||||
|
|
|
@ -6,7 +6,7 @@ import li.strolch.utils.ObjectHelper;
|
|||
* Implements the contains predicate, delegating to {@link ObjectHelper#isIn(Object, Object, boolean)}
|
||||
*/
|
||||
public class CollectionContainsPredicate extends AbstractSearchPredicate {
|
||||
private boolean ignoreCase;
|
||||
private final boolean ignoreCase;
|
||||
|
||||
public CollectionContainsPredicate(Object right, boolean ignoreCase) {
|
||||
super(right);
|
||||
|
|
|
@ -6,7 +6,7 @@ import li.strolch.utils.ObjectHelper;
|
|||
* Implements the contains predicate, delegating to {@link ObjectHelper#contains(Object, Object, boolean)}
|
||||
*/
|
||||
public class ContainsPredicate extends AbstractSearchPredicate {
|
||||
private boolean ignoreCase;
|
||||
private final boolean ignoreCase;
|
||||
|
||||
public ContainsPredicate(Object right, boolean ignoreCase) {
|
||||
super(right);
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.Date;
|
|||
|
||||
import li.strolch.search.SearchPredicate;
|
||||
import li.strolch.search.ValueCoercer;
|
||||
import li.strolch.utils.ObjectHelper;
|
||||
import li.strolch.utils.collections.DateRange;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,6 @@ package li.strolch.search.predicates;
|
|||
|
||||
import li.strolch.search.SearchPredicate;
|
||||
import li.strolch.search.ValueCoercer;
|
||||
import li.strolch.utils.ObjectHelper;
|
||||
|
||||
/**
|
||||
* Implements the not predicate by negating the return value of the internal {@link SearchPredicate}
|
||||
|
|
|
@ -78,12 +78,10 @@ public class DefaultServiceHandler extends StrolchComponent implements ServiceHa
|
|||
T argument) {
|
||||
DBC.PRE.assertNotNull("Certificate my not be null!", certificate);
|
||||
|
||||
if (!(svc instanceof AbstractService))
|
||||
if (!(svc instanceof AbstractService<T, U> service))
|
||||
throw new IllegalArgumentException(
|
||||
"This service handle expects all services to be instance of " + AbstractService.class.getName());
|
||||
|
||||
AbstractService<T, U> service = (AbstractService<T, U>) svc;
|
||||
|
||||
long start = System.nanoTime();
|
||||
|
||||
// first check that the caller may perform this service
|
||||
|
|
|
@ -19,8 +19,8 @@ import li.strolch.privilege.model.Certificate;
|
|||
|
||||
public interface ServiceHandler {
|
||||
|
||||
public <T extends ServiceArgument, U extends ServiceResult> U doService(Certificate certificate,
|
||||
<T extends ServiceArgument, U extends ServiceResult> U doService(Certificate certificate,
|
||||
Service<T, U> service, T argument);
|
||||
|
||||
public <U extends ServiceResult> U doService(Certificate certificate, Service<ServiceArgument, U> service);
|
||||
<U extends ServiceResult> U doService(Certificate certificate, Service<ServiceArgument, U> service);
|
||||
}
|
|
@ -201,6 +201,6 @@ public class RuntimeMock implements AutoCloseable {
|
|||
|
||||
public interface StrolchRunnable {
|
||||
|
||||
public void run(StrolchAgent agent) throws Exception;
|
||||
void run(StrolchAgent agent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,5 +19,5 @@ import li.strolch.model.Resource;
|
|||
|
||||
public interface ResourceGeneratorHandlerTest {
|
||||
|
||||
public Resource getTestResource(String id, String name, String type);
|
||||
Resource getTestResource(String id, String name, String type);
|
||||
}
|
||||
|
|
|
@ -17,5 +17,5 @@ package li.strolch.runtime.configuration.model;
|
|||
|
||||
public interface ServiceHandlerTest {
|
||||
|
||||
public ServiceResultTest doService();
|
||||
ServiceResultTest doService();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ package li.strolch.runtime.configuration.model;
|
|||
|
||||
public class ServiceResultTest {
|
||||
|
||||
private int result;
|
||||
private final int result;
|
||||
|
||||
public ServiceResultTest(int result) {
|
||||
this.result = result;
|
||||
|
|
|
@ -366,9 +366,9 @@ public class StrolchSearchTest {
|
|||
|
||||
public class BallSearch extends ResourceSearch {
|
||||
|
||||
private String id;
|
||||
private String status;
|
||||
private String color;
|
||||
private final String id;
|
||||
private final String status;
|
||||
private final String color;
|
||||
|
||||
public BallSearch(String id, String status, String color) {
|
||||
this.id = id;
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
*/
|
||||
package li.strolch.exception;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.privilege.model.Restrictable;
|
||||
import li.strolch.utils.I18nMessage;
|
||||
|
|
|
@ -56,15 +56,9 @@ public abstract class AbstractStrolchRootElement extends GroupedParameterizedEle
|
|||
|
||||
private void setInterpretationAndUom(StrolchRootElement element, Parameter<?> relationP) {
|
||||
switch (element.getObjectType()) {
|
||||
case Tags.RESOURCE:
|
||||
relationP.setInterpretation(INTERPRETATION_RESOURCE_REF);
|
||||
break;
|
||||
case Tags.ORDER:
|
||||
relationP.setInterpretation(INTERPRETATION_ORDER_REF);
|
||||
break;
|
||||
case Tags.ACTIVITY:
|
||||
relationP.setInterpretation(INTERPRETATION_ACTIVITY_REF);
|
||||
break;
|
||||
case Tags.RESOURCE -> relationP.setInterpretation(INTERPRETATION_RESOURCE_REF);
|
||||
case Tags.ORDER -> relationP.setInterpretation(INTERPRETATION_ORDER_REF);
|
||||
case Tags.ACTIVITY -> relationP.setInterpretation(INTERPRETATION_ACTIVITY_REF);
|
||||
}
|
||||
|
||||
relationP.setUom(element.getType());
|
||||
|
@ -92,15 +86,9 @@ public abstract class AbstractStrolchRootElement extends GroupedParameterizedEle
|
|||
relationsP = new StringListParameter(param, name, emptyList());
|
||||
|
||||
switch (objectTypes.get(0)) {
|
||||
case Tags.RESOURCE:
|
||||
relationsP.setInterpretation(INTERPRETATION_RESOURCE_REF);
|
||||
break;
|
||||
case Tags.ORDER:
|
||||
relationsP.setInterpretation(INTERPRETATION_ORDER_REF);
|
||||
break;
|
||||
case Tags.ACTIVITY:
|
||||
relationsP.setInterpretation(INTERPRETATION_ACTIVITY_REF);
|
||||
break;
|
||||
case Tags.RESOURCE -> relationsP.setInterpretation(INTERPRETATION_RESOURCE_REF);
|
||||
case Tags.ORDER -> relationsP.setInterpretation(INTERPRETATION_ORDER_REF);
|
||||
case Tags.ACTIVITY -> relationsP.setInterpretation(INTERPRETATION_ACTIVITY_REF);
|
||||
}
|
||||
|
||||
relationsP.setUom(types.get(0));
|
||||
|
|
|
@ -68,7 +68,7 @@ public class Locator {
|
|||
throw new StrolchException(
|
||||
"The path elements may not be null and must contain at least 1 item"); //$NON-NLS-1$
|
||||
}
|
||||
this.pathElements = Collections.unmodifiableList(new ArrayList<>(pathElements));
|
||||
this.pathElements = List.copyOf(pathElements);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,6 @@ package li.strolch.model.activity;
|
|||
import java.util.function.Predicate;
|
||||
|
||||
import li.strolch.exception.StrolchModelException;
|
||||
import li.strolch.exception.StrolchPolicyException;
|
||||
import li.strolch.model.*;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.policy.PolicyDef;
|
||||
|
|
|
@ -35,53 +35,32 @@ public class AuditFromDomReader {
|
|||
|
||||
String idS = rootElement.getAttribute(Tags.Audit.ID);
|
||||
DBC.INTERIM.assertNotEmpty("Id must be set!", idS);
|
||||
audit.setId(Long.valueOf(idS));
|
||||
audit.setId(Long.parseLong(idS));
|
||||
|
||||
NodeList childNodes = rootElement.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node item = childNodes.item(i);
|
||||
if (!(item instanceof Element))
|
||||
if (!(item instanceof Element element))
|
||||
continue;
|
||||
|
||||
Element element = (Element) item;
|
||||
String nodeName = element.getNodeName();
|
||||
String txtContent = element.getTextContent();
|
||||
|
||||
switch (nodeName) {
|
||||
case Tags.Audit.USERNAME:
|
||||
audit.setUsername(txtContent);
|
||||
break;
|
||||
case Tags.Audit.FIRSTNAME:
|
||||
audit.setFirstname(txtContent);
|
||||
break;
|
||||
case Tags.Audit.LASTNAME:
|
||||
audit.setLastname(txtContent);
|
||||
break;
|
||||
case Tags.Audit.DATE:
|
||||
audit.setDate(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent));
|
||||
break;
|
||||
case Tags.Audit.ELEMENT_TYPE:
|
||||
audit.setElementType(txtContent);
|
||||
break;
|
||||
case Tags.Audit.ELEMENT_SUB_TYPE:
|
||||
audit.setElementSubType(txtContent);
|
||||
break;
|
||||
case Tags.Audit.ELEMENT_ACCESSED:
|
||||
audit.setElementAccessed(txtContent);
|
||||
break;
|
||||
case Tags.Audit.NEW_VERSION:
|
||||
audit.setNewVersion(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent));
|
||||
break;
|
||||
case Tags.Audit.ACTION:
|
||||
audit.setAction(txtContent);
|
||||
break;
|
||||
case Tags.Audit.ACCESS_TYPE:
|
||||
audit.setAccessType(AccessType.valueOf(txtContent));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
MessageFormat.format("Unhandled/Invalid tag {0} for Audit {1}", nodeName, idS));
|
||||
case Tags.Audit.USERNAME -> audit.setUsername(txtContent);
|
||||
case Tags.Audit.FIRSTNAME -> audit.setFirstname(txtContent);
|
||||
case Tags.Audit.LASTNAME -> audit.setLastname(txtContent);
|
||||
case Tags.Audit.DATE ->
|
||||
audit.setDate(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent));
|
||||
case Tags.Audit.ELEMENT_TYPE -> audit.setElementType(txtContent);
|
||||
case Tags.Audit.ELEMENT_SUB_TYPE -> audit.setElementSubType(txtContent);
|
||||
case Tags.Audit.ELEMENT_ACCESSED -> audit.setElementAccessed(txtContent);
|
||||
case Tags.Audit.NEW_VERSION ->
|
||||
audit.setNewVersion(ISO8601FormatFactory.getInstance().getXmlDateFormat().parse(txtContent));
|
||||
case Tags.Audit.ACTION -> audit.setAction(txtContent);
|
||||
case Tags.Audit.ACCESS_TYPE -> audit.setAccessType(AccessType.valueOf(txtContent));
|
||||
default -> throw new IllegalArgumentException(
|
||||
MessageFormat.format("Unhandled/Invalid tag {0} for Audit {1}", nodeName, idS));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,102 +39,75 @@ public class AuditSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName) {
|
||||
|
||||
case Tags.AUDIT:
|
||||
case Tags.AUDIT -> {
|
||||
this.currentAudit = new Audit();
|
||||
this.currentAudit.setId(Long.valueOf(attributes.getValue(Tags.Audit.ID)));
|
||||
break;
|
||||
|
||||
case Tags.Audit.USERNAME:
|
||||
case Tags.Audit.FIRSTNAME:
|
||||
case Tags.Audit.LASTNAME:
|
||||
case Tags.Audit.DATE:
|
||||
case Tags.Audit.ELEMENT_TYPE:
|
||||
case Tags.Audit.ELEMENT_SUB_TYPE:
|
||||
case Tags.Audit.ELEMENT_ACCESSED:
|
||||
case Tags.Audit.NEW_VERSION:
|
||||
case Tags.Audit.ACTION:
|
||||
case Tags.Audit.ACCESS_TYPE:
|
||||
this.sb = new StringBuilder();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||
this.currentAudit.setId(Long.parseLong(attributes.getValue(Tags.Audit.ID)));
|
||||
}
|
||||
case Tags.Audit.USERNAME, Tags.Audit.FIRSTNAME, Tags.Audit.LASTNAME, Tags.Audit.DATE, Tags.Audit.ELEMENT_TYPE, Tags.Audit.ELEMENT_SUB_TYPE, Tags.Audit.ELEMENT_ACCESSED, Tags.Audit.NEW_VERSION, Tags.Audit.ACTION, Tags.Audit.ACCESS_TYPE ->
|
||||
this.sb = new StringBuilder();
|
||||
default -> throw new IllegalArgumentException(
|
||||
MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
switch (qName) {
|
||||
|
||||
case Tags.AUDIT:
|
||||
case Tags.AUDIT -> {
|
||||
this.auditConsumer.accept(this.currentAudit);
|
||||
this.currentAudit = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.USERNAME:
|
||||
}
|
||||
case Tags.Audit.USERNAME -> {
|
||||
this.currentAudit.setUsername(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.FIRSTNAME:
|
||||
}
|
||||
case Tags.Audit.FIRSTNAME -> {
|
||||
this.currentAudit.setFirstname(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.LASTNAME:
|
||||
}
|
||||
case Tags.Audit.LASTNAME -> {
|
||||
this.currentAudit.setLastname(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.DATE:
|
||||
}
|
||||
case Tags.Audit.DATE -> {
|
||||
this.currentAudit.setDate(ISO8601FormatFactory.getInstance().parseDate(this.sb.toString()));
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.ELEMENT_TYPE:
|
||||
}
|
||||
case Tags.Audit.ELEMENT_TYPE -> {
|
||||
this.currentAudit.setElementType(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.ELEMENT_SUB_TYPE:
|
||||
}
|
||||
case Tags.Audit.ELEMENT_SUB_TYPE -> {
|
||||
this.currentAudit.setElementSubType(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.ELEMENT_ACCESSED:
|
||||
}
|
||||
case Tags.Audit.ELEMENT_ACCESSED -> {
|
||||
this.currentAudit.setElementAccessed(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.NEW_VERSION:
|
||||
}
|
||||
case Tags.Audit.NEW_VERSION -> {
|
||||
this.currentAudit.setNewVersion(ISO8601FormatFactory.getInstance().parseDate(this.sb.toString()));
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.ACTION:
|
||||
}
|
||||
case Tags.Audit.ACTION -> {
|
||||
this.currentAudit.setAction(this.sb.toString());
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
case Tags.Audit.ACCESS_TYPE:
|
||||
}
|
||||
case Tags.Audit.ACCESS_TYPE -> {
|
||||
this.currentAudit.setAccessType(AccessType.valueOf(this.sb.toString()));
|
||||
this.sb = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||
}
|
||||
default -> throw new IllegalArgumentException(
|
||||
MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (this.sb != null)
|
||||
this.sb.append(ch, start, length);
|
||||
}
|
||||
|
|
|
@ -20,5 +20,5 @@ package li.strolch.model.audit;
|
|||
*/
|
||||
public interface AuditVisitor<U> {
|
||||
|
||||
public U visitAudit(Audit audit);
|
||||
U visitAudit(Audit audit);
|
||||
}
|
||||
|
|
|
@ -165,16 +165,12 @@ public abstract class ParameterBagContainerBuilder<T extends ParameterBagContain
|
|||
}
|
||||
|
||||
protected String getInterpretation(String objectType) {
|
||||
switch (objectType) {
|
||||
case Tags.RESOURCE:
|
||||
return INTERPRETATION_RESOURCE_REF;
|
||||
case Tags.ORDER:
|
||||
return INTERPRETATION_ORDER_REF;
|
||||
case Tags.ACTIVITY:
|
||||
return INTERPRETATION_ACTIVITY_REF;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected object type " + objectType);
|
||||
}
|
||||
return switch (objectType) {
|
||||
case Tags.RESOURCE -> INTERPRETATION_RESOURCE_REF;
|
||||
case Tags.ORDER -> INTERPRETATION_ORDER_REF;
|
||||
case Tags.ACTIVITY -> INTERPRETATION_ACTIVITY_REF;
|
||||
default -> throw new IllegalArgumentException("Unexpected object type " + objectType);
|
||||
};
|
||||
}
|
||||
|
||||
private ParameterBag getRelationsBag(ParameterBagContainer element) {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class PolicyContainerBuilder<T extends ParameterBagContainerBuilder<T>> e
|
|||
if (this.policies == null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T t = (T) this;
|
||||
this.policies = new PoliciesBuilder<T>(t);
|
||||
this.policies = new PoliciesBuilder<>(t);
|
||||
}
|
||||
return policies;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public interface PolicyDefVisitor {
|
|||
* @throws ClassNotFoundException
|
||||
* if the class referenced by this {@link PolicyDef} does not exist
|
||||
*/
|
||||
public <T> Class<T> visit(JavaPolicyDef javaPolicyDef) throws ClassNotFoundException;
|
||||
<T> Class<T> visit(JavaPolicyDef javaPolicyDef) throws ClassNotFoundException;
|
||||
|
||||
/**
|
||||
* This method resolves a Policy by further indirection. I.e. the {@link PolicyDef#getValue()} is a key to the
|
||||
|
@ -46,8 +46,6 @@ public interface PolicyDefVisitor {
|
|||
*
|
||||
* @return an instance of the policy resolved by the key {@link PolicyDef#getValue()}
|
||||
*
|
||||
* @throws ClassNotFoundException
|
||||
* if the class referenced by this {@link PolicyDef} does not exist
|
||||
*/
|
||||
public <T> Class<T> visit(KeyPolicyDef keyPolicyDef) throws ClassNotFoundException;
|
||||
<T> Class<T> visit(KeyPolicyDef keyPolicyDef);
|
||||
}
|
|
@ -68,10 +68,10 @@ public interface IValueChange<T extends IValue> {
|
|||
*
|
||||
* @return true if this element is read only
|
||||
*/
|
||||
public boolean isReadOnly();
|
||||
boolean isReadOnly();
|
||||
|
||||
/**
|
||||
* Sets this element to readOnly, so that it may not be modified. To modify it, call {@link #getClone()}
|
||||
*/
|
||||
public void setReadOnly();
|
||||
void setReadOnly();
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@ import li.strolch.model.activity.Activity;
|
|||
public interface OrderVisitor<U> extends StrolchRootElementVisitor<U> {
|
||||
|
||||
@Override
|
||||
public default U visitActivity(Activity activity) {
|
||||
default U visitActivity(Activity activity) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + activity.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public default U visitResource(Resource resource) {
|
||||
default U visitResource(Resource resource) {
|
||||
throw new UnsupportedOperationException(getClass().getName() + " can not handle " + resource.getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import li.strolch.model.parameter.*;
|
|||
*/
|
||||
public class SetParameterValueFromStringVisitor implements ParameterVisitor<Void> {
|
||||
|
||||
private String value;
|
||||
private final String value;
|
||||
|
||||
public SetParameterValueFromStringVisitor(String value) {
|
||||
this.value = value;
|
||||
|
|
|
@ -26,7 +26,7 @@ import li.strolch.utils.time.PeriodDuration;
|
|||
*/
|
||||
public class SetParameterValueVisitor implements ParameterVisitor<Void> {
|
||||
|
||||
private Object value;
|
||||
private final Object value;
|
||||
|
||||
public SetParameterValueVisitor(Object value) {
|
||||
this.value = value;
|
||||
|
|
|
@ -25,8 +25,8 @@ import li.strolch.model.timevalue.impl.*;
|
|||
*/
|
||||
public class SetStateValueVisitor implements TimedStateVisitor<Void> {
|
||||
|
||||
private long time;
|
||||
private Object value;
|
||||
private final long time;
|
||||
private final Object value;
|
||||
|
||||
public SetStateValueVisitor(long time, Object value) {
|
||||
this.time = time;
|
||||
|
|
|
@ -41,8 +41,8 @@ import li.strolch.utils.dbc.DBC;
|
|||
*/
|
||||
public class StrolchElementDeepEqualsVisitor implements StrolchElementVisitor<List<Locator>> {
|
||||
|
||||
private List<Locator> mismatchedLocators;
|
||||
private StrolchElement srcElement;
|
||||
private final List<Locator> mismatchedLocators;
|
||||
private final StrolchElement srcElement;
|
||||
|
||||
public StrolchElementDeepEqualsVisitor(StrolchElement srcElement) {
|
||||
this.srcElement = srcElement;
|
||||
|
|
|
@ -66,10 +66,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList childNodes = resourceElement.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node item = childNodes.item(i);
|
||||
if (!(item instanceof Element))
|
||||
if (!(item instanceof Element timedStateElem))
|
||||
continue;
|
||||
|
||||
Element timedStateElem = (Element) item;
|
||||
if (!timedStateElem.getNodeName().equals(Tags.TIMED_STATE))
|
||||
continue;
|
||||
|
||||
|
@ -112,10 +111,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList timeValueElems = timedStateElem.getChildNodes();
|
||||
for (int j = 0; j < timeValueElems.getLength(); j++) {
|
||||
Node timeValueItem = timeValueElems.item(j);
|
||||
if (!(timeValueItem instanceof Element))
|
||||
if (!(timeValueItem instanceof Element timeValueElem))
|
||||
continue;
|
||||
|
||||
Element timeValueElem = (Element) timeValueItem;
|
||||
if (!timeValueElem.getNodeName().equals(Tags.VALUE))
|
||||
continue;
|
||||
|
||||
|
@ -143,11 +141,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList childNodes = activityElement.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node item = childNodes.item(i);
|
||||
if (!(item instanceof Element))
|
||||
if (!(item instanceof Element childElem))
|
||||
continue;
|
||||
|
||||
Element childElem = (Element) item;
|
||||
|
||||
switch (childElem.getNodeName()) {
|
||||
case Tags.ACTIVITY:
|
||||
Activity childActivity = new Activity();
|
||||
|
@ -192,10 +188,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList bags = element.getChildNodes();
|
||||
for (int i = 0; i < bags.getLength(); i++) {
|
||||
Node item = bags.item(i);
|
||||
if (!(item instanceof Element))
|
||||
if (!(item instanceof Element bagElement))
|
||||
continue;
|
||||
|
||||
Element bagElement = (Element) item;
|
||||
if (!bagElement.getNodeName().equals(Tags.PARAMETER_BAG))
|
||||
continue;
|
||||
|
||||
|
@ -225,10 +220,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList parameterElements = element.getChildNodes();
|
||||
for (int i = 0; i < parameterElements.getLength(); i++) {
|
||||
Node item = parameterElements.item(i);
|
||||
if (!(item instanceof Element))
|
||||
if (!(item instanceof Element paramElement))
|
||||
continue;
|
||||
|
||||
Element paramElement = (Element) item;
|
||||
if (!paramElement.getNodeName().equals(Tags.PARAMETER))
|
||||
continue;
|
||||
|
||||
|
@ -299,10 +293,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList valueChangeNodes = element.getChildNodes();
|
||||
for (int i = 0; i < valueChangeNodes.getLength(); i++) {
|
||||
Node item = valueChangeNodes.item(i);
|
||||
if (!(item instanceof Element))
|
||||
if (!(item instanceof Element valueChangeElem))
|
||||
continue;
|
||||
|
||||
Element valueChangeElem = (Element) item;
|
||||
if (!valueChangeElem.getNodeName().equals(Tags.VALUE_CHANGE))
|
||||
continue;
|
||||
|
||||
|
@ -328,20 +321,18 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node resourceChildItem = childNodes.item(i);
|
||||
if (!(resourceChildItem instanceof Element))
|
||||
if (!(resourceChildItem instanceof Element policiesElem))
|
||||
continue;
|
||||
|
||||
Element policiesElem = (Element) resourceChildItem;
|
||||
if (!policiesElem.getNodeName().equals(Tags.POLICIES))
|
||||
continue;
|
||||
|
||||
NodeList policyChildNodes = policiesElem.getChildNodes();
|
||||
for (int j = 0; j < policyChildNodes.getLength(); j++) {
|
||||
Node policiesChildItem = policyChildNodes.item(j);
|
||||
if (!(policiesChildItem instanceof Element))
|
||||
if (!(policiesChildItem instanceof Element policyElem))
|
||||
continue;
|
||||
|
||||
Element policyElem = (Element) policiesChildItem;
|
||||
if (!policyElem.getNodeName().equals(Tags.POLICY))
|
||||
continue;
|
||||
|
||||
|
@ -360,10 +351,9 @@ public class StrolchElementFromDomVisitor {
|
|||
NodeList childNodes = element.getChildNodes();
|
||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
||||
Node resourceChildItem = childNodes.item(i);
|
||||
if (!(resourceChildItem instanceof Element))
|
||||
if (!(resourceChildItem instanceof Element versionElem))
|
||||
continue;
|
||||
|
||||
Element versionElem = (Element) resourceChildItem;
|
||||
if (!versionElem.getNodeName().equals(Tags.VERSION))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -10,9 +10,9 @@ import li.strolch.utils.collections.MapOfMaps;
|
|||
|
||||
public class StrolchElementToMapListener implements StrolchElementListener {
|
||||
|
||||
private MapOfMaps<String, String, Resource> resourceMap = new MapOfMaps<>();
|
||||
private MapOfMaps<String, String, Order> orderMap = new MapOfMaps<>();
|
||||
private MapOfMaps<String, String, Activity> activityMap = new MapOfMaps<>();
|
||||
private final MapOfMaps<String, String, Resource> resourceMap = new MapOfMaps<>();
|
||||
private final MapOfMaps<String, String, Order> orderMap = new MapOfMaps<>();
|
||||
private final MapOfMaps<String, String, Activity> activityMap = new MapOfMaps<>();
|
||||
|
||||
public MapOfMaps<String, String, Resource> getResourceMap() {
|
||||
return this.resourceMap;
|
||||
|
|
|
@ -22,11 +22,9 @@ import javax.xml.parsers.SAXParserFactory;
|
|||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Tags;
|
||||
import li.strolch.utils.helper.StringHelper;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
|
|
@ -328,14 +328,14 @@ public class XmlModelSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (this.textBuffer != null) {
|
||||
this.textBuffer.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
switch (qName) {
|
||||
case RESOURCE:
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.io.InputStreamReader;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Tags;
|
||||
|
@ -40,7 +39,7 @@ import org.xml.sax.SAXException;
|
|||
*/
|
||||
public class XmlModelSaxStreamReader extends XmlModelSaxReader {
|
||||
|
||||
private InputSource source;
|
||||
private final InputSource source;
|
||||
|
||||
public XmlModelSaxStreamReader(StrolchElementListener listener, InputStream stream) {
|
||||
this(listener, stream, DEFAULT_ENCODING);
|
||||
|
@ -72,13 +71,12 @@ public class XmlModelSaxStreamReader extends XmlModelSaxReader {
|
|||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
|
||||
switch (qName) {
|
||||
|
||||
case Tags.INCLUDE_FILE:
|
||||
case Tags.INCLUDE_FILE -> {
|
||||
String msg = "The {0} can''t handle Tags of type {1}";
|
||||
msg = MessageFormat.format(msg, XmlModelSaxStreamReader.class.getName(), Tags.INCLUDE_FILE);
|
||||
throw new IllegalArgumentException(msg); //$NON-NLS-1$
|
||||
default:
|
||||
super.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
default -> super.startElement(uri, localName, qName, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public class ModelToSaxWriterTest extends ModelMarshallingTest {
|
|||
activity.accept(new StrolchElementToSaxWriterVisitor(writer));
|
||||
writer.writeEndDocument();
|
||||
|
||||
System.out.println(out.toString());
|
||||
System.out.println(out);
|
||||
|
||||
SimpleStrolchElementListener listener = new SimpleStrolchElementListener();
|
||||
XmlModelSaxStreamReader saxStreamReader = new XmlModelSaxStreamReader(listener,
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ActionTest {
|
|||
* no test. Just to see the XML serialization in the console
|
||||
*/
|
||||
// @Test
|
||||
public void testToDOM() throws ParserConfigurationException, TransformerException {
|
||||
public void showToDOM() throws ParserConfigurationException, TransformerException {
|
||||
|
||||
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Document document = db.newDocument();
|
||||
|
|
|
@ -340,7 +340,7 @@ public class ActivityTest {
|
|||
* no test. Just to see the XML serialization in the console
|
||||
*/
|
||||
// @Test
|
||||
public void testToDOM() throws ParserConfigurationException, TransformerException {
|
||||
public void showToDOM() throws ParserConfigurationException, TransformerException {
|
||||
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
|
|
|
@ -49,7 +49,7 @@ public class FloatTimeVariableTest {
|
|||
public void init() {
|
||||
this.timeVariable = new TimeVariable<>();
|
||||
for (long i = 0; i < MAX; i += STEP) {
|
||||
this.timeVariable.setValueAt(Long.valueOf(i), new FloatValue(i));
|
||||
this.timeVariable.setValueAt(i, new FloatValue(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class IntegerTimeVariableTest {
|
|||
private static final Long PICK = 50L;
|
||||
|
||||
private TimeVariable<IntegerValue> timeVariable;
|
||||
private Map<Long, IntegerValue> expectedValues = new HashMap<>();
|
||||
private final Map<Long, IntegerValue> expectedValues = new HashMap<>();
|
||||
|
||||
/**
|
||||
* set the values ascending with a difference of STEP
|
||||
|
@ -52,7 +52,7 @@ public class IntegerTimeVariableTest {
|
|||
this.timeVariable = new TimeVariable<>();
|
||||
for (int i = 0; i < MAX; i += STEP) {
|
||||
IntegerValue expectedValue = new IntegerValue(i);
|
||||
Long time = Long.valueOf(i);
|
||||
Long time = (long) i;
|
||||
this.expectedValues.put(time, expectedValue);
|
||||
this.timeVariable.setValueAt(time, expectedValue);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class StringTimeVariableTest {
|
|||
|
||||
private TimeVariable<IValue<Set<AString>>> timeVariable;
|
||||
|
||||
private Map<Long, StringSetValue> testSets = new HashMap<>();
|
||||
private final Map<Long, StringSetValue> testSets = new HashMap<>();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
|
|
|
@ -22,5 +22,5 @@ import li.strolch.persistence.api.TransactionResult;
|
|||
*/
|
||||
public interface DaoCommand {
|
||||
|
||||
public void doComand(TransactionResult txResult);
|
||||
void doComand(TransactionResult txResult);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class PostgreSqlAuditDao implements AuditDao {
|
|||
private static final String removeSql = "delete from audits where id = ?";
|
||||
private static final String removeAllSql = "delete from audits where element_type = ? and date between ? and ?";
|
||||
|
||||
private PostgreSqlStrolchTransaction tx;
|
||||
private final PostgreSqlStrolchTransaction tx;
|
||||
|
||||
public PostgreSqlAuditDao(PostgreSqlStrolchTransaction postgreSqlStrolchTransaction) {
|
||||
this.tx = postgreSqlStrolchTransaction;
|
||||
|
|
|
@ -129,7 +129,7 @@ public final class PostgreSqlDbConnectionBuilder extends DbConnectionBuilder {
|
|||
* @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
public Connection getConnection(String username, String password) {
|
||||
throw new UnsupportedOperationException("Deprecated, use parameterless version!");
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class PostgreSqlStrolchTransaction extends AbstractTransaction {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PostgreSqlStrolchTransaction.class);
|
||||
private PostgreSqlPersistenceHandler persistenceHandler;
|
||||
private final PostgreSqlPersistenceHandler persistenceHandler;
|
||||
|
||||
private PostgreSqlOrderDao orderDao;
|
||||
private PostgreSqlResourceDao resourceDao;
|
||||
|
@ -43,7 +43,7 @@ public class PostgreSqlStrolchTransaction extends AbstractTransaction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeChanges() throws Exception {
|
||||
protected void writeChanges() {
|
||||
|
||||
// first perform DAOs
|
||||
if (this.orderDao != null)
|
||||
|
|
|
@ -37,7 +37,7 @@ import li.strolch.xmlpers.objref.TypeRef;
|
|||
*/
|
||||
public class XmlAuditDao implements AuditDao {
|
||||
|
||||
private PersistenceTransaction tx;
|
||||
private final PersistenceTransaction tx;
|
||||
|
||||
public XmlAuditDao(StrolchTransaction tx) {
|
||||
XmlStrolchTransaction strolchTx = (XmlStrolchTransaction) tx;
|
||||
|
@ -67,9 +67,6 @@ public class XmlAuditDao implements AuditDao {
|
|||
long size = 0;
|
||||
Set<String> types = queryTypes();
|
||||
for (String type : types) {
|
||||
// SubTypeRef subTypeRef = getTypeRef(type);
|
||||
// size += this.tx.getMetadataDao().querySize(subTypeRef);
|
||||
|
||||
size += querySize(type, dateRange);
|
||||
}
|
||||
return size;
|
||||
|
|
|
@ -12,7 +12,7 @@ import li.strolch.xmlpers.objref.SubTypeRef;
|
|||
|
||||
public class XmlLogMessageDao implements LogMessageDao {
|
||||
|
||||
private PersistenceTransaction tx;
|
||||
private final PersistenceTransaction tx;
|
||||
|
||||
public XmlLogMessageDao(StrolchTransaction tx) {
|
||||
XmlStrolchTransaction strolchTx = (XmlStrolchTransaction) tx;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
package li.strolch.persistence.xml;
|
||||
|
||||
import static li.strolch.agent.impl.DefaultRealmHandler.PREFIX_DATA_STORE_FILE;
|
||||
import static li.strolch.db.DbConstants.PROP_DB_IGNORE_REALM;
|
||||
import static li.strolch.db.DbConstants.PROP_USE_ENV;
|
||||
import static li.strolch.runtime.StrolchConstants.makeRealmKey;
|
||||
import static li.strolch.utils.helper.StringHelper.isEmpty;
|
||||
|
|
|
@ -28,8 +28,8 @@ import li.strolch.xmlpers.api.TransactionResult;
|
|||
|
||||
public class XmlStrolchTransaction extends AbstractTransaction {
|
||||
|
||||
private XmlPersistenceHandler persistenceHandler;
|
||||
private PersistenceTransaction tx;
|
||||
private final XmlPersistenceHandler persistenceHandler;
|
||||
private final PersistenceTransaction tx;
|
||||
|
||||
public XmlStrolchTransaction(ComponentContainer container, StrolchRealm realm, Certificate certificate,
|
||||
String action, boolean readOnly, PersistenceTransaction tx, XmlPersistenceHandler persistenceHandler) {
|
||||
|
@ -43,17 +43,17 @@ public class XmlStrolchTransaction extends AbstractTransaction {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeChanges() throws Exception {
|
||||
protected void writeChanges() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollback() throws Exception {
|
||||
protected void rollback() {
|
||||
this.tx.autoCloseableRollback();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void commit() throws Exception {
|
||||
protected void commit() {
|
||||
if (!this.tx.hasTransactionResult()) {
|
||||
TransactionResult result = new TransactionResult();
|
||||
this.tx.setTransactionResult(result);
|
||||
|
|
|
@ -68,7 +68,7 @@ public class ActivitySaxParser implements SaxParser<Activity> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter xmlWriter) throws XMLStreamException {
|
||||
public void write(XMLStreamWriter xmlWriter) {
|
||||
this.activity.accept(new StrolchElementToSaxWriterVisitor(xmlWriter));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class AuditSaxParser implements SaxParser<Audit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter xmlWriter) throws XMLStreamException {
|
||||
public void write(XMLStreamWriter xmlWriter) {
|
||||
this.audit.accept(new AuditToSaxWriterVisitor(xmlWriter));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class LogMessageSaxParser implements SaxParser<LogMessage> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter xmlWriter) throws XMLStreamException {
|
||||
public void write(XMLStreamWriter xmlWriter) {
|
||||
new LogMessageToSaxWriterVisitor(xmlWriter).visit(this.logMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,46 +57,29 @@ public class LogMessageSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName) {
|
||||
|
||||
case Tags.LOG_MESSAGE:
|
||||
case Tags.LOG_MESSAGE -> {
|
||||
this.id = attributes.getValue(Tags.ID);
|
||||
this.dateTime = ISO8601.parseToZdt(attributes.getValue(Tags.DATE));
|
||||
this.realm = attributes.getValue(Tags.REALM);
|
||||
break;
|
||||
|
||||
case Tags.USERNAME:
|
||||
case Tags.LOCATOR:
|
||||
case Tags.SEVERITY:
|
||||
case Tags.BUNDLE:
|
||||
case Tags.KEY:
|
||||
case Tags.MESSAGE:
|
||||
case Tags.EXCEPTION:
|
||||
case Tags.STATE:
|
||||
|
||||
this.sb = new StringBuilder();
|
||||
break;
|
||||
|
||||
case Tags.PROPERTIES:
|
||||
this.properties = new Properties();
|
||||
break;
|
||||
|
||||
case Tags.PROPERTY:
|
||||
}
|
||||
case Tags.USERNAME, Tags.LOCATOR, Tags.SEVERITY, Tags.BUNDLE, Tags.KEY, Tags.MESSAGE, Tags.EXCEPTION, Tags.STATE ->
|
||||
this.sb = new StringBuilder();
|
||||
case Tags.PROPERTIES -> this.properties = new Properties();
|
||||
case Tags.PROPERTY -> {
|
||||
String key = attributes.getValue(Tags.KEY);
|
||||
String value = attributes.getValue(Tags.VALUE);
|
||||
this.properties.setProperty(key, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||
}
|
||||
default -> throw new IllegalArgumentException(
|
||||
MessageFormat.format("The element ''{0}'' is unhandled!", qName)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
switch (qName) {
|
||||
|
||||
|
@ -160,7 +143,7 @@ public class LogMessageSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (this.sb != null)
|
||||
this.sb.append(ch, start, length);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class OrderSaxParser implements SaxParser<Order> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter xmlWriter) throws XMLStreamException {
|
||||
public void write(XMLStreamWriter xmlWriter) {
|
||||
this.order.accept(new StrolchElementToSaxWriterVisitor(xmlWriter));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class ResourceSaxParser implements SaxParser<Resource> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(XMLStreamWriter xmlWriter) throws XMLStreamException {
|
||||
public void write(XMLStreamWriter xmlWriter) {
|
||||
this.resource.accept(new StrolchElementToSaxWriterVisitor(xmlWriter));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,7 +164,7 @@ public abstract class BaseLdapPrivilegeHandler extends DefaultPrivilegeHandler {
|
|||
|
||||
protected abstract String getLastName(String username, Attributes attrs) throws NamingException;
|
||||
|
||||
protected abstract Locale getLocale(Attributes attrs) throws NamingException;
|
||||
protected abstract Locale getLocale(Attributes attrs);
|
||||
|
||||
protected abstract Set<String> getLdapGroups(String username, Attributes attrs) throws NamingException;
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public class JsonConfigLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Locale getLocale(Attributes attrs) throws NamingException {
|
||||
protected Locale getLocale(Attributes attrs) {
|
||||
return this.defaultLocale;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class SimpleLdapPrivilegeHandler extends BaseLdapPrivilegeHandler {
|
|||
|
||||
@Override
|
||||
protected Map<String, String> buildProperties(String username, Attributes attrs, Set<String> ldapGroups,
|
||||
Set<String> strolchRoles) throws NamingException {
|
||||
Set<String> strolchRoles) {
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put(ORGANISATION, this.organisation);
|
||||
|
|
|
@ -153,22 +153,10 @@ public class Crypt {
|
|||
|
||||
sb.append("$");
|
||||
switch (this.algorithm) {
|
||||
case "MD5":
|
||||
sb.append("1");
|
||||
break;
|
||||
|
||||
case "PBKDF2WithHmacSHA256":
|
||||
case "SHA-256":
|
||||
sb.append("5");
|
||||
break;
|
||||
|
||||
case "PBKDF2WithHmacSHA512":
|
||||
case "SHA-512":
|
||||
sb.append("6");
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("Unhandled algorithm " + this.algorithm);
|
||||
case "MD5" -> sb.append("1");
|
||||
case "PBKDF2WithHmacSHA256", "SHA-256" -> sb.append("5");
|
||||
case "PBKDF2WithHmacSHA512", "SHA-512" -> sb.append("6");
|
||||
default -> throw new IllegalStateException("Unhandled algorithm " + this.algorithm);
|
||||
}
|
||||
|
||||
if (this.iterations != 0 && this.iterations != DEFAULT_SMALL_ITERATIONS) {
|
||||
|
@ -206,21 +194,19 @@ public class Crypt {
|
|||
|
||||
private void setAlgorithm(String id, boolean hasSalt) {
|
||||
switch (id) {
|
||||
case "1":
|
||||
case "1" -> {
|
||||
this.algorithm = "MD5";
|
||||
this.keyLength = 0;
|
||||
break;
|
||||
case "5":
|
||||
}
|
||||
case "5" -> {
|
||||
this.algorithm = hasSalt ? "PBKDF2WithHmacSHA256" : "SHA-256";
|
||||
this.keyLength = 256;
|
||||
break;
|
||||
case "6":
|
||||
}
|
||||
case "6" -> {
|
||||
this.algorithm = hasSalt ? "PBKDF2WithHmacSHA512" : "SHA-512";
|
||||
this.keyLength = 256;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalStateException("Unhandled ID " + id);
|
||||
}
|
||||
default -> throw new IllegalStateException("Unhandled ID " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -308,9 +308,8 @@ public final class Certificate implements Serializable {
|
|||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof Certificate))
|
||||
if (!(obj instanceof Certificate other))
|
||||
return false;
|
||||
Certificate other = (Certificate) obj;
|
||||
if (this.authToken == null) {
|
||||
if (other.authToken != null)
|
||||
return false;
|
||||
|
|
|
@ -44,17 +44,17 @@ public class PrivilegeContext {
|
|||
// object state
|
||||
//
|
||||
|
||||
private UserRep userRep;
|
||||
private Certificate certificate;
|
||||
private Map<String, IPrivilege> privileges;
|
||||
private Map<String, PrivilegePolicy> policies;
|
||||
private final UserRep userRep;
|
||||
private final Certificate certificate;
|
||||
private final Map<String, IPrivilege> privileges;
|
||||
private final Map<String, PrivilegePolicy> policies;
|
||||
|
||||
public PrivilegeContext(UserRep userRep, Certificate certificate, Map<String, IPrivilege> privileges,
|
||||
Map<String, PrivilegePolicy> policies) {
|
||||
this.userRep = userRep;
|
||||
this.certificate = certificate;
|
||||
this.privileges = Collections.unmodifiableMap(new HashMap<>(privileges));
|
||||
this.policies = Collections.unmodifiableMap(new HashMap<>(policies));
|
||||
this.privileges = Map.copyOf(privileges);
|
||||
this.policies = Map.copyOf(policies);
|
||||
}
|
||||
|
||||
public UserRep getUserRep() {
|
||||
|
|
|
@ -34,12 +34,12 @@ public interface Restrictable {
|
|||
*
|
||||
* @return the name of the {@link IPrivilege} which is to be used to validate privileges against
|
||||
*/
|
||||
public String getPrivilegeName();
|
||||
String getPrivilegeName();
|
||||
|
||||
/**
|
||||
* Returns the value which defines or describes what privilege is to be granted
|
||||
*
|
||||
* @return the value which defines or describes what privilege is to be granted
|
||||
*/
|
||||
public Object getPrivilegeValue();
|
||||
Object getPrivilegeValue();
|
||||
}
|
||||
|
|
|
@ -82,9 +82,7 @@ public class UserRep implements Serializable {
|
|||
|
||||
if (propertyMap != null) {
|
||||
this.properties = new HashMap<>();
|
||||
propertyMap.forEach((key, value) -> {
|
||||
this.properties.put(key.trim(), value.trim());
|
||||
});
|
||||
propertyMap.forEach((key, value) -> this.properties.put(key.trim(), value.trim()));
|
||||
}
|
||||
|
||||
this.history = history;
|
||||
|
|
|
@ -66,7 +66,7 @@ public class RoleAccessPrivilege implements PrivilegePolicy {
|
|||
return true;
|
||||
|
||||
// RoleAccessPrivilege policy expects the privilege value to be a role
|
||||
if (!(object instanceof Tuple)) {
|
||||
if (!(object instanceof Tuple tuple)) {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages
|
||||
.getString("Privilege.illegalArgument.nontuple"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, restrictable.getClass().getSimpleName());
|
||||
|
@ -77,25 +77,19 @@ public class RoleAccessPrivilege implements PrivilegePolicy {
|
|||
if (privilege.isAllAllowed())
|
||||
return true;
|
||||
|
||||
Tuple tuple = (Tuple) object;
|
||||
|
||||
// get role name as privilege value
|
||||
Role oldRole = tuple.getFirst();
|
||||
Role newRole = tuple.getSecond();
|
||||
|
||||
switch (privilegeName) {
|
||||
|
||||
case PrivilegeHandler.PRIVILEGE_GET_ROLE:
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_ROLE:
|
||||
case PrivilegeHandler.PRIVILEGE_REMOVE_ROLE: {
|
||||
case PrivilegeHandler.PRIVILEGE_GET_ROLE, PrivilegeHandler.PRIVILEGE_ADD_ROLE, PrivilegeHandler.PRIVILEGE_REMOVE_ROLE -> {
|
||||
DBC.INTERIM.assertNull("For " + privilegeName + " first must be null!", oldRole);
|
||||
DBC.INTERIM.assertNotNull("For " + privilegeName + " second must not be null!", newRole);
|
||||
|
||||
String privilegeValue = newRole.getName();
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, privilegeValue, assertHasPrivilege);
|
||||
}
|
||||
|
||||
case PrivilegeHandler.PRIVILEGE_MODIFY_ROLE: {
|
||||
case PrivilegeHandler.PRIVILEGE_MODIFY_ROLE -> {
|
||||
DBC.INTERIM.assertNotNull("For " + privilegeName + " first must not be null!", oldRole);
|
||||
DBC.INTERIM.assertNotNull("For " + privilegeName + " second must not be null!", newRole);
|
||||
|
||||
|
@ -104,13 +98,12 @@ public class RoleAccessPrivilege implements PrivilegePolicy {
|
|||
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, privilegeValue, assertHasPrivilege);
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages
|
||||
.getString("Privilege.roleAccessPrivilege.unknownPrivilege"); //$NON-NLS-1$
|
||||
default -> {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages.getString(
|
||||
"Privilege.roleAccessPrivilege.unknownPrivilege"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, privilegeName);
|
||||
throw new PrivilegeException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class UserAccessPrivilege implements PrivilegePolicy {
|
|||
return true;
|
||||
|
||||
// RoleAccessPrivilege policy expects the privilege value to be a role
|
||||
if (!(object instanceof Tuple)) {
|
||||
if (!(object instanceof Tuple tuple)) {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages
|
||||
.getString("Privilege.illegalArgument.nontuple"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, restrictable.getClass().getSimpleName());
|
||||
|
@ -76,13 +76,8 @@ public class UserAccessPrivilege implements PrivilegePolicy {
|
|||
if (privilege.isAllAllowed())
|
||||
return true;
|
||||
|
||||
Tuple tuple = (Tuple) object;
|
||||
|
||||
switch (privilegeName) {
|
||||
case PrivilegeHandler.PRIVILEGE_GET_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_REMOVE_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_MODIFY_USER: {
|
||||
case PrivilegeHandler.PRIVILEGE_GET_USER, PrivilegeHandler.PRIVILEGE_ADD_USER, PrivilegeHandler.PRIVILEGE_REMOVE_USER, PrivilegeHandler.PRIVILEGE_MODIFY_USER -> {
|
||||
User oldUser = tuple.getFirst();
|
||||
User newUser = tuple.getSecond();
|
||||
|
||||
|
@ -90,12 +85,11 @@ public class UserAccessPrivilege implements PrivilegePolicy {
|
|||
DBC.INTERIM.assertNotNull("For " + privilegeName + " second must not be null!", newUser);
|
||||
|
||||
String privilegeValue = newUser.getUsername();
|
||||
DBC.INTERIM
|
||||
.assertEquals("oldUser and newUser names must be the same", oldUser.getUsername(), privilegeValue);
|
||||
DBC.INTERIM.assertEquals("oldUser and newUser names must be the same", oldUser.getUsername(),
|
||||
privilegeValue);
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, privilegeValue, assertHasPrivilege);
|
||||
}
|
||||
|
||||
case PrivilegeHandler.PRIVILEGE_SET_USER_STATE: {
|
||||
case PrivilegeHandler.PRIVILEGE_SET_USER_STATE -> {
|
||||
User oldUser = tuple.getFirst();
|
||||
User newUser = tuple.getSecond();
|
||||
|
||||
|
@ -105,9 +99,7 @@ public class UserAccessPrivilege implements PrivilegePolicy {
|
|||
String privilegeValue = newUser.getUserState().name();
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, privilegeValue, assertHasPrivilege);
|
||||
}
|
||||
|
||||
case PrivilegeHandler.PRIVILEGE_SET_USER_LOCALE:
|
||||
case PrivilegeHandler.PRIVILEGE_SET_USER_PASSWORD: {
|
||||
case PrivilegeHandler.PRIVILEGE_SET_USER_LOCALE, PrivilegeHandler.PRIVILEGE_SET_USER_PASSWORD -> {
|
||||
User oldUser = tuple.getFirst();
|
||||
User newUser = tuple.getSecond();
|
||||
|
||||
|
@ -122,9 +114,7 @@ public class UserAccessPrivilege implements PrivilegePolicy {
|
|||
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, privilegeValue, assertHasPrivilege);
|
||||
}
|
||||
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_ROLE_TO_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_REMOVE_ROLE_FROM_USER: {
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_ROLE_TO_USER, PrivilegeHandler.PRIVILEGE_REMOVE_ROLE_FROM_USER -> {
|
||||
User user = tuple.getFirst();
|
||||
String roleName = tuple.getSecond();
|
||||
|
||||
|
@ -133,11 +123,11 @@ public class UserAccessPrivilege implements PrivilegePolicy {
|
|||
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, roleName, assertHasPrivilege);
|
||||
}
|
||||
|
||||
default:
|
||||
default -> {
|
||||
String msg = PrivilegeMessages.getString("Privilege.userAccessPrivilege.unknownPrivilege"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, privilegeName, this.getClass().getName());
|
||||
throw new PrivilegeException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,21 +68,15 @@ public class UserAccessWithSameOrganisationPrivilege extends UserAccessPrivilege
|
|||
Object object = restrictable.getPrivilegeValue();
|
||||
|
||||
// RoleAccessPrivilege policy expects the privilege value to be a role
|
||||
if (!(object instanceof Tuple)) {
|
||||
if (!(object instanceof Tuple tuple)) {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages.getString(
|
||||
"Privilege.illegalArgument.nontuple"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, restrictable.getClass().getSimpleName());
|
||||
throw new PrivilegeException(msg);
|
||||
}
|
||||
|
||||
Tuple tuple = (Tuple) object;
|
||||
|
||||
switch (privilegeName) {
|
||||
case PrivilegeHandler.PRIVILEGE_GET_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_MODIFY_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_SET_USER_PASSWORD:
|
||||
case PrivilegeHandler.PRIVILEGE_REMOVE_USER: {
|
||||
case PrivilegeHandler.PRIVILEGE_GET_USER, PrivilegeHandler.PRIVILEGE_ADD_USER, PrivilegeHandler.PRIVILEGE_MODIFY_USER, PrivilegeHandler.PRIVILEGE_SET_USER_PASSWORD, PrivilegeHandler.PRIVILEGE_REMOVE_USER -> {
|
||||
|
||||
if (isStrolchAdminAndIgnoreOrganisation(ctx))
|
||||
break;
|
||||
|
@ -101,10 +95,8 @@ public class UserAccessWithSameOrganisationPrivilege extends UserAccessPrivilege
|
|||
if (!assertUserInSameOrganisation(ctx, newUser, assertHasPrivilege))
|
||||
return false;
|
||||
|
||||
break;
|
||||
}
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_ROLE_TO_USER:
|
||||
case PrivilegeHandler.PRIVILEGE_REMOVE_ROLE_FROM_USER: {
|
||||
case PrivilegeHandler.PRIVILEGE_ADD_ROLE_TO_USER, PrivilegeHandler.PRIVILEGE_REMOVE_ROLE_FROM_USER -> {
|
||||
|
||||
if (isStrolchAdminAndIgnoreOrganisation(ctx))
|
||||
break;
|
||||
|
@ -114,15 +106,14 @@ public class UserAccessWithSameOrganisationPrivilege extends UserAccessPrivilege
|
|||
if (!assertUserInSameOrganisation(ctx, user, assertHasPrivilege))
|
||||
return false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
default -> {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages.getString(
|
||||
"Privilege.userAccessPrivilege.unknownPrivilege"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, privilegeName);
|
||||
throw new PrivilegeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// now delegate the rest of the validation to the super class
|
||||
return super.validateAction(ctx, privilege, restrictable, assertHasPrivilege);
|
||||
|
|
|
@ -64,7 +64,7 @@ public class UsernameFromCertificatePrivilege implements PrivilegePolicy {
|
|||
Object object = restrictable.getPrivilegeValue();
|
||||
|
||||
// RoleAccessPrivilege policy expects the privilege value to be a role
|
||||
if (!(object instanceof Certificate)) {
|
||||
if (!(object instanceof Certificate cert)) {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages
|
||||
.getString("Privilege.illegalArgument.noncertificate"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, restrictable.getClass().getSimpleName());
|
||||
|
@ -75,7 +75,6 @@ public class UsernameFromCertificatePrivilege implements PrivilegePolicy {
|
|||
if (privilege.isAllAllowed())
|
||||
return true;
|
||||
|
||||
Certificate cert = (Certificate) object;
|
||||
String privilegeValue = cert.getUsername();
|
||||
return checkByAllowDenyValues(ctx, privilege, restrictable, privilegeValue, assertHasPrivilege);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class UsernameFromCertificateWithSameOrganisationPrivilege extends Userna
|
|||
Object object = restrictable.getPrivilegeValue();
|
||||
|
||||
// RoleAccessPrivilege policy expects the privilege value to be a role
|
||||
if (!(object instanceof Certificate)) {
|
||||
if (!(object instanceof Certificate cert)) {
|
||||
String msg = Restrictable.class.getName() + PrivilegeMessages.getString(
|
||||
"Privilege.illegalArgument.noncertificate"); //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, restrictable.getClass().getSimpleName());
|
||||
|
@ -77,7 +77,6 @@ public class UsernameFromCertificateWithSameOrganisationPrivilege extends Userna
|
|||
}
|
||||
|
||||
// get object
|
||||
Certificate cert = (Certificate) object;
|
||||
|
||||
// first validate same organisation
|
||||
if (!isStrolchAdminAndIgnoreOrganisation(cert) && !assertUserInSameOrganisation(ctx, cert, assertHasPrivilege))
|
||||
|
|
|
@ -53,7 +53,7 @@ public class CertificateStubsSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName) {
|
||||
case XML_ROOT_CERTIFICATES:
|
||||
|
|
|
@ -21,11 +21,11 @@ import org.xml.sax.SAXException;
|
|||
// TODO write JavaDoc...
|
||||
public interface ElementParser {
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException;
|
||||
void startElement(String uri, String localName, String qName, Attributes attributes);
|
||||
|
||||
public void characters(char[] ch, int start, int length) throws SAXException;
|
||||
void characters(char[] ch, int start, int length);
|
||||
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException;
|
||||
void endElement(String uri, String localName, String qName);
|
||||
|
||||
public void notifyChild(ElementParser child);
|
||||
void notifyChild(ElementParser child);
|
||||
}
|
|
@ -21,17 +21,17 @@ import org.xml.sax.SAXException;
|
|||
public abstract class ElementParserAdapter implements ElementParser {
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
// empty implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
// empty implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
// empty implementation
|
||||
}
|
||||
|
||||
|
|
|
@ -46,15 +46,9 @@ public class PrivilegeConfigSaxReader extends DefaultHandler {
|
|||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
|
||||
switch (qName) {
|
||||
case XmlConstants.XML_CONTAINER:
|
||||
this.buildersStack.push(new ContainerParser());
|
||||
break;
|
||||
case XmlConstants.XML_PARAMETERS:
|
||||
this.buildersStack.push(new ParametersParser());
|
||||
break;
|
||||
case XmlConstants.XML_POLICIES:
|
||||
this.buildersStack.push(new PoliciesParser());
|
||||
break;
|
||||
case XmlConstants.XML_CONTAINER -> this.buildersStack.push(new ContainerParser());
|
||||
case XmlConstants.XML_PARAMETERS -> this.buildersStack.push(new ParametersParser());
|
||||
case XmlConstants.XML_POLICIES -> this.buildersStack.push(new PoliciesParser());
|
||||
}
|
||||
|
||||
if (!this.buildersStack.isEmpty())
|
||||
|
@ -73,14 +67,11 @@ public class PrivilegeConfigSaxReader extends DefaultHandler {
|
|||
if (!this.buildersStack.isEmpty())
|
||||
this.buildersStack.peek().endElement(uri, localName, qName);
|
||||
|
||||
ElementParser elementParser = null;
|
||||
switch (qName) {
|
||||
case XmlConstants.XML_CONTAINER:
|
||||
case XmlConstants.XML_PARAMETERS:
|
||||
case XmlConstants.XML_POLICIES:
|
||||
elementParser = this.buildersStack.pop();
|
||||
break;
|
||||
}
|
||||
ElementParser elementParser = switch (qName) {
|
||||
case XmlConstants.XML_CONTAINER, XmlConstants.XML_PARAMETERS, XmlConstants.XML_POLICIES ->
|
||||
this.buildersStack.pop();
|
||||
default -> null;
|
||||
};
|
||||
|
||||
if (!this.buildersStack.isEmpty() && elementParser != null)
|
||||
this.buildersStack.peek().notifyChild(elementParser);
|
||||
|
@ -91,81 +82,62 @@ public class PrivilegeConfigSaxReader extends DefaultHandler {
|
|||
private String currentElement;
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName) {
|
||||
case XmlConstants.XML_CONTAINER:
|
||||
this.currentElement = qName;
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_ENCRYPTION: {
|
||||
case XmlConstants.XML_CONTAINER -> this.currentElement = qName;
|
||||
case XmlConstants.XML_HANDLER_ENCRYPTION -> {
|
||||
this.currentElement = qName;
|
||||
String className = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
getContainerModel().setEncryptionHandlerClassName(className);
|
||||
break;
|
||||
}
|
||||
case XmlConstants.XML_HANDLER_PASSWORD_STRENGTH: {
|
||||
case XmlConstants.XML_HANDLER_PASSWORD_STRENGTH -> {
|
||||
this.currentElement = qName;
|
||||
String className = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
getContainerModel().setPasswordStrengthHandlerClassName(className);
|
||||
break;
|
||||
}
|
||||
case XmlConstants.XML_HANDLER_PERSISTENCE: {
|
||||
case XmlConstants.XML_HANDLER_PERSISTENCE -> {
|
||||
this.currentElement = qName;
|
||||
String className = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
getContainerModel().setPersistenceHandlerClassName(className);
|
||||
break;
|
||||
}
|
||||
case XmlConstants.XML_HANDLER_USER_CHALLENGE: {
|
||||
case XmlConstants.XML_HANDLER_USER_CHALLENGE -> {
|
||||
this.currentElement = qName;
|
||||
String className = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
getContainerModel().setUserChallengeHandlerClassName(className);
|
||||
break;
|
||||
}
|
||||
case XmlConstants.XML_HANDLER_SSO: {
|
||||
case XmlConstants.XML_HANDLER_SSO -> {
|
||||
this.currentElement = qName;
|
||||
String className = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
getContainerModel().setSsoHandlerClassName(className);
|
||||
break;
|
||||
}
|
||||
case XmlConstants.XML_HANDLER_PRIVILEGE: {
|
||||
case XmlConstants.XML_HANDLER_PRIVILEGE -> {
|
||||
this.currentElement = qName;
|
||||
String className = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
getContainerModel().setPrivilegeHandlerClassName(className);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyChild(ElementParser child) {
|
||||
if (!(child instanceof ParametersParser))
|
||||
if (!(child instanceof ParametersParser parametersChild))
|
||||
return;
|
||||
|
||||
ParametersParser parametersChild = (ParametersParser) child;
|
||||
|
||||
switch (this.currentElement) {
|
||||
case XmlConstants.XML_CONTAINER:
|
||||
getContainerModel().setParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_ENCRYPTION:
|
||||
getContainerModel().setEncryptionHandlerParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_PASSWORD_STRENGTH:
|
||||
getContainerModel().setPasswordStrengthHandlerParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_PERSISTENCE:
|
||||
getContainerModel().setPersistenceHandlerParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_USER_CHALLENGE:
|
||||
getContainerModel().setUserChallengeHandlerParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_SSO:
|
||||
getContainerModel().setSsoHandlerParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_HANDLER_PRIVILEGE:
|
||||
getContainerModel().setPrivilegeHandlerParameterMap(parametersChild.getParameterMap());
|
||||
break;
|
||||
case XmlConstants.XML_CONTAINER -> getContainerModel().setParameterMap(parametersChild.getParameterMap());
|
||||
case XmlConstants.XML_HANDLER_ENCRYPTION ->
|
||||
getContainerModel().setEncryptionHandlerParameterMap(parametersChild.getParameterMap());
|
||||
case XmlConstants.XML_HANDLER_PASSWORD_STRENGTH ->
|
||||
getContainerModel().setPasswordStrengthHandlerParameterMap(parametersChild.getParameterMap());
|
||||
case XmlConstants.XML_HANDLER_PERSISTENCE ->
|
||||
getContainerModel().setPersistenceHandlerParameterMap(parametersChild.getParameterMap());
|
||||
case XmlConstants.XML_HANDLER_USER_CHALLENGE ->
|
||||
getContainerModel().setUserChallengeHandlerParameterMap(parametersChild.getParameterMap());
|
||||
case XmlConstants.XML_HANDLER_SSO ->
|
||||
getContainerModel().setSsoHandlerParameterMap(parametersChild.getParameterMap());
|
||||
case XmlConstants.XML_HANDLER_PRIVILEGE ->
|
||||
getContainerModel().setPrivilegeHandlerParameterMap(parametersChild.getParameterMap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +149,7 @@ public class PrivilegeConfigSaxReader extends DefaultHandler {
|
|||
private final Map<String, String> parameterMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (qName.equals(XmlConstants.XML_PARAMETER)) {
|
||||
String key = attributes.getValue(XmlConstants.XML_ATTR_NAME).trim();
|
||||
String value = attributes.getValue(XmlConstants.XML_ATTR_VALUE).trim();
|
||||
|
@ -199,8 +170,7 @@ public class PrivilegeConfigSaxReader extends DefaultHandler {
|
|||
// <Policy name="DefaultPrivilege" class="li.strolch.privilege.policy.DefaultPrivilege" />
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (qName.equals(XmlConstants.XML_POLICY)) {
|
||||
String policyName = attributes.getValue(XmlConstants.XML_ATTR_NAME).trim();
|
||||
String policyClassName = attributes.getValue(XmlConstants.XML_ATTR_CLASS).trim();
|
||||
|
|
|
@ -129,59 +129,59 @@ public class PrivilegeRolesSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
this.text = new StringBuilder();
|
||||
|
||||
if (qName.equals(XmlConstants.XML_ROLE)) {
|
||||
switch (qName) {
|
||||
case XmlConstants.XML_ROLE:
|
||||
this.roleName = attributes.getValue(XmlConstants.XML_ATTR_NAME).trim();
|
||||
} else if (qName.equals(XmlConstants.XML_PRIVILEGE)) {
|
||||
break;
|
||||
case XmlConstants.XML_PRIVILEGE:
|
||||
this.privilegeName = attributes.getValue(XmlConstants.XML_ATTR_NAME).trim();
|
||||
this.privilegePolicy = attributes.getValue(XmlConstants.XML_ATTR_POLICY).trim();
|
||||
} else if (qName.equals(XmlConstants.XML_ALLOW) || qName.equals(XmlConstants.XML_DENY) || qName
|
||||
.equals(XmlConstants.XML_ALL_ALLOWED)) {
|
||||
break;
|
||||
case XmlConstants.XML_ALLOW:
|
||||
case XmlConstants.XML_DENY:
|
||||
case XmlConstants.XML_ALL_ALLOWED:
|
||||
// no-op
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unhandled tag " + qName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
if (this.text != null)
|
||||
this.text.append(ch, start, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
|
||||
if (qName.equals(XmlConstants.XML_ALL_ALLOWED)) {
|
||||
this.allAllowed = StringHelper.parseBoolean(this.text.toString().trim());
|
||||
} else if (qName.equals(XmlConstants.XML_ALLOW)) {
|
||||
this.allowList.add(this.text.toString().trim());
|
||||
} else if (qName.equals(XmlConstants.XML_DENY)) {
|
||||
this.denyList.add(this.text.toString().trim());
|
||||
} else if (qName.equals(XmlConstants.XML_PRIVILEGE)) {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
switch (qName) {
|
||||
case XmlConstants.XML_ALL_ALLOWED ->
|
||||
this.allAllowed = StringHelper.parseBoolean(this.text.toString().trim());
|
||||
case XmlConstants.XML_ALLOW -> this.allowList.add(this.text.toString().trim());
|
||||
case XmlConstants.XML_DENY -> this.denyList.add(this.text.toString().trim());
|
||||
case XmlConstants.XML_PRIVILEGE -> {
|
||||
IPrivilege privilege = new PrivilegeImpl(this.privilegeName, this.privilegePolicy, this.allAllowed,
|
||||
this.denyList, this.allowList);
|
||||
this.privileges.put(this.privilegeName, privilege);
|
||||
|
||||
this.privilegeName = null;
|
||||
this.privilegePolicy = null;
|
||||
this.allAllowed = false;
|
||||
this.denyList = new HashSet<>();
|
||||
this.allowList = new HashSet<>();
|
||||
|
||||
} else if (qName.equals(XmlConstants.XML_ROLE)) {
|
||||
|
||||
}
|
||||
case XmlConstants.XML_ROLE -> {
|
||||
Role role = new Role(this.roleName, this.privileges);
|
||||
|
||||
getRoles().add(role);
|
||||
logger.info(MessageFormat.format("New Role: {0}", role)); //$NON-NLS-1$
|
||||
init();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,8 +192,7 @@ public class PrivilegeRolesSaxReader extends DefaultHandler {
|
|||
public Map<String, String> parameterMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (qName.equals(XmlConstants.XML_PROPERTY)) {
|
||||
String key = attributes.getValue(XmlConstants.XML_ATTR_NAME).trim();
|
||||
String value = attributes.getValue(XmlConstants.XML_ATTR_VALUE).trim();
|
||||
|
|
|
@ -133,8 +133,7 @@ public class PrivilegeUsersSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
this.text = new StringBuilder();
|
||||
|
||||
|
@ -189,82 +188,42 @@ public class PrivilegeUsersSaxReader extends DefaultHandler {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
this.text.append(ch, start, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
|
||||
switch (qName) {
|
||||
case XML_FIRSTNAME:
|
||||
|
||||
this.firstName = this.text.toString().trim();
|
||||
break;
|
||||
|
||||
case XML_LASTNAME:
|
||||
|
||||
this.lastname = this.text.toString().trim();
|
||||
break;
|
||||
|
||||
case XML_STATE:
|
||||
|
||||
this.userState = UserState.valueOf(this.text.toString().trim());
|
||||
break;
|
||||
|
||||
case XML_LOCALE:
|
||||
|
||||
this.locale = Locale.forLanguageTag(this.text.toString().trim());
|
||||
break;
|
||||
|
||||
case XML_PASSWORD_CHANGE_REQUESTED:
|
||||
|
||||
this.passwordChangeRequested = Boolean.parseBoolean(this.text.toString().trim());
|
||||
break;
|
||||
|
||||
case XML_FIRST_LOGIN:
|
||||
|
||||
this.history.setFirstLogin(ISO8601.parseToZdt(this.text.toString().trim()));
|
||||
break;
|
||||
|
||||
case XML_LAST_LOGIN:
|
||||
|
||||
this.history.setLastLogin(ISO8601.parseToZdt(this.text.toString().trim()));
|
||||
break;
|
||||
|
||||
case XML_LAST_PASSWORD_CHANGE:
|
||||
|
||||
this.history.setLastPasswordChange(ISO8601.parseToZdt(this.text.toString().trim()));
|
||||
break;
|
||||
|
||||
case XML_ROLE:
|
||||
|
||||
this.userRoles.add(this.text.toString().trim());
|
||||
break;
|
||||
|
||||
case XML_USER:
|
||||
|
||||
case XML_FIRSTNAME -> this.firstName = this.text.toString().trim();
|
||||
case XML_LASTNAME -> this.lastname = this.text.toString().trim();
|
||||
case XML_STATE -> this.userState = UserState.valueOf(this.text.toString().trim());
|
||||
case XML_LOCALE -> this.locale = Locale.forLanguageTag(this.text.toString().trim());
|
||||
case XML_PASSWORD_CHANGE_REQUESTED ->
|
||||
this.passwordChangeRequested = Boolean.parseBoolean(this.text.toString().trim());
|
||||
case XML_FIRST_LOGIN -> this.history.setFirstLogin(ISO8601.parseToZdt(this.text.toString().trim()));
|
||||
case XML_LAST_LOGIN -> this.history.setLastLogin(ISO8601.parseToZdt(this.text.toString().trim()));
|
||||
case XML_LAST_PASSWORD_CHANGE ->
|
||||
this.history.setLastPasswordChange(ISO8601.parseToZdt(this.text.toString().trim()));
|
||||
case XML_ROLE -> this.userRoles.add(this.text.toString().trim());
|
||||
case XML_USER -> {
|
||||
if (this.history == null)
|
||||
this.history = new UserHistory();
|
||||
|
||||
User user = new User(this.userId, this.username, this.password, this.salt, this.hashAlgorithm,
|
||||
hashIterations, hashKeyLength, this.firstName, this.lastname, this.userState, this.userRoles,
|
||||
this.locale, this.parameters, this.passwordChangeRequested, this.history);
|
||||
logger.info(MessageFormat.format("New User: {0}", user)); //$NON-NLS-1$
|
||||
|
||||
getUsers().add(user);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
default -> {
|
||||
if (!(qName.equals(XML_ROLES) //
|
||||
|| qName.equals(XML_PARAMETER) //
|
||||
|| qName.equals(XML_HISTORY) //
|
||||
|| qName.equals(XML_PARAMETERS))) {
|
||||
throw new IllegalArgumentException("Unhandled tag " + qName);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,23 +242,20 @@ public class PrivilegeUsersSaxReader extends DefaultHandler {
|
|||
public Map<String, String> parameterMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
|
||||
switch (qName) {
|
||||
case XML_PROPERTY:
|
||||
|
||||
case XML_PROPERTY -> {
|
||||
String key = attributes.getValue(XML_ATTR_NAME).trim();
|
||||
String value = attributes.getValue(XML_ATTR_VALUE).trim();
|
||||
this.parameterMap.put(key, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
}
|
||||
default -> {
|
||||
if (!qName.equals(XML_PROPERTIES)) {
|
||||
throw new IllegalArgumentException("Unhandled tag " + qName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getParameterMap() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package li.strolch.privilege.test;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
|
@ -59,9 +60,9 @@ public class AbstractPrivilegeTest {
|
|||
File dstRoles = new File(targetPath, rolesFilename);
|
||||
|
||||
// write config
|
||||
String config = new String(Files.readAllBytes(privilegeConfigFile.toPath()), "UTF-8");
|
||||
String config = new String(Files.readAllBytes(privilegeConfigFile.toPath()), StandardCharsets.UTF_8);
|
||||
config = config.replace("${target}", dst);
|
||||
Files.write(dstConfig.toPath(), config.getBytes("UTF-8"));
|
||||
Files.write(dstConfig.toPath(), config.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// copy model
|
||||
Files.copy(privilegeUsersFile.toPath(), dstUsers.toPath());
|
||||
|
|
|
@ -13,19 +13,19 @@ import org.junit.Test;
|
|||
public class PersistSessionsTest extends AbstractPrivilegeTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
public static void init() {
|
||||
removeConfigs(PersistSessionsTest.class.getSimpleName());
|
||||
prepareConfigs(PersistSessionsTest.class.getSimpleName(), "PrivilegeConfig.xml", "PrivilegeUsers.xml",
|
||||
"PrivilegeRoles.xml");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() throws Exception {
|
||||
public static void destroy() {
|
||||
removeConfigs(PersistSessionsTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
initialize(PersistSessionsTest.class.getSimpleName(), "PrivilegeConfig.xml");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,19 +29,19 @@ import org.junit.Test;
|
|||
public class PrivilegeConflictMergeTest extends AbstractPrivilegeTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
public static void init() {
|
||||
removeConfigs(PrivilegeConflictMergeTest.class.getSimpleName());
|
||||
prepareConfigs(PrivilegeConflictMergeTest.class.getSimpleName(), "PrivilegeConfigMerge.xml",
|
||||
"PrivilegeUsersMerge.xml", "PrivilegeRolesMerge.xml");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void destroy() throws Exception {
|
||||
public static void destroy() {
|
||||
removeConfigs(PrivilegeConflictMergeTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
public void setup() {
|
||||
initialize(PrivilegeConflictMergeTest.class.getSimpleName(), "PrivilegeConfigMerge.xml");
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue