Changeset 25591 for main


Ignore:
Timestamp:
2012-05-14T14:28:38+12:00 (12 years ago)
Author:
sjm84
Message:

Some tidying up as well as adding system commands

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/URLFilter.java

    r25536 r25591  
    3131    //Restricted URLs
    3232    protected static final String SITECONFIG_URL = "sites/[^/]+/siteConfig.xml";
    33 
    3433    protected static final ArrayList<String> _restrictedURLs;
    3534    static
     
    4039    }
    4140
     41    //Constants
     42    protected static final String DOCUMENT_PATH = "document";
     43    protected static final String COLLECTION_PATH = "collection";
     44    protected static final String PAGE_PATH = "page";
     45    protected static final String SYSTEM_PATH = "system";
     46
     47    protected static final String METADATA_RETRIEVAL_SERVICE = "DocumentMetadataRetrieve";
     48    protected static final String ASSOCIATED_FILE_PATH = "/index/assoc/";
     49    protected static final String COLLECTION_FILE_PATH = "/collect/";
     50   
     51    protected static final String SYSTEM_SUBACTION_CONFIGURE = "configure";
     52    protected static final String SYSTEM_SUBACTION_RECONFIGURE = "reconfigure";
     53    protected static final String SYSTEM_SUBACTION_ACTIVATE = "activate";
     54    protected static final String SYSTEM_SUBACTION_DEACTIVATE = "deactivate";
     55
    4256    public void init(FilterConfig filterConfig) throws ServletException
    4357    {
     
    6579            }
    6680
    67             if (url.contains("/index/assoc/"))
     81            //If the user is trying to access a collection file we need to run a security check
     82            if (url.contains(ASSOCIATED_FILE_PATH))
    6883            {
    6984                String dir = null;
    70                 int dirStart = url.indexOf("/index/assoc/") + "/index/assoc/".length();
     85                int dirStart = url.indexOf(ASSOCIATED_FILE_PATH) + ASSOCIATED_FILE_PATH.length();
    7186                int dirEnd = -1;
    7287                if (dirStart < url.length() && url.indexOf("/", dirStart) != -1)
     
    8499
    85100                String collection = null;
    86                 int colStart = url.indexOf("/collect/") + "/collect/".length();
     101                int colStart = url.indexOf(COLLECTION_FILE_PATH) + COLLECTION_FILE_PATH.length();
    87102                int colEnd = -1;
    88103                if (colStart < url.length() && url.indexOf("/", colStart) != -1)
     
    114129
    115130                Element metaMessage = gsDoc.createElement(GSXML.MESSAGE_ELEM);
    116                 Element metaRequest = GSXML.createBasicRequest(gsDoc, GSXML.REQUEST_TYPE_PROCESS, collection + "/DocumentMetadataRetrieve", new UserContext());
     131                Element metaRequest = GSXML.createBasicRequest(gsDoc, GSXML.REQUEST_TYPE_PROCESS, collection + "/" + METADATA_RETRIEVAL_SERVICE, new UserContext());
    117132                metaMessage.appendChild(metaRequest);
    118133
     
    179194            else
    180195            {
     196                //If we have a jsessionid on the end of our URL we want to ignore it
    181197                int index;
    182                 if((index = url.indexOf(";jsessionid")) != -1)
     198                if ((index = url.indexOf(";jsessionid")) != -1)
    183199                {
    184200                    url = url.substring(0, index);
     
    191207
    192208                    //COLLECTION
    193                     if (segments[i].equals("collection") && (i + 1) < segments.length)
     209                    if (segments[i].equals(COLLECTION_PATH) && (i + 1) < segments.length)
    194210                    {
    195211                        gRequest.setParameter(GSParams.COLLECTION, segments[i + 1]);
    196212                    }
    197213                    //DOCUMENT
    198                     else if (segments[i].equals("document") && (i + 1) < segments.length)
     214                    else if (segments[i].equals(DOCUMENT_PATH) && (i + 1) < segments.length)
    199215                    {
    200216                        gRequest.setParameter(GSParams.DOCUMENT, segments[i + 1]);
     
    204220                    }
    205221                    //PAGE
    206                     else if (segments[i].equals("page") && (i + 1) < segments.length)
     222                    else if (segments[i].equals(PAGE_PATH) && (i + 1) < segments.length)
    207223                    {
    208224                        gRequest.setParameter(GSParams.SUBACTION, segments[i + 1]);
     
    211227                        defaultParamValues = new String[] { "p" };
    212228                    }
     229                    //SYSTEM
     230                    else if (segments[i].equals(SYSTEM_PATH) && (i + 1) < segments.length)
     231                    {
     232                        String sa = segments[i + 1];
     233                        if (sa.equals(SYSTEM_SUBACTION_CONFIGURE) || sa.equals(SYSTEM_SUBACTION_RECONFIGURE))
     234                        {
     235                            sa = "c";
     236                        }
     237                        else if (sa.equals(SYSTEM_SUBACTION_ACTIVATE))
     238                        {
     239                            sa = "a";
     240                        }
     241                        else if (sa.equals(SYSTEM_SUBACTION_DEACTIVATE))
     242                        {
     243                            sa = "d";
     244                        }
     245                       
     246                        if (sa.equals("c") && (i + 2) < segments.length)
     247                        {
     248                            gRequest.setParameter(GSParams.SYSTEM_CLUSTER, segments[i + 2]);
     249                        }
     250                       
     251                        if (sa.equals("a") && (i + 2) < segments.length)
     252                        {
     253                            gRequest.setParameter(GSParams.SYSTEM_MODULE_TYPE, "collection");
     254                            gRequest.setParameter(GSParams.SYSTEM_MODULE_NAME, segments[i + 2]);
     255                        }
     256                       
     257                        if (sa.equals("d") && (i + 2) < segments.length)
     258                        {
     259                            gRequest.setParameter(GSParams.SYSTEM_CLUSTER, segments[i + 2]);
     260                        }
     261
     262                        gRequest.setParameter(GSParams.SUBACTION, sa);
     263
     264                        additionalParameters = new String[] { GSParams.ACTION };
     265                        defaultParamValues = new String[] { "s" };
     266                    }
    213267                    //ADMIN
    214268                    else if (segments[i].equals("admin") && (i + 1) < segments.length)
     
    253307                            serviceName = segments[i + 1];
    254308                            gRequest.setParameter("s", serviceName);
    255                            
     309
    256310                            additionalParameters = new String[] { GSParams.ACTION, GSParams.SUBACTION, GSParams.REQUEST_TYPE };
    257311                            defaultParamValues = new String[] { "q", "", "d" };
    258312                        }
    259                         if((i + 2) < segments.length)
    260                         {
    261                             System.err.println("HUH??");
     313                        if ((i + 2) < segments.length)
     314                        {
    262315                            if (serviceName.equals("TextQuery") || serviceName.equals("RawQuery"))
    263316                            {
Note: See TracChangeset for help on using the changeset viewer.