/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ @Override public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) { //allow for lazy role naming: if a role is named in a security constraint, try and //add it to the list of declared roles (ie as if it was declared with a security-role for (String role : mapping.getConstraint().getRoles()) { if ("*".equals(role) || "**".equals(role)) continue; addRole(role); } } if (isStarted()) { processConstraintMapping(mapping); } }
for (ConstraintMapping cm : constraintMappings) String[] cmr = cm.getConstraint().getRoles(); if (cmr!=null)
Constraint constraint = mapping.getConstraint(); boolean forbidden = constraint.isForbidden(); ri.setForbidden(forbidden); UserDataConstraint userDataConstraint = UserDataConstraint.get(mapping.getConstraint().getDataConstraint()); ri.setUserDataConstraint(userDataConstraint); boolean checked = mapping.getConstraint().getAuthenticate(); ri.setChecked(checked); if (mapping.getConstraint().isAnyRole()) ri.setAnyRole(true); else if (mapping.getConstraint().isAnyAuth()) String[] newRoles = mapping.getConstraint().getRoles(); for (String role : newRoles)
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ public void addConstraintMapping(ConstraintMapping mapping) { constraintMappings.add(mapping); if (mapping.getConstraint() != null && mapping.getConstraint().getRoles() != null) for (String role : mapping.getConstraint().getRoles()) if (!"*".equals(role)) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) for (String role : mapping.getConstraint().getRoles()) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ @Override public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) for (String role : mapping.getConstraint().getRoles()) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) for (String role : mapping.getConstraint().getRoles()) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ @Override public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) for (String role : mapping.getConstraint().getRoles()) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) for (String role : mapping.getConstraint().getRoles()) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) for (String role : mapping.getConstraint().getRoles()) addRole(role); if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ @Override public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) { //allow for lazy role naming: if a role is named in a security constraint, try and //add it to the list of declared roles (ie as if it was declared with a security-role for (String role : mapping.getConstraint().getRoles()) { if ("*".equals(role) || "**".equals(role)) continue; addRole(role); } } if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ @Override public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) { //allow for lazy role naming: if a role is named in a security constraint, try and //add it to the list of declared roles (ie as if it was declared with a security-role for (String role : mapping.getConstraint().getRoles()) { if ("*".equals(role) || "**".equals(role)) continue; addRole(role); } } if (isStarted()) { processConstraintMapping(mapping); } }
/** * @see org.eclipse.jetty.security.ConstraintAware#addConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) */ @Override public void addConstraintMapping(ConstraintMapping mapping) { _constraintMappings.add(mapping); if (mapping.getConstraint()!=null && mapping.getConstraint().getRoles()!=null) { //allow for lazy role naming: if a role is named in a security constraint, try and //add it to the list of declared roles (ie as if it was declared with a security-role for (String role : mapping.getConstraint().getRoles()) { if ("*".equals(role) || "**".equals(role)) continue; addRole(role); } } if (isStarted()) { processConstraintMapping(mapping); } }
/** * Process the constraints following the combining rules in Servlet 3.0 EA * spec section 13.7.1 Note that much of the logic is in the RoleInfo class. * * @param constraintMappings The constraintMappings to set. * @param roles The known roles (or null to determine them from the mappings) */ public void setConstraintMappings(List<ConstraintMapping> constraintMappings, Set<String> roles) { if (isStarted()) throw new IllegalStateException("Started"); this.constraintMappings.clear(); this.constraintMappings.addAll(constraintMappings); if (roles == null) { roles = new HashSet<String>(); for (ConstraintMapping cm : constraintMappings) { String[] cmr = cm.getConstraint().getRoles(); if (cmr != null) { for (String r : cmr) if (!"*".equals(r)) roles.add(r); } } } setRoles(roles); }
private ConstraintMapping createConstraintMapping() { ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(new Constraint()); cm.getConstraint().setAuthenticate(true); cm.getConstraint().setDataConstraint(Constraint.DC_NONE); cm.getConstraint().setRoles(new String[] { authRole }); cm.setPathSpec("/*"); return cm; }
for (ConstraintMapping cm : constraintMappings) String[] cmr = cm.getConstraint().getRoles(); if (cmr!=null)
for (ConstraintMapping cm : constraintMappings) String[] cmr = cm.getConstraint().getRoles(); if (cmr!=null)
for (ConstraintMapping cm : constraintMappings) String[] cmr = cm.getConstraint().getRoles(); if (cmr!=null)
protected void processConstraintMapping(ConstraintMapping mapping) { String pathSpec = mapping.getPathSpec(); StringTokenizer tok = new StringTokenizer(pathSpec, PATH_SPEC_SEPARATORS); String httpMethod = mapping.getMethod(); while (tok.hasMoreTokens()) { String spec = tok.nextToken().trim(); if (httpMethod == null) { if ("*".equals(spec)) { if (defaultRoleInfo == null) { defaultRoleInfo = new RoleInfo(); } addConstraint(defaultRoleInfo, mapping.getConstraint()); } else { throw new IllegalArgumentException("No method specified for PathSpec " + pathSpec + "."); } } RestPathMap<RoleInfo> mappings = constraintMap.get(httpMethod); if (mappings == null) { mappings = new RestPathMap<RoleInfo>(); constraintMap.put(httpMethod, mappings); } RoleInfo roleInfo = mappings.get(spec); if (roleInfo == null) { roleInfo = new RoleInfo(); mappings.put(spec, roleInfo); } addConstraint(roleInfo, mapping.getConstraint()); } }
private void auth(ServletContextHandler ctx, Authenticator authType) { final String role = "can-access"; MappedLoginService users = new MappedLoginService() { @Override protected UserIdentity loadUser(String who) { return null; } @Override protected void loadUsers() throws IOException { putUser(username, new Password(password), new String[] { role }); } }; ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(new Constraint()); cm.getConstraint().setAuthenticate(true); cm.getConstraint().setDataConstraint(Constraint.DC_NONE); cm.getConstraint().setRoles(new String[] { role }); cm.setPathSpec("/*"); ConstraintSecurityHandler sec = new ConstraintSecurityHandler(); sec.setStrict(false); sec.setRealmName(realm); sec.setAuthenticator(authType); sec.setLoginService(users); sec.setConstraintMappings(new ConstraintMapping[] { cm }); sec.setHandler(ctx); contexts.removeHandler(ctx); contexts.addHandler(sec); }