@Test public void tooLate() { final LocalDateTime localDateTime = LocalDateTime.now(tz).minusHours(1); final Date past = Date.from(localDateTime.atZone(tz).toInstant()); IPermission permission = createMockPermission(null, past, IPermission.PERMISSION_TYPE_GRANT, null); permissions = new IPermission[] {permission}; when(authorizationService.getAllPermissionsForPrincipal( principal, IPermission.PORTAL_SYSTEM, MAX_INACTIVE_ATTR, null)) .thenReturn(permissions); assertNull("", strategy.calcMaxInactive(person)); }
@Override public Integer calcMaxInactive(IPerson person) { assert person != null; IAuthorizationPrincipal principal = authorizationService.newPrincipal( (String) person.getAttribute(IPerson.USERNAME), IPerson.class); IPermission[] permissions = authorizationService.getAllPermissionsForPrincipal( principal, IPermission.PORTAL_SYSTEM, MAX_INACTIVE_ATTR, null); assert permissions != null; if (permissions.length == 0) { log.info( "No {} permissions apply to user '{}'", MAX_INACTIVE_ATTR, person.getAttribute(IPerson.USERNAME)); return null; } Integer rulingGrant = null; Integer rulingDeny = null; for (IPermission p : permissions) { long now = System.currentTimeMillis(); if (p.getEffective() != null && p.getEffective().getTime() > now) { continue; } if (p.getExpires() != null && p.getExpires().getTime() < now) { continue; } if (p.getType().equals(IPermission.PERMISSION_TYPE_GRANT)) { try { Integer grantEntry = Integer.valueOf(p.getTarget()); if (rulingGrant == null || grantEntry < 0 || rulingGrant < grantEntry) { rulingGrant = grantEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission grant '" + p.getTarget() + "'; target must be an integer value."); } } else if (p.getType().equals(IPermission.PERMISSION_TYPE_DENY)) { try { Integer denyEntry = Integer.valueOf(p.getTarget()); if (rulingDeny == null || rulingDeny > denyEntry) { rulingDeny = denyEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission deny '" + p.getTarget() + "'; target must be an integer value."); } } else { log.warn("Unknown permission type: " + p.getType()); } } if (rulingDeny != null && rulingDeny < 0) { log.warn( "A MAX_INACTIVE DENY entry improperly specified a negative target: " + rulingDeny); rulingDeny = null; } if (rulingGrant != null || rulingDeny != null) { int maxInactive = rulingGrant != null ? rulingGrant : 0; if (rulingDeny != null) { int limit = rulingDeny; if (maxInactive >= 0) { maxInactive = limit < maxInactive ? limit : maxInactive; } else { maxInactive = limit; } } return maxInactive; } return null; }
ClassicMaxInactiveStrategy implements IMaxInactiveStrategy { @Override public Integer calcMaxInactive(IPerson person) { assert person != null; IAuthorizationPrincipal principal = authorizationService.newPrincipal( (String) person.getAttribute(IPerson.USERNAME), IPerson.class); IPermission[] permissions = authorizationService.getAllPermissionsForPrincipal( principal, IPermission.PORTAL_SYSTEM, MAX_INACTIVE_ATTR, null); assert permissions != null; if (permissions.length == 0) { log.info( "No {} permissions apply to user '{}'", MAX_INACTIVE_ATTR, person.getAttribute(IPerson.USERNAME)); return null; } Integer rulingGrant = null; Integer rulingDeny = null; for (IPermission p : permissions) { long now = System.currentTimeMillis(); if (p.getEffective() != null && p.getEffective().getTime() > now) { continue; } if (p.getExpires() != null && p.getExpires().getTime() < now) { continue; } if (p.getType().equals(IPermission.PERMISSION_TYPE_GRANT)) { try { Integer grantEntry = Integer.valueOf(p.getTarget()); if (rulingGrant == null || grantEntry < 0 || rulingGrant < grantEntry) { rulingGrant = grantEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission grant '" + p.getTarget() + "'; target must be an integer value."); } } else if (p.getType().equals(IPermission.PERMISSION_TYPE_DENY)) { try { Integer denyEntry = Integer.valueOf(p.getTarget()); if (rulingDeny == null || rulingDeny > denyEntry) { rulingDeny = denyEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission deny '" + p.getTarget() + "'; target must be an integer value."); } } else { log.warn("Unknown permission type: " + p.getType()); } } if (rulingDeny != null && rulingDeny < 0) { log.warn( "A MAX_INACTIVE DENY entry improperly specified a negative target: " + rulingDeny); rulingDeny = null; } if (rulingGrant != null || rulingDeny != null) { int maxInactive = rulingGrant != null ? rulingGrant : 0; if (rulingDeny != null) { int limit = rulingDeny; if (maxInactive >= 0) { maxInactive = limit < maxInactive ? limit : maxInactive; } else { maxInactive = limit; } } return maxInactive; } return null; } }
ClassicMaxInactiveStrategy implements IMaxInactiveStrategy { @Override public Integer calcMaxInactive(IPerson person) { assert person != null; IAuthorizationPrincipal principal = authorizationService.newPrincipal( (String) person.getAttribute(IPerson.USERNAME), IPerson.class); IPermission[] permissions = authorizationService.getAllPermissionsForPrincipal( principal, IPermission.PORTAL_SYSTEM, MAX_INACTIVE_ATTR, null); assert permissions != null; if (permissions.length == 0) { log.info( "No {} permissions apply to user '{}'", MAX_INACTIVE_ATTR, person.getAttribute(IPerson.USERNAME)); return null; } Integer rulingGrant = null; Integer rulingDeny = null; for (IPermission p : permissions) { long now = System.currentTimeMillis(); if (p.getEffective() != null && p.getEffective().getTime() > now) { continue; } if (p.getExpires() != null && p.getExpires().getTime() < now) { continue; } if (p.getType().equals(IPermission.PERMISSION_TYPE_GRANT)) { try { Integer grantEntry = Integer.valueOf(p.getTarget()); if (rulingGrant == null || grantEntry < 0 || rulingGrant < grantEntry) { rulingGrant = grantEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission grant '" + p.getTarget() + "'; target must be an integer value."); } } else if (p.getType().equals(IPermission.PERMISSION_TYPE_DENY)) { try { Integer denyEntry = Integer.valueOf(p.getTarget()); if (rulingDeny == null || rulingDeny > denyEntry) { rulingDeny = denyEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission deny '" + p.getTarget() + "'; target must be an integer value."); } } else { log.warn("Unknown permission type: " + p.getType()); } } if (rulingDeny != null && rulingDeny < 0) { log.warn( "A MAX_INACTIVE DENY entry improperly specified a negative target: " + rulingDeny); rulingDeny = null; } if (rulingGrant != null || rulingDeny != null) { int maxInactive = rulingGrant != null ? rulingGrant : 0; if (rulingDeny != null) { int limit = rulingDeny; if (maxInactive >= 0) { maxInactive = limit < maxInactive ? limit : maxInactive; } else { maxInactive = limit; } } return maxInactive; } return null; }  }
ClassicMaxInactiveStrategy implements IMaxInactiveStrategy { @Override public Integer calcMaxInactive(IPerson person) { assert person != null; IAuthorizationPrincipal principal = authorizationService.newPrincipal( (String) person.getAttribute(IPerson.USERNAME), IPerson.class); IPermission[] permissions = authorizationService.getAllPermissionsForPrincipal( principal, IPermission.PORTAL_SYSTEM, MAX_INACTIVE_ATTR, null); assert permissions != null; if (permissions.length == 0) { log.info( "No {} permissions apply to user '{}'", MAX_INACTIVE_ATTR, person.getAttribute(IPerson.USERNAME)); return null; } Integer rulingGrant = null; Integer rulingDeny = null; for (IPermission p : permissions) { long now = System.currentTimeMillis(); if (p.getEffective() != null && p.getEffective().getTime() > now) { continue; } if (p.getExpires() != null && p.getExpires().getTime() < now) { continue; } if (p.getType().equals(IPermission.PERMISSION_TYPE_GRANT)) { try { Integer grantEntry = Integer.valueOf(p.getTarget()); if (rulingGrant == null || grantEntry < 0 || rulingGrant < grantEntry) { rulingGrant = grantEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission grant '" + p.getTarget() + "'; target must be an integer value."); } } else if (p.getType().equals(IPermission.PERMISSION_TYPE_DENY)) { try { Integer denyEntry = Integer.valueOf(p.getTarget()); if (rulingDeny == null || rulingDeny > denyEntry) { rulingDeny = denyEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission deny '" + p.getTarget() + "'; target must be an integer value."); } } else { log.warn("Unknown permission type: " + p.getType()); } } if (rulingDeny != null && rulingDeny < 0) { log.warn( "A MAX_INACTIVE DENY entry improperly specified a negative target: " + rulingDeny); rulingDeny = null; } if (rulingGrant != null || rulingDeny != null) { int maxInactive = rulingGrant != null ? rulingGrant : 0; if (rulingDeny != null) { int limit = rulingDeny; if (maxInactive >= 0) { maxInactive = limit < maxInactive ? limit : maxInactive; } else { maxInactive = limit; } } return maxInactive; } return null; }  @Override Integer calcMaxInactive(IPerson person); }
ClassicMaxInactiveStrategy implements IMaxInactiveStrategy { @Override public Integer calcMaxInactive(IPerson person) { assert person != null; IAuthorizationPrincipal principal = authorizationService.newPrincipal( (String) person.getAttribute(IPerson.USERNAME), IPerson.class); IPermission[] permissions = authorizationService.getAllPermissionsForPrincipal( principal, IPermission.PORTAL_SYSTEM, MAX_INACTIVE_ATTR, null); assert permissions != null; if (permissions.length == 0) { log.info( "No {} permissions apply to user '{}'", MAX_INACTIVE_ATTR, person.getAttribute(IPerson.USERNAME)); return null; } Integer rulingGrant = null; Integer rulingDeny = null; for (IPermission p : permissions) { long now = System.currentTimeMillis(); if (p.getEffective() != null && p.getEffective().getTime() > now) { continue; } if (p.getExpires() != null && p.getExpires().getTime() < now) { continue; } if (p.getType().equals(IPermission.PERMISSION_TYPE_GRANT)) { try { Integer grantEntry = Integer.valueOf(p.getTarget()); if (rulingGrant == null || grantEntry < 0 || rulingGrant < grantEntry) { rulingGrant = grantEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission grant '" + p.getTarget() + "'; target must be an integer value."); } } else if (p.getType().equals(IPermission.PERMISSION_TYPE_DENY)) { try { Integer denyEntry = Integer.valueOf(p.getTarget()); if (rulingDeny == null || rulingDeny > denyEntry) { rulingDeny = denyEntry; } } catch (NumberFormatException nfe) { log.warn( "Invalid MAX_INACTIVE permission deny '" + p.getTarget() + "'; target must be an integer value."); } } else { log.warn("Unknown permission type: " + p.getType()); } } if (rulingDeny != null && rulingDeny < 0) { log.warn( "A MAX_INACTIVE DENY entry improperly specified a negative target: " + rulingDeny); rulingDeny = null; } if (rulingGrant != null || rulingDeny != null) { int maxInactive = rulingGrant != null ? rulingGrant : 0; if (rulingDeny != null) { int limit = rulingDeny; if (maxInactive >= 0) { maxInactive = limit < maxInactive ? limit : maxInactive; } else { maxInactive = limit; } } return maxInactive; } return null; }  @Override Integer calcMaxInactive(IPerson person); static final String MAX_INACTIVE_ATTR; }