@Test void testAdminRoles() { final SecurityContext mockDelegate = mock(SecurityContext.class); final String iss = "https: final String sub = "acoburn"; final JwtClaims claims = new JwtClaims(); claims.setSubject(sub); claims.setIssuer(iss); claims.setClaim("groups", List.of("testers")); final JsonWebToken principal = new DefaultJWTCallerPrincipal(claims); final SecurityContext ctx = new WebIdSecurityContext(mockDelegate, principal, singleton(iss + sub)); assertTrue(ctx.isUserInRole(TrellisRoles.ADMIN)); assertTrue(ctx.isUserInRole(TrellisRoles.USER)); assertFalse(ctx.isUserInRole("other-role")); assertTrue(ctx.isUserInRole("testers")); }
@Override public boolean isUserInRole(final String role) { if (principal != null) { if (TrellisRoles.ADMIN.equals(role)) { return admins.contains(principal.getName()); } return TrellisRoles.USER.equals(role) || principal.getGroups().contains(role); } return false; }
WebIdSecurityContext implements SecurityContext { @Override public boolean isUserInRole(final String role) { if (principal != null) { if (TrellisRoles.ADMIN.equals(role)) { return admins.contains(principal.getName()); } return TrellisRoles.USER.equals(role) || principal.getGroups().contains(role); } return false; } }
WebIdSecurityContext implements SecurityContext { @Override public boolean isUserInRole(final String role) { if (principal != null) { if (TrellisRoles.ADMIN.equals(role)) { return admins.contains(principal.getName()); } return TrellisRoles.USER.equals(role) || principal.getGroups().contains(role); } return false; } WebIdSecurityContext(final SecurityContext delegate, final JsonWebToken principal,
            final Set<String> admins); }
WebIdSecurityContext implements SecurityContext { @Override public boolean isUserInRole(final String role) { if (principal != null) { if (TrellisRoles.ADMIN.equals(role)) { return admins.contains(principal.getName()); } return TrellisRoles.USER.equals(role) || principal.getGroups().contains(role); } return false; } WebIdSecurityContext(final SecurityContext delegate, final JsonWebToken principal,
            final Set<String> admins); @Override Principal getUserPrincipal(); @Override boolean isSecure(); @Override String getAuthenticationScheme(); @Override boolean isUserInRole(final String role); }
WebIdSecurityContext implements SecurityContext { @Override public boolean isUserInRole(final String role) { if (principal != null) { if (TrellisRoles.ADMIN.equals(role)) { return admins.contains(principal.getName()); } return TrellisRoles.USER.equals(role) || principal.getGroups().contains(role); } return false; } WebIdSecurityContext(final SecurityContext delegate, final JsonWebToken principal,
            final Set<String> admins); @Override Principal getUserPrincipal(); @Override boolean isSecure(); @Override String getAuthenticationScheme(); @Override boolean isUserInRole(final String role);  }