Package org.apache.jetspeed.services.security

Examples of org.apache.jetspeed.services.security.RoleException


            }
            user = (LDAPUser)JetspeedSecurity.getUser(new UserNamePrincipal(username));
        }
        catch(JetspeedSecurityException e)
        {
            throw new RoleException("Failed to Retrieve User: ", e);
        }
        try
        {
            for (Enumeration enum1 = user.getGroupRoles().elements(); enum1.hasMoreElements();)
            {
                st = new StringTokenizer((String)enum1.nextElement(),",");
                String gn = st.nextToken();
                String rn = st.nextToken();
                if (rn.equalsIgnoreCase(roleName) && gn.equalsIgnoreCase(groupName))
                {
                    return true;
                }
            }
        }
        catch(Exception e)
        {
            throw new RoleException("Failed to retrieve roles ", e);
        }
        return false;
    }
View Full Code Here


            {
                return new LDAPRole((LDAPURL) ((Vector)roleurls.elementAt(0)).firstElement());
            }
            else if(roleurls.size() > 1)
            {
                throw new RoleException("Multiple roles with same name");
            }
        }
        catch(Exception e)
        {
            throw new RoleException("Failed to retrieve roles ", e);
        }
        throw new RoleException("Unknown role '" + roleName + "'");
    }
View Full Code Here

                return true;
            }
        }
        catch(Exception e)
        {
            throw new RoleException("Failed to retrieve roles ", e);
        }
        return false;
    }
View Full Code Here

            user = JetspeedSecurity.getUser(new UserNamePrincipal(username));
        }
        catch(JetspeedSecurityException e)
        {
            logger.error( "Failed to Retrieve User: " + username, e );
            throw new RoleException("Failed to Retrieve User: ", e);
        }
        Criteria criteria = new Criteria();
        criteria.add(TurbineUserGroupRolePeer.USER_ID, user.getUserId());
        List rels;
        HashMap roles;

        try
        {
            rels = TurbineUserGroupRolePeer.doSelect(criteria);
            if (rels.size() > 0)
            {
                roles = new HashMap(rels.size());
            }
            else
                roles = new HashMap();

            for (int ix = 0; ix < rels.size(); ix++)
            {
                TurbineUserGroupRole rel = (TurbineUserGroupRole)rels.get(ix);
                Role role = rel.getTurbineRole();
                roles.put(role.getName(), role);
            }
        }
        catch(Exception e)
        {
            logger.error( "Failed to retrieve roles ", e );
            throw new RoleException("Failed to retrieve roles ", e);
        }
        return roles.values().iterator();
    }
View Full Code Here

            roles = TurbineRolePeer.doSelect(criteria);
        }
        catch(Exception e)
        {
            logger.error( "Failed to retrieve roles ", e );
            throw new RoleException("Failed to retrieve roles ", e);
        }
        return roles.iterator();
    }
View Full Code Here

    public void addRole(Role role)
        throws JetspeedSecurityException
    {
        if(roleExists(role.getName()))
        {
            throw new RoleException("The role '" +
                role.getName() + "' already exists");
        }

        try
        {
            TurbineRole trole = new TurbineRole();
            trole.setRoleName(role.getName());
            Criteria criteria = TurbineRolePeer.buildCriteria(trole);
            NumberKey key = (NumberKey)TurbineRolePeer.doInsert(criteria);
            role.setId(key.toString());
        }
        catch(Exception e)
        {
            String message = "Failed to create role '" + role.getName() + "'";
            logger.error( message, e );
            throw new RoleException( message, e );
        }

        if (cachingEnable)
        {
            JetspeedSecurityCache.addRole(role);
        }

        try
        {
            addDefaultRolePSML(role);
        }
        catch (Exception e)
        {
            try
            {
                removeRole(role.getName());
            }
            catch (Exception e2)
            {
            }
            logger.error( "Failed to add default PSML for Role resource", e );
            throw new RoleException("Failed to add default PSML for Role resource", e);
        }

    }
View Full Code Here

            }
            catch(Exception e2)
            {
            }
            logger.error( "Failed to create Role PSML", e );
            throw new RoleException("Failed to create Role PSML", e);
        }
    }
View Full Code Here

    public void saveRole(Role role)
        throws JetspeedSecurityException
    {
        if(!roleExists(role.getName()))
        {
            throw new RoleException("The role '" +
                role.getName() + "' doesn't exists");
        }

        try
        {
            if (role instanceof TurbineRole)
            {
                TurbineRolePeer.doUpdate((TurbineRole)role);
            }
            else
            {
                throw new RoleException("TurbineRoleManagment: Role is not a Turbine role, cannot update");
            }

        }
        catch(Exception e)
        {
            String message = "Failed to create role '" + role.getName() + "'";
            logger.error( message, e );
            throw new RoleException( message, e );
        }

    }
View Full Code Here

        Connection conn = null;
        try
        {
            if (systemRoles.contains(rolename))
            {
                throw new RoleException("[" + rolename + "] is a system role and cannot be removed");
            }

            conn = Torque.getConnection();
            Role role = this.getRole(rolename);

            Criteria criteria = new Criteria();
            criteria.add(TurbineRolePeer.ROLE_NAME, rolename);

            if(cascadeDelete)
            {
                // CASCADE TURBINE_USER_GROUP_ROLE, TURBINE_ROLE_PERMISSION
                Criteria criteria1 = new Criteria();
                criteria1.add(TurbineUserGroupRolePeer.ROLE_ID, role.getId());
                TurbineUserGroupRolePeer.doDelete(criteria1, conn);

                Criteria criteria2 = new Criteria();
                criteria2.add(TurbineRolePermissionPeer.ROLE_ID, role.getId());
                TurbineRolePermissionPeer.doDelete(criteria2, conn);
            }

            TurbineRolePeer.doDelete(criteria, conn);
            PsmlManager.removeRoleDocuments(role);

            conn.commit();

            if (cachingEnable)
            {
                JetspeedSecurityCache.removeAllRoles(rolename);
            }
        }
        catch(Exception e)
        {
            try
            {
                conn.rollback();
            }
            catch (java.sql.SQLException sqle)
            {
                logger.error("SQLException", sqle);
            }
            String message = "Failed to remove role '" + rolename + "'";
            logger.error( message, e );
            throw new RoleException( message, e );
        }
        finally
        {
            try
            {
View Full Code Here

        }
        catch(Exception e)
        {
            String message = "Grant role '" + rolename + "' to user '" + username + "' failed: ";
            logger.error( message, e );
            throw new RoleException( message, e );
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.services.security.RoleException

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.