Package org.nxplanner.domain

Examples of org.nxplanner.domain.Role


        // Search for additional roles
        List roles = getRoles(context, user);
        for (int i = 0; i < roles.size(); i++) {
            String roleName = (String)roles.get(i);
            subject.getPrincipals().add(new Role(roleName));
        }
        // Create and return a suitable Principal for this user
        return subject;
    }
View Full Code Here


    }


    private boolean hasRole(Collection roles, String name) {
        for (Iterator iterator = roles.iterator(); iterator.hasNext();) {
            Role role = (Role)iterator.next();
            if (role.getName().equals(name)) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

    // These helper functions should be refactored into the domain objects

    private boolean hasRole(Collection roles, String name) {
        for (Iterator iterator = roles.iterator(); iterator.hasNext();) {
            Role role = (Role)iterator.next();
            if (role.getName().equals(name)) {
                return true;
            }
        }
        return false;
    }
View Full Code Here

                    Role.class.getName() + " where role.name = ?",
                    rolename, Hibernate.STRING);
        } catch (HibernateException e) {
            throw new RepositoryException();
        }
        Role role = null;
        Iterator roleIterator = roles.iterator();
        if (roleIterator.hasNext()) {
            role = (Role)roleIterator.next();
        }
        return role;
View Full Code Here

            throw new RepositoryException(e);
        }
    }

    public void deleteForPersonOnProject(String roleName, int personId, int projectId) throws RepositoryException {
        Role role = roleRepository.findRoleByName(roleName);
        try {
            ThreadSession.get().delete("from assoc in " + RoleAssociation.class +
                    " where assoc.roleId = ? and assoc.projectId = ? and assoc.personId = ?",
                    new Object[]{new Integer(role.getId()), new Integer(projectId),
                                 new Integer(personId)},
                    new Type[]{Hibernate.INTEGER, Hibernate.INTEGER, Hibernate.INTEGER});
        } catch (HibernateException e) {
            throw new RepositoryException(e);
        }
View Full Code Here

        }
    }

    public void insertForPersonOnProject(String roleName, int personId, int projectId)
            throws RepositoryException {
        Role role = roleRepository.findRoleByName(roleName);
        if (role != null) {
            try {
                ThreadSession.get().save(new RoleAssociation(projectId, personId, role.getId()));
            } catch (HibernateException e) {
                throw new RepositoryException(e);
            }
        }
    }
View Full Code Here

    public static boolean isUserInRole(HttpServletRequest request, String roleName) {
        Subject subject = getSubject(request);
        if (subject != null) {
            Iterator roles = subject.getPrincipals(Role.class).iterator();
            while (roles.hasNext()) {
                Role role = (Role)roles.next();
                if (role.getName().equals(roleName)) {
                    return true;
                }
            }
        }
        return false;
View Full Code Here

                sysadmin.setInitials("SYS");
                sysadmin.setPassword("1tGWp1Bdm02Sw4bD7/o0N2ao405Tf8kjxGBW/A=="); // password=admin
                sysadmin.setLastUpdateTime(new Date());
                session.save(sysadmin);
            }
            Role viewerRole = initializeRole(session, "viewer", 1, 8);
            Role editorRole = initializeRole(session, "editor", 2, 7);
            Role adminRole = initializeRole(session, "admin", 3, 6);
            Role sysadminRole = initializeRole(session, "sysadmin", 4, 5);
            addRoleAssociation(session, sysadminRole.getId(), sysadmin.getId(), 0);
            createPermission(session, sysadminRole, "%", "%");
            createPermission(session, adminRole, "%", "admin%");
            createPermission(session, editorRole, "%", "create%");
            createPermission(session, editorRole, "%", "edit%");
            createPermission(session, editorRole, "%", "integrate%");
View Full Code Here

    }

    private Role initializeRole(Session session, String roleName, int left, int right) throws HibernateException {
        List roles = session.find("from role in class " + Role.class.getName() + " where role.name = ?",
                roleName, Hibernate.STRING);
        Role role;
        if (roles.size() == 0) {
            log.info("creating role: " + roleName);
            role = new Role(roleName);
            role.setLeft(left);
            role.setRight(right);
            session.save(role);
        } else {
            role = (Role) roles.get(0);
        }
        return role;
View Full Code Here

    public Subject setUpSubject(Person person, String[] roles) {
        Subject subject = new Subject();
        subject.getPrincipals().add(new PersonPrincipal(person));
        for (int i = 0; i < roles.length; i++) {
            if (roles[i] != null) {
                subject.getPrincipals().add(new Role(roles[i]));
            }
        }
        SecurityHelper.setSubject(request, subject);
        return subject;
    }
View Full Code Here

TOP

Related Classes of org.nxplanner.domain.Role

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.