1package org.apache.archiva.webdav.util;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */212223import org.apache.archiva.security.common.ArchivaRoleConstants;
24import org.apache.commons.lang.StringUtils;
2526import java.util.ArrayList;
27import java.util.List;
28import java.util.Locale;
2930/**31 * WebdavMethodUtil32 *33 */34publicclassWebdavMethodUtil35 {
36privatestaticfinal List<String> READ_METHODS;
3738static39 {
40 READ_METHODS = new ArrayList<>( 5 );
41 READ_METHODS.add( "HEAD" );
42 READ_METHODS.add( "GET" );
43 READ_METHODS.add( "PROPFIND" );
44 READ_METHODS.add( "OPTIONS" );
45 READ_METHODS.add( "REPORT" );
46 }
4748publicstatic String getMethodPermission( String method )
49 {
50if ( StringUtils.isBlank( method ) )
51 {
52thrownew IllegalArgumentException( "WebDAV method is empty" );
53 }
54if ( READ_METHODS.contains( method.toUpperCase( Locale.US ) ) )
55 {
56return ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS;
57 }
58elseif ( "DELETE".equals( method.toUpperCase( Locale.US ) ) )
59 {
60return ArchivaRoleConstants.OPERATION_REPOSITORY_DELETE;
61 }
62else63 {
64return ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD;
65 }
66 }
6768publicstaticboolean isReadMethod( String method )
69 {
70if ( StringUtils.isBlank( method ) )
71 {
72thrownew IllegalArgumentException( "WebDAV method is empty" );
73 }
74return READ_METHODS.contains( method.toUpperCase( Locale.US ) );
75 }
76 }