public Restriction getRestriction() { return restriction == null ? Restrictions.none() : restriction; }
/** * Assigns home, root and read only attributes from KpwdPrincipal. */ @SuppressWarnings("null") @Override public void session(Set<Principal> authorizedPrincipals, Set<Object> attrib) throws AuthenticationException { KpwdPrincipal kpwd = getFirst(filter(authorizedPrincipals, KpwdPrincipal.class), null); checkAuthentication(kpwd != null, "no record found"); attrib.add(new HomeDirectory(kpwd.home)); attrib.add(new RootDirectory(kpwd.root)); if (kpwd.isReadOnly) { attrib.add(Restrictions.readOnly()); } } }
/** * Compose multiple restrictions where each Restriction can veto an * operation. */ public static Restriction concat(Restriction... restrictions) { switch (restrictions.length) { case 0: return UNRESTRICTED; case 1: return restrictions[0]; case 2: if (restrictions [0].isSubsumedBy(restrictions [1])) { return restrictions [1]; } if (restrictions [1].isSubsumedBy(restrictions [0])) { return restrictions [0]; } // Fall through for default behaviour default: return concat(asList(restrictions)); } }
@Override public void session(Set<Principal> authorizedPrincipals, Set<Object> attrib) throws AuthenticationException { Principal principal = find(authorizedPrincipals, instanceOf(UserNamePrincipal.class), null); checkAuthentication(principal != null, "no username principal"); Collection<UserAuthzInformation> mappings = _map.getValuesForPredicatesMatching(principal.getName()); checkAuthentication(!mappings.isEmpty(), "no mapping found for " + principal); for (UserAuthzInformation mapping : mappings) { attrib.add(new HomeDirectory(mapping.getHome())); attrib.add(new RootDirectory(mapping.getRoot())); if (mapping.isReadOnly()) { attrib.add(Restrictions.readOnly()); } mapping.getMaxUpload().ifPresent(s -> { attrib.add(new MaxUploadSize(s)); }); } } }
public void setRestriction(Restriction restriction) { this.restriction = (restriction != null && !Restrictions.none().equals(restriction)) ? restriction : null; }