This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.webdav.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022
023import org.apache.archiva.security.common.ArchivaRoleConstants;
024import org.apache.commons.lang3.StringUtils;
025
026import java.util.ArrayList;
027import java.util.List;
028import java.util.Locale;
029
030/**
031 * WebdavMethodUtil
032 *
033 */
034public class WebdavMethodUtil
035{
036    private static final List<String> READ_METHODS;
037
038    static
039    {
040        READ_METHODS = new ArrayList<>( 5 );
041        READ_METHODS.add( "HEAD" );
042        READ_METHODS.add( "GET" );
043        READ_METHODS.add( "PROPFIND" );
044        READ_METHODS.add( "OPTIONS" );
045        READ_METHODS.add( "REPORT" );
046    }
047
048    public static String getMethodPermission( String method )
049    {
050        if ( StringUtils.isBlank( method ) )
051        {
052            throw new IllegalArgumentException( "WebDAV method is empty" );
053        }
054        if ( READ_METHODS.contains( method.toUpperCase( Locale.US ) ) )
055        {
056            return ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
057        }
058        else if ( "DELETE".equals( method.toUpperCase( Locale.US ) ) )
059        {
060            return ArchivaRoleConstants.OPERATION_REPOSITORY_DELETE;
061        }
062        else
063        {
064            return ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
065        }
066    }
067
068    public static boolean isReadMethod( String method )
069    {
070        if ( StringUtils.isBlank( method ) )
071        {
072            throw new IllegalArgumentException( "WebDAV method is empty" );
073        }
074        return READ_METHODS.contains( method.toUpperCase( Locale.US ) );
075    }
076}