Examples of EditGameSecurityForm


Examples of si.unimb.cot.mgbl.gamemgmt.formbeans.EditGameSecurityForm

  public ActionForward defaultMethod(ActionMapping am, ActionForm af, HttpServletRequest req, HttpServletResponse res) {
   
    //we use transactions here
    //super.defaultMethod(am, af, req, res);
   
    EditGameSecurityForm form=(EditGameSecurityForm)af;

    MessageBean.addSpeedOMeterCheckPoint(req, "point1");
   
    form.setMyUserId(webUser.getId());
   
    long id=Long.parseLong(req.getParameter("id"));
    GameHiber g=GameDao.findGameHiber(id,session);
    Game g2=GameDao.findGame(id,session);

    MessageBean.addSpeedOMeterCheckPoint(req, "point2");
   
    form.setGame(g2);
   
    if (!SecurityCenter.canIDefineSecurityForGame(webUser.getId(), form.getGame())) {
      MessageBean.setMyMessage(req, ("Error: Insufficient privileges."));
      form.reset(session);
      return am.findForward("error");
    }
   
    //if needeed invalidate cache
    if (req.getParameter("invalidateCache")!=null) {
      SecurityCenter.invalidateCache();
      MessageBean.setMyMessage(req, ("Security cache invalidated."));
    }
   
    //do the update, if needed - allow
    MessageBean.addSpeedOMeterCheckPoint(req, "point3");

    boolean changed=false;
    if (req.getParameter("AllowBrowseSubmitUsers")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getSelectedUser(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("AllowPlaySubmitUsers")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getSelectedUser(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("AllowEditSubmitUsers")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getSelectedUser(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("AllowViewScoresSubmitUsers")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getSelectedUser(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("AllowAllSubmitUsers")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getSelectedUser(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point4");

    if (req.getParameter("AllowBrowseSubmitGroups")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getSelectedGroup(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("AllowPlaySubmitGroups")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getSelectedGroup(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("AllowEditSubmitGroups")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getSelectedGroup(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("AllowViewScoresSubmitGroups")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getSelectedGroup(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("AllowAllSubmitGroups")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getSelectedGroup(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point5");

    if (req.getParameter("AllowBrowseSubmitSets")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getSelectedUserSet(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("AllowPlaySubmitSets")!=null) { changed=true;  GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getSelectedUserSet(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("AllowEditSubmitSets")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getSelectedUserSet(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("AllowViewScoresSubmitSets")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getSelectedUserSet(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("AllowAllSubmitSets")!=null)  { changed=true; GameSecurityDao.allow(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getSelectedUserSet(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point6");

    //do the update, if needed - revoke
    if (req.getParameter("RevokeSubmitPlayUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowPlayForUsersSelected(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("RevokeSubmitPlayGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowPlayForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
    if (req.getParameter("RevokeSubmitPlaySet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowPlayForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_PLAY,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point7");

    if (req.getParameter("RevokeSubmitEditUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowEditForUsersSelected(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("RevokeSubmitEditGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowEditForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
    if (req.getParameter("RevokeSubmitEditSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowEditForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_EDIT,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point8");

    if (req.getParameter("RevokeSubmitBrowseUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowBrowseForUsersSelected(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("RevokeSubmitBrowseGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowBrowseForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
    if (req.getParameter("RevokeSubmitBrowseSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowBrowseForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_BROWSE,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point9");

    if (req.getParameter("RevokeSubmitAllUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowAllForUsersSelected(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
    if (req.getParameter("RevokeSubmitAllGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowAllForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
    if (req.getParameter("RevokeSubmitAllSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowAllForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_ALL,req,session);}
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point10");

    if (req.getParameter("RevokeSubmitViewScoresUser")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_USER,form.getAllowViewScoresForUsersSelected(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("RevokeSubmitViewScoresGroup")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_ROLE,form.getAllowViewScoresForUserGroupsSelected(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
    if (req.getParameter("RevokeSubmitViewScoresSet")!=null)   { changed=true; GameSecurityDao.revoke(form.getGame(),GameSecurity.TARGET_TYPE_SET,form.getAllowViewScoresForUserSetsSelected(),GameSecurityDao.SECURITY_TYPE_VIEW_SCORES,req,session);}
   
    if (changed) {
      //update the security summary for the game
      //for faster working!
     
      List<GameSecurityHiber> gss=null;
      StringBuffer summary=new StringBuffer();
     
      gss=GameSecurityDao.getGameSecurityForGameAllowAll(g.getId(),session);
      if (gss.size()>0) {
        summary.append("A(");
        boolean first=true;
       
        MessageBean.addSpeedOMeterCheckPoint(req, "point11");

        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
       
        MessageBean.addSpeedOMeterCheckPoint(req, "point12");

       
        summary.append(") ");
      }
     
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point13");


      gss=GameSecurityDao.getGameSecurityForGameAllowEdit(g.getId(),session);
      if (gss.size()>0) {
        summary.append("E(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        if (first) { first=false;} else {summary.append(", "); }
        summary.append(") ");
      }

     
      MessageBean.addSpeedOMeterCheckPoint(req, "point14");


      gss=GameSecurityDao.getGameSecurityForGameAllowPlay(g.getId(),session);
      if (gss.size()>0) {
        summary.append("P(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;
          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        summary.append(") ");
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point15");

      gss=GameSecurityDao.getGameSecurityForGameAllowBrowse(g.getId(),session);
      if (gss.size()>0) {
        summary.append("B(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        summary.append(") ");
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point16");

      gss=GameSecurityDao.getGameSecurityForGameAllowViewScores(g.getId(),session);
      if (gss.size()>0) {
        summary.append("VS(");
        boolean first=true;
        for (GameSecurityHiber security : gss) {
          String name="";
          switch (security.getTargetType()) {
            case GameSecurity.TARGET_TYPE_ROLE: name=UserRoleDao.findRole(security.getTargetId(),session).getRolename(); break;
            case GameSecurity.TARGET_TYPE_SET: name=UserSetDao.findUserSet(security.getTargetId(),session).getName(); break;
            case GameSecurity.TARGET_TYPE_USER:
              User u=UserDao.findUser(security.getTargetId(),session);
              name=u.getUsername();
              if ((name==null)||(name.equals(""))) name=u.getMsisdn()+"";
               
            break;

          }
          if (first) { first=false;} else {summary.append(", "); }
          summary.append(name);
        }
        summary.append(") ");
      }

      g.setSecuritySummary(summary.toString());
      GameDao.updateGame(g,session);
    }
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point17");

    //reset the view
    form.reset(session);
    MessageBean.addSpeedOMeterCheckPoint(req, "point18a");
    if (req.getParameter("id")!=null) {
      //display security for game

      Game toSet=Game.asGameObject(g);
      toSet.setGameType(g2.getGameType());
      form.setGame(toSet);

      List<GameSecurityHiber> all;
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point18");

      //allow browse
      all=GameSecurityDao.getGameSecurityForGameAllowBrowse(g.getId(),session);
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point19a");
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowBrowseForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowBrowseForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowBrowseForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point19");

      //allow play
      all=GameSecurityDao.getGameSecurityForGameAllowPlay(g.getId(),session);
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowPlayForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowPlayForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowPlayForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point20");

      //allow edit
      all=GameSecurityDao.getGameSecurityForGameAllowEdit(g.getId(),session);
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowEditForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowEditForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowEditForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point21");

      //allow view scores
      all=GameSecurityDao.getGameSecurityForGameAllowViewScores(g.getId(),session);
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowViewScoresForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowViewScoresForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowViewScoresForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }
     
      MessageBean.addSpeedOMeterCheckPoint(req, "point22");

      //allow all
      all=GameSecurityDao.getGameSecurityForGameAllowAll(g.getId(),session);
      MessageBean.addSpeedOMeterCheckPoint(req, "point23a");
      for (GameSecurityHiber security : all) {
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_ROLE)form.getAllowAllForUserGroups().add(UserRoleDao.findRole(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_SETform.getAllowAllForUserSets().add(UserSetDao.findUserSet(security.getTargetId(),session));
        if (security.getTargetType()==GameSecurity.TARGET_TYPE_USER) form.getAllowAllForUsers().add(UserDao.findUser(security.getTargetId(),session));
      }

    }
   
    MessageBean.addSpeedOMeterCheckPoint(req, "point23");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.