Package com.adito.security

Examples of com.adito.security.SystemDatabase


    public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
      CoreUtil.clearFlow(request);
        IpRestriction[] restrictions = null;

        SystemDatabase sdb = SystemDatabaseFactory.getInstance();
        restrictions = sdb.getIpRestrictions();
       
        ((ShowAvailableIpRestrictionsForm) form).initialize(restrictions, request.getSession());
        return mapping.findForward("success");
    }


                    throws Exception {

        String[] id = request.getParameterValues("id");
        if (id != null) {   
            IpRestriction[] ipRestrictions = findRemainingIpRestrictions(id);
            SystemDatabase database = SystemDatabaseFactory.getInstance();
            String remoteAddr = request.getRemoteAddr();
            boolean isValid = database.verifyIPAddress(remoteAddr, ipRestrictions);
            return mapping.findForward(isValid ? "confirmDelete" : "confirmDeleteWithLockout");
        }
        return mapping.findForward("refresh");
    }

        }
        return mapping.findForward("refresh");
    }
   
    private IpRestriction[] findRemainingIpRestrictions(String[] restrictionIds) throws Exception {
        SystemDatabase database = SystemDatabaseFactory.getInstance();
        IpRestriction[] restrictions = database.getIpRestrictions();
       
        Collection<IpRestriction> differences = new HashSet<IpRestriction>(Arrays.asList(restrictions));
        for (String restrictionId : restrictionIds) {
            IpRestriction ipRestriction = findIpRestriction(restrictions, Integer.valueOf(restrictionId));
            if (ipRestriction !=null) {

     * @throws Exception on any error
     */
    public ActionForward moveDown(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        PolicyUtil.checkPermission(PolicyConstants.IP_RESTRICTIONS_RESOURCE_TYPE, PolicyConstants.PERM_EDIT, request);
        int id = Integer.parseInt(request.getParameter("id"));
        SystemDatabase database = SystemDatabaseFactory.getInstance();
        IpRestriction restriction1 = database.getIpRestriction(id);
        String ipAddress = restriction1.getAddress();
        String ipPermission = restriction1.getAllowed() ? "Allowed" : "Denied";
        try {
            List<IpRestriction> restrictions = Arrays.asList(database.getIpRestrictions());
            database.swapIpRestrictions(restriction1, restrictions.get(restrictions.indexOf(restriction1) + 1));
            fireCoreEvent(request, CoreEventConstants.IP_RESTRICTION_MOVE_DOWN, ipAddress, ipPermission, CoreEvent.STATE_SUCCESSFUL);
        } catch (Exception e) {
            fireCoreEvent(request, CoreEventConstants.IP_RESTRICTION_MOVE_DOWN, ipAddress, ipPermission, CoreEvent.STATE_UNSUCCESSFUL);
            throw e;
        }       

     * @throws Exception on any error
     */
    public ActionForward moveUp(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        PolicyUtil.checkPermission(PolicyConstants.IP_RESTRICTIONS_RESOURCE_TYPE, PolicyConstants.PERM_EDIT, request);
        int id = Integer.parseInt(request.getParameter("id"));
        SystemDatabase database = SystemDatabaseFactory.getInstance();
        IpRestriction restriction1 = database.getIpRestriction(id);
        String ipAddress = restriction1.getAddress();
        String ipPermission = restriction1.getAllowed() ? "Allowed" : "Denied";
        try {
            List<IpRestriction> restrictions = Arrays.asList(database.getIpRestrictions());
            database.swapIpRestrictions(restriction1, restrictions.get(restrictions.indexOf(restriction1) - 1));
            fireCoreEvent(request, CoreEventConstants.IP_RESTRICTION_MOVE_UP, ipAddress, ipPermission, CoreEvent.STATE_SUCCESSFUL);
        } catch (Exception e) {
            fireCoreEvent(request, CoreEventConstants.IP_RESTRICTION_MOVE_UP, ipAddress, ipPermission, CoreEvent.STATE_UNSUCCESSFUL);
            throw e;
        }       

        }       
        return mapping.findForward("refresh");
    }
   
    private void deleteIpRestrictions(HttpServletRequest request, String[] restrictionIds) throws Exception {
        SystemDatabase database = SystemDatabaseFactory.getInstance();
        IpRestriction[] restrictions = database.getIpRestrictions();
       
        for (String restrictionId : restrictionIds) {
            IpRestriction ipRestriction = findIpRestriction(restrictions, Integer.valueOf(restrictionId));
            if (ipRestriction != null) {
                deleteIpRestriction(request, ipRestriction);

    private void deleteIpRestriction(HttpServletRequest request, IpRestriction restriction) throws Exception {
        String ipAddress = restriction.getAddress();
        String ipPermission = restriction.getAllowed() ? "Allowed" : "Denied";
       
        try {
            SystemDatabase database = SystemDatabaseFactory.getInstance();
            database.removeIpRestriction(restriction.getID());
            fireCoreEvent(request, CoreEventConstants.DELETE_IP_RESTRICTION, ipAddress, ipPermission, CoreEvent.STATE_SUCCESSFUL);
        } catch (Exception e) {
            fireCoreEvent(request, CoreEventConstants.DELETE_IP_RESTRICTION, ipAddress, ipPermission, CoreEvent.STATE_UNSUCCESSFUL);
            throw e;
        }       

        return cancel(mapping, form, request, response);
    }
   
    private boolean isAdditionValid(HttpServletRequest request, IpRestrictionForm form) throws Exception {
        IpRestriction[] ipRestrictions = findIpRestrictions(form.getRestriction().getAddress(), form.getType().equals(IpRestrictionForm.ALLOW_TYPE));
        SystemDatabase database = SystemDatabaseFactory.getInstance();
        String remoteAddr = request.getRemoteAddr();
        return database.verifyIPAddress(remoteAddr, ipRestrictions);
    }

        String remoteAddr = request.getRemoteAddr();
        return database.verifyIPAddress(remoteAddr, ipRestrictions);
    }

    private IpRestriction[] findIpRestrictions(String restriction, boolean isAllow) throws Exception {
        SystemDatabase database = SystemDatabaseFactory.getInstance();
        IpRestriction[] restrictions = database.getIpRestrictions();
        int i = 0;
        for(; i < restrictions.length; i++) {
          if(restrictions[i].getAddress().equals(restriction)) {
            restrictions[i] = new IpRestriction(restrictions[i].getAddress(), isAllow, restrictions[i].getPriority());
            break;

    public ActionForward favorite(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
                    throws Exception {
        AbstractResourcesForm f = (AbstractResourcesForm) form;
        ActionMessages msgs = new ActionMessages();
        User user = LogonControllerFactory.getInstance().getUser(request);
        SystemDatabase sdb = SystemDatabaseFactory.getInstance();
        if (getSessionInfo(request).getNavigationContext() != SessionInfo.USER_CONSOLE_CONTEXT) {
            throw new Exception("Favorites may only be set in the user console.");
        }       
        Resource resource = getResourceById(f.getSelectedResource());
        if(ResourceUtil.filterResourceIdsForGlobalFavorites(PolicyDatabaseFactory.getInstance().getGrantedResourcesOfType(getSessionInfo(request).getUser(),
            resource.getResourceType()), resource.getResourceType()).contains(new Integer(resource.getResourceId()))) {
            throw new Exception("Cannot set a user favorite for items that have a policy favorite.");
        }
        if (sdb.getFavorite(getResourceType().getResourceTypeId(), user, f.getSelectedResource()) != null) {
            msgs.add(Globals.ERROR_KEY, new BundleActionMessage("navigation", "addToFavorites.error.alreadyFavorite", resource
                .getResourceName()));
            saveErrors(request, msgs);
            return mapping.findForward("refresh");
        }
        sdb.addFavorite(getResourceType().getResourceTypeId(), f.getSelectedResource(), user.getPrincipalName());
        msgs.add(Globals.MESSAGES_KEY, new BundleActionMessage("navigation", "addToFavorites.message.favoriteAdded", resource
            .getResourceName()));
        saveMessages(request, msgs);
        return mapping.findForward("refresh");
    }

TOP

Related Classes of com.adito.security.SystemDatabase

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.