Package org.eclipse.jetty.util.security

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


        server.setHandler(security);

        // This constraint requires authentication and in addition that an
        // authenticated user be a member of a given set of roles for
        // authorization purposes.
        Constraint constraint = new Constraint();
        constraint.setName("auth");
        constraint.setAuthenticate(true);
        constraint.setRoles(new String[] { "user", "admin" });

        // Binds a url pattern with the previously created constraint. The roles
        // for this constraing mapping are mined from the Constraint itself
        // although methods exist to declare and bind roles separately as well.
        ConstraintMapping mapping = new ConstraintMapping();
View Full Code Here


        _server.addBean(_loginService);

        ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        _server.setHandler(security);

        Constraint constraint = new Constraint();
        constraint.setName("auth");
        constraint.setAuthenticate( true );
        constraint.setRoles(new String[]{"user", "admin"});

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

View Full Code Here

      loginService.putUser(pUser, credential, new String[] {pRole});
      return loginService;
    }

    private ConstraintMapping[] getConstraintMappings(String ... pRoles) {
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(pRoles);
        constraint.setAuthenticate(true);

        ConstraintMapping cm = new ConstraintMapping();
        cm.setConstraint(constraint);
        cm.setPathSpec("/*");
        return new ConstraintMapping[] { cm };
View Full Code Here

        new Password(properties.getProperty("eventhubhandler.password")), new String[]{"user"});

    server.addBean(loginService);

    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate( true );
    constraint.setRoles(new String[] { "user", "admin" });
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec( "/*" );
    mapping.setConstraint( constraint );
    securityHandler.setConstraintMappings(Collections.singletonList(mapping));
    securityHandler.setAuthenticator(new BasicAuthenticator());
View Full Code Here

            }
        }
        if (roleInfo.isForbidden())
            return;

        Constraint constraint = mapping.getConstraint();
        boolean forbidden = constraint.isForbidden();
        roleInfo.setForbidden(forbidden);
        if (forbidden)
        {
            if (httpMethod == null)
            {
                mappings.clear();
                mappings.put(null,roleInfo);
            }
        }
        else
        {
            UserDataConstraint userDataConstraint = UserDataConstraint.get(constraint.getDataConstraint());
            roleInfo.setUserDataConstraint(userDataConstraint);

            boolean checked = constraint.getAuthenticate();
            roleInfo.setChecked(checked);
            if (roleInfo.isChecked())
            {
                if (constraint.isAnyRole())
                {
                    if (_strict)
                    {
                        // * means "all defined roles"
                        for (String role : _roles)
                            roleInfo.addRole(role);
                    }
                    else
                        // * means any role
                        roleInfo.setAnyRole(true);
                }
                else
                {
                    String[] newRoles = constraint.getRoles();
                    for (String role : newRoles)
                    {
                        if (_strict &&!_roles.contains(role))
                            throw new IllegalArgumentException("Attempt to use undeclared role: " + role + ", known roles: " + _roles);
                        roleInfo.addRole(role);
View Full Code Here

    servletHolder.setInitParameter("resourceBase", util.resolvePath("target"));
    servletHolder.setInitParameter("dirAllowed", Boolean.TRUE.toString());

    webappContext.getServletHandler().addServletWithMapping(servletHolder, "/*");

    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(new String[]{"users"});
    constraint.setAuthenticate(true);

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

 
View Full Code Here

        HashLoginService l = new HashLoginService();
        l.putUser(username, Credential.getCredential(password), new String[] {"user"});
        l.setName(realm);

        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(new String[]{"user"});
        constraint.setAuthenticate(true);

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

 
View Full Code Here

        // Increase form size.
        context.getServletContext().getContextHandler().setMaxFormContentSize(10 * 1000 * 1000) ;

        // Wire up authentication if appropriate
        if ( jettyConfig == null && serverConfig.authConfigFile != null ) {
            Constraint constraint = new Constraint() ;
            constraint.setName(Constraint.__BASIC_AUTH) ;
            constraint.setRoles(new String[]{"fuseki"}) ;
            constraint.setAuthenticate(true) ;

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

View Full Code Here

  private ConstraintSecurityHandler newSecurityHandler(ResourceHandler handler) {
    HashLoginService login = new HashLoginService();
    login.putUser(USERNAME, Credential.getCredential(PASSWORD), new String[] { "user" });

    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(new String[] { "user" });
    constraint.setAuthenticate(true);

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

 
View Full Code Here

        Handler handler = server.getHandler();
        ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        server.setHandler(security);
        security.setHandler(handler);

        Constraint constraint = new Constraint();
        constraint.setAuthenticate(true);
        constraint.setRoles(roles);

        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setPathSpec(cometdServletPath + "/*");
        mapping.setConstraint(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.