// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SecurityUtil.java

package com.keyshop.pub.security.util;

import com.keyshop.pub.security.bo.AuthuserLogBO;
import com.keyshop.pub.security.model.*;
import java.io.PrintStream;
import java.sql.Date;
import java.util.*;

public class SecurityUtil
{

    public static final String USERCATEGORY_SUPER = "1";
    public static final String USERCATEGORY_NORMAL = "0";
    public static final String USERROLE_SELLFITTINGS = "1";
    public static final String USERROLE_STOCK = "2";
    public static final String USERROLE_FINANCE = "3";
    public static final String USERROLE_BASEINFO = "4";
    public static final String USERROLE_SYSTEM = "5";
    public static final String USERROLE_REPORT = "6";
    public static final String USERROLES[] = {
        "1", "2", "3", "4", "5", "6"
    };
    public static final ArrayList SELLFITTINGSACTIONS;
    public static final ArrayList STOCKACTIONS;
    public static final ArrayList FINANCEACTIONS;
    public static final ArrayList REPORTACTIONS;
    public static final ArrayList BASEINFOACTIONS;
    public static final ArrayList SYSTEMACTIONS;
    public static final ArrayList USERROLEACTIONS;

    public SecurityUtil()
    {
    }

    public static String getActionRole(String actionClassName)
    {
        for(int i = 0; i < USERROLES.length; i++)
        {
            Iterator it = ((ArrayList)USERROLEACTIONS.get(i)).iterator();
            String role = USERROLES[i];
            while(it.hasNext()) 
            {
                String className = (String)it.next();
                if(actionClassName.equals(className))
                    return role;
            }
        }

        return null;
    }

    public static boolean hasRole(String className, User user)
    {
        String classRoleId = getActionRole(className);
        System.out.println("classRoleId = " + classRoleId);
        if(user != null)
        {
            Set roleList = user.getChildList();
            if(roleList != null && roleList.size() > 0)
            {
                for(Iterator it = roleList.iterator(); it.hasNext();)
                {
                    UserRole userRole = (UserRole)it.next();
                    if(userRole.getRoleId().equals(classRoleId))
                        return true;
                }

            }
        }
        return false;
    }

    public static boolean hasRoleById(String roleId, User user)
    {
        if(user != null)
        {
            Set roleList = user.getChildList();
            if(roleList != null && roleList.size() > 0)
            {
                for(Iterator it = roleList.iterator(); it.hasNext();)
                {
                    UserRole userRole = (UserRole)it.next();
                    if(userRole.getRoleId().equals(roleId))
                        return true;
                }

            }
        }
        return false;
    }

    public static void addAuthuserLog(String content, Date time, String userId, String userName)
        throws Exception
    {
        AuthuserLog authuserLog = new AuthuserLog();
        authuserLog.setContent(content);
        authuserLog.setTime(time);
        authuserLog.setUserId(userId);
        authuserLog.setUserName(userName);
        AuthuserLogBO authuserLogBo = new AuthuserLogBO();
        authuserLogBo.addBean(authuserLog);
        System.out.print("The authuserLog======" + authuserLog);
    }

    static 
    {
        SELLFITTINGSACTIONS = new ArrayList();
        SELLFITTINGSACTIONS.add("com.keyshop.csms.fittings.controller.SellQuotationSheetAction");
        SELLFITTINGSACTIONS.add("com.keyshop.csms.fittings.controller.SellSheetAction");
        SELLFITTINGSACTIONS.add("com.keyshop.csms.fittings.controller.SellReturnSheetAction");
        STOCKACTIONS = new ArrayList();
        STOCKACTIONS.add("com.keyshop.csms.fittings.controller.InStoreSheetAction");
        STOCKACTIONS.add("com.keyshop.csms.fittings.controller.PurReGoodsSheetAction");
        STOCKACTIONS.add("com.keyshop.csms.fittings.controller.AskPriceSheetAction");
        STOCKACTIONS.add("com.keyshop.csms.fittings.controller.InstigatesSheetAction");
        STOCKACTIONS.add("com.keyshop.csms.fittings.controller.StockCheckSheetAction");
        STOCKACTIONS.add("com.keyshop.csms.fittings.controller.StockFittingsDetailAction");
        FINANCEACTIONS = new ArrayList();
        FINANCEACTIONS.add("com.keyshop.csms.finance.controller.BaddebtAction");
        FINANCEACTIONS.add("com.keyshop.csms.finance.controller.ChargeAction");
        FINANCEACTIONS.add("com.keyshop.csms.finance.controller.ClientFinanceAction");
        FINANCEACTIONS.add("com.keyshop.csms.finance.controller.ProviderFinanceAction");
        REPORTACTIONS = new ArrayList();
        REPORTACTIONS.add("com.keyshop.csms.report.controller.ReportAction");
        BASEINFOACTIONS = new ArrayList();
        BASEINFOACTIONS.add("com.keyshop.csms.baseinfo.controller.BaseInfoAction");
        BASEINFOACTIONS.add("com.keyshop.csms.fittings.controller.FittingsAction");
        BASEINFOACTIONS.add("com.keyshop.csms.fittings.controller.FittingsProviderAction");
        BASEINFOACTIONS.add("com.keyshop.csms.company.controller.EmployeeAction");
        BASEINFOACTIONS.add("com.keyshop.csms.clientserver.controller.MemberAction");
        SYSTEMACTIONS = new ArrayList();
        SYSTEMACTIONS.add("com.keyshop.pub.security.controller.AuthuserLogAction");
        SYSTEMACTIONS.add("com.keyshop.pub.security.controller.UserAction");
        USERROLEACTIONS = new ArrayList();
        USERROLEACTIONS.add(SELLFITTINGSACTIONS);
        USERROLEACTIONS.add(STOCKACTIONS);
        USERROLEACTIONS.add(FINANCEACTIONS);
        USERROLEACTIONS.add(REPORTACTIONS);
        USERROLEACTIONS.add(BASEINFOACTIONS);
        USERROLEACTIONS.add(SYSTEMACTIONS);
    }
}
