Skip to content

Instantly share code, notes, and snippets.

View erikdehair's full-sized avatar

Erik de Hair erikdehair

  • Pocos
  • Eindhoven, The Netherlands
View GitHub Profile
TypesafeQuery<VirtualCircuit> tq = newTypesafeQuery(VirtualCircuit.class);
QVirtualCircuit cand = QVirtualCircuit.candidate("virtualCircuit");
// find al uncompleted NetworkInformationFunction's for the virtual circuit
TypesafeSubquery<NetworkInformationFunction> subquery = tq.subquery(NetworkInformationFunction.class, "uncompletedNIF");
QNetworkInformationFunction uncompletedNIF = QNetworkInformationFunction.candidate("uncompletedNIF");
subquery.filter(uncompletedNIF.completed.eq(false));
tq.filter(cand.automaticShapingEnabled.eq(true)
.and(cand.eq(((QNetworkInformationFunction)subquery.candidate()).virtualCircuit))
@erikdehair
erikdehair / RunAsService.java
Last active July 4, 2017 13:33
An example of how to create 'Run As' methods for Apache Isis using Apache Shiro. This example has some references to non existing classes like DashboardService but the concept should be clear though. When 'running as' another user, the permissions (as determined by Shiro) of the other user apply.
@DomainService(nature = NatureOfService.VIEW_MENU_ONLY)
@DomainServiceLayout(menuBar = DomainServiceLayout.MenuBar.TERTIARY)
public class RunAsService {
@ActionLayout(contributed= Contributed.AS_NEITHER)
public Dashboard runAs(User user) {
SimplePrincipalCollection principals = new SimplePrincipalCollection(user.getUsername(), "jdbcRealm"); // jdbcRealm is realm as configured in Shiro config (shiro.ini)
org.apache.shiro.SecurityUtils.getSubject().runAs(principals);
log.info("User '"+ SecurityUtil.getRealUsername() +"' now running as '"+ SecurityUtil.getUsername() +"'");