Package org.eclipse.jetty.util.security

Examples of org.eclipse.jetty.util.security.Constraint


     * @param descriptor
     * @param node
     */
    protected void visitSecurityConstraint(WebAppContext context, Descriptor descriptor, XmlParser.Node node)
    {
        Constraint scBase = new Constraint();

        //ServletSpec 3.0, p74 security-constraints, as minOccurs > 1, are additive
        //across fragments
       
        //TODO: need to remember origin of the constraints
        try
        {
            XmlParser.Node auths = node.get("auth-constraint");

            if (auths != null)
            {
                scBase.setAuthenticate(true);
                // auth-constraint
                Iterator<XmlParser.Node> iter = auths.iterator("role-name");
                List<String> roles = new ArrayList<String>();
                while (iter.hasNext())
                {
                    String role = iter.next().toString(false, true);
                    roles.add(role);
                }
                scBase.setRoles(roles.toArray(new String[roles.size()]));
            }

            XmlParser.Node data = node.get("user-data-constraint");
            if (data != null)
            {
                data = data.get("transport-guarantee");
                String guarantee = data.toString(false, true).toUpperCase(Locale.ENGLISH);
                if (guarantee == null || guarantee.length() == 0 || "NONE".equals(guarantee))
                    scBase.setDataConstraint(Constraint.DC_NONE);
                else if ("INTEGRAL".equals(guarantee))
                    scBase.setDataConstraint(Constraint.DC_INTEGRAL);
                else if ("CONFIDENTIAL".equals(guarantee))
                    scBase.setDataConstraint(Constraint.DC_CONFIDENTIAL);
                else
                {
                    LOG.warn("Unknown user-data-constraint:" + guarantee);
                    scBase.setDataConstraint(Constraint.DC_CONFIDENTIAL);
                }
            }
            Iterator<XmlParser.Node> iter = node.iterator("web-resource-collection");
            while (iter.hasNext())
            {
                XmlParser.Node collection =  iter.next();
                String name = collection.getString("web-resource-name", false, true);
                Constraint sc = (Constraint) scBase.clone();
                sc.setName(name);

                Iterator<XmlParser.Node> iter2 = collection.iterator("url-pattern");
                while (iter2.hasNext())
                {
                    String url = iter2.next().toString(false, true);
View Full Code Here


        return context;
    }

    private static SecurityHandler createSecurityHandler(LoginService loginService)
    {
        Constraint constraint = new Constraint();
        constraint.setAuthenticate(false);

        ConstraintMapping constraintMapping = new ConstraintMapping();
        constraintMapping.setConstraint(constraint);
        constraintMapping.setPathSpec("/*");

 
View Full Code Here

        return context;
    }

    private static SecurityHandler createSecurityHandler(LoginService loginService)
    {
        Constraint constraint = new Constraint();
        constraint.setAuthenticate(false);

        ConstraintMapping constraintMapping = new ConstraintMapping();
        constraintMapping.setConstraint(constraint);
        constraintMapping.setPathSpec("/*");

 
View Full Code Here

    private static void addAuthHandler(Server server, String auth, LoginAuthenticator authenticator, boolean strict, Handler handler) {

        server.addBean(LOGIN_SERVICE);

        Constraint constraint = new Constraint();
        constraint.setName(auth);
        constraint.setRoles(new String[] { USER, ADMIN });
        constraint.setAuthenticate(true);

        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setConstraint(constraint);
        mapping.setPathSpec("/*");

 
View Full Code Here

        return request;
    }

    protected ConstraintMapping constraintMapping(String method, String url, String... roles) {
        ConstraintMapping constraintMapping = new ConstraintMapping();
        Constraint constraint = new Constraint();
        constraintMapping.setMethod(method);
        constraintMapping.setPathSpec(url);
        if (roles.length > 0) {
            constraint.setAuthenticate(true);
            constraint.setRoles(roles);
        }
        constraintMapping.setConstraint(constraint);
        return constraintMapping;
    }
View Full Code Here

        return constraintMapping;
    }

    protected ConstraintMapping forbidden(String method, String url) {
        ConstraintMapping constraintMapping = new ConstraintMapping();
        Constraint constraint = new Constraint();
        constraintMapping.setMethod(method);
        constraintMapping.setPathSpec(url);
        constraint.setAuthenticate(true);
        constraintMapping.setConstraint(constraint);
        return constraintMapping;
    }
View Full Code Here

        localServer.addBean(new JsonErrorHandler());

        try {
            if(login != AuthenticationType.NONE) {
                Authenticator authenticator = login.createAuthenticator();
                Constraint constraint = new Constraint(authenticator.getAuthMethod(), REST_ROLE);
                constraint.setAuthenticate(true);

                ConstraintMapping cm = new ConstraintMapping();
                cm.setPathSpec("/*");
                cm.setConstraint(constraint);

View Full Code Here

        throw new IllegalArgumentException("Unable to find login config resource: " + getLoginConfig());
      }
      System.setProperty(AUTH_LOGIN_CONFIG_PROPERTY, loginConfigResource.getFile().getPath());
    }
   
    Constraint userConstraint = new Constraint();
    userConstraint.setRoles(new String[] {"user"});
    userConstraint.setAuthenticate(true);
    ConstraintMapping restrictedConstraintMapping = new ConstraintMapping();
    restrictedConstraintMapping.setConstraint(userConstraint);
    restrictedConstraintMapping.setPathSpec("/*");
   
    Constraint noAuthenticationConstraint = new Constraint();
    noAuthenticationConstraint.setAuthenticate(false);
    ConstraintMapping publicConstraintMapping = new ConstraintMapping();
    publicConstraintMapping.setConstraint(noAuthenticationConstraint);
    publicConstraintMapping.setPathSpec("/jax/bundles/fm/prototype/login.ftl");
   
    JAASLoginService loginService = new JAASLoginService("OpenGamma");
View Full Code Here


    /* ------------------------------------------------------------ */
    public static Constraint createConstraint()
    {
        return new Constraint();
    }
View Full Code Here

     * @param roles
     * @param dataConstraint
     */
    public static Constraint createConstraint (String name, boolean authenticate, String[] roles, int dataConstraint)
    {
        Constraint constraint = createConstraint();
        if (name != null)
            constraint.setName(name);
        constraint.setAuthenticate(authenticate);
        constraint.setRoles(roles);
        constraint.setDataConstraint(dataConstraint);
        return constraint;
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.util.security.Constraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.