[New] Added privilege checking for StrolchQueries
This commit is contained in:
parent
352a702c15
commit
523d44c41e
4
pom.xml
4
pom.xml
|
@ -32,6 +32,10 @@
|
||||||
<groupId>ch.eitchnet</groupId>
|
<groupId>ch.eitchnet</groupId>
|
||||||
<artifactId>ch.eitchnet.utils</artifactId>
|
<artifactId>ch.eitchnet.utils</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.eitchnet</groupId>
|
||||||
|
<artifactId>ch.eitchnet.privilege</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -18,13 +18,14 @@ package li.strolch.model.audit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import li.strolch.model.query.StrolchQuery;
|
||||||
import ch.eitchnet.utils.collections.DateRange;
|
import ch.eitchnet.utils.collections.DateRange;
|
||||||
import ch.eitchnet.utils.dbc.DBC;
|
import ch.eitchnet.utils.dbc.DBC;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class AuditQuery {
|
public class AuditQuery implements StrolchQuery {
|
||||||
|
|
||||||
private String elementTypeSelection;
|
private String elementTypeSelection;
|
||||||
private List<AuditSelection> selections;
|
private List<AuditSelection> selections;
|
||||||
|
@ -71,4 +72,20 @@ public class AuditQuery {
|
||||||
selection.accept(visitor);
|
selection.accept(visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPrivilegeName() {
|
||||||
|
return StrolchQuery.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getPrivilegeValue() {
|
||||||
|
return getClass().getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import li.strolch.model.parameter.Parameter;
|
||||||
*
|
*
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class OrderQuery extends StrolchQuery<OrderQueryVisitor> {
|
public class OrderQuery extends StrolchElementQuery<OrderQueryVisitor> {
|
||||||
|
|
||||||
public OrderQuery(Navigation navigation) {
|
public OrderQuery(Navigation navigation) {
|
||||||
super(navigation);
|
super(navigation);
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package li.strolch.model.query;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface Query<T extends QueryVisitor> {
|
|
||||||
|
|
||||||
public void visit(T queryVisitor);
|
|
||||||
}
|
|
|
@ -28,7 +28,7 @@ import li.strolch.model.parameter.Parameter;
|
||||||
*
|
*
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public class ResourceQuery extends StrolchQuery<ResourceQueryVisitor> {
|
public class ResourceQuery extends StrolchElementQuery<ResourceQueryVisitor> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param navigation
|
* @param navigation
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package li.strolch.model.query;
|
||||||
|
|
||||||
|
import ch.eitchnet.utils.dbc.DBC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*/
|
||||||
|
public abstract class StrolchElementQuery<T extends QueryVisitor> implements StrolchQuery {
|
||||||
|
|
||||||
|
private Navigation navigation;
|
||||||
|
private Selection selection;
|
||||||
|
|
||||||
|
public StrolchElementQuery(Navigation navigation) {
|
||||||
|
this.navigation = navigation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNavigation() {
|
||||||
|
return this.navigation != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSelection() {
|
||||||
|
return this.selection != null && this.selection.hasSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Selection getSelection() {
|
||||||
|
return this.selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchElementQuery<T> with(Selection selection) {
|
||||||
|
assertNoSelectionYetSet();
|
||||||
|
this.selection = selection;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNoSelectionYetSet() {
|
||||||
|
String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$
|
||||||
|
DBC.PRE.assertNull(msg, this.selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchElementQuery<T> withAny() {
|
||||||
|
assertNoSelectionYetSet();
|
||||||
|
this.selection = new AnySelection();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AndSelection and() {
|
||||||
|
assertNoSelectionYetSet();
|
||||||
|
AndSelection and = new AndSelection();
|
||||||
|
this.selection = and;
|
||||||
|
return and;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrSelection or() {
|
||||||
|
assertNoSelectionYetSet();
|
||||||
|
OrSelection or = new OrSelection();
|
||||||
|
this.selection = or;
|
||||||
|
return or;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchElementQuery<T> not(Selection selection) {
|
||||||
|
assertNoSelectionYetSet();
|
||||||
|
this.selection = new NotSelection(selection);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void accept(T visitor) {
|
||||||
|
DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$
|
||||||
|
DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$
|
||||||
|
this.navigation.accept(visitor);
|
||||||
|
this.selection.accept(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeName()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getPrivilegeName() {
|
||||||
|
return StrolchQuery.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ch.eitchnet.privilege.model.Restrictable#getPrivilegeValue()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getPrivilegeValue() {
|
||||||
|
return getClass().getName();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,73 +15,12 @@
|
||||||
*/
|
*/
|
||||||
package li.strolch.model.query;
|
package li.strolch.model.query;
|
||||||
|
|
||||||
import ch.eitchnet.utils.dbc.DBC;
|
import ch.eitchnet.privilege.model.Restrictable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*/
|
*/
|
||||||
public abstract class StrolchQuery<T extends QueryVisitor> {
|
public interface StrolchQuery extends Restrictable {
|
||||||
|
|
||||||
private Navigation navigation;
|
// marker interface
|
||||||
private Selection selection;
|
|
||||||
|
|
||||||
public StrolchQuery(Navigation navigation) {
|
|
||||||
this.navigation = navigation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNavigation() {
|
|
||||||
return this.navigation != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasSelection() {
|
|
||||||
return this.selection != null && this.selection.hasSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Selection getSelection() {
|
|
||||||
return this.selection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StrolchQuery<T> with(Selection selection) {
|
|
||||||
assertNoSelectionYetSet();
|
|
||||||
this.selection = selection;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertNoSelectionYetSet() {
|
|
||||||
String msg = "A selection is already set! Use a cascaded boolean operators to perform multiple selections"; //$NON-NLS-1$
|
|
||||||
DBC.PRE.assertNull(msg, this.selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public StrolchQuery<T> withAny() {
|
|
||||||
assertNoSelectionYetSet();
|
|
||||||
this.selection = new AnySelection();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AndSelection and() {
|
|
||||||
assertNoSelectionYetSet();
|
|
||||||
AndSelection and = new AndSelection();
|
|
||||||
this.selection = and;
|
|
||||||
return and;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrSelection or() {
|
|
||||||
assertNoSelectionYetSet();
|
|
||||||
OrSelection or = new OrSelection();
|
|
||||||
this.selection = or;
|
|
||||||
return or;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StrolchQuery<T> not(Selection selection) {
|
|
||||||
assertNoSelectionYetSet();
|
|
||||||
this.selection = new NotSelection(selection);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void accept(T visitor) {
|
|
||||||
DBC.PRE.assertNotNull("No navigation set!", this.navigation); //$NON-NLS-1$
|
|
||||||
DBC.PRE.assertNotNull("No selection defined!", this.selection); //$NON-NLS-1$
|
|
||||||
this.navigation.accept(visitor);
|
|
||||||
this.selection.accept(visitor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue