├── .gitignore
├── LICENSE
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── it
│ │ └── ms
│ │ └── filemanager
│ │ ├── FilemanagerApplication.java
│ │ ├── api
│ │ ├── ConfigurerAdapter.java
│ │ ├── handler
│ │ │ ├── AllowedInterceptor.java
│ │ │ ├── LogInterceptor.java
│ │ │ └── RestExceptionHandler.java
│ │ ├── lang
│ │ │ └── FileManagerException.java
│ │ └── rest
│ │ │ ├── ConfigurationRest.java
│ │ │ └── FileManagerRest.java
│ │ ├── configuration
│ │ └── ConfigFileManager.java
│ │ ├── model
│ │ ├── Mode.java
│ │ ├── request
│ │ │ ├── AbstractParams.java
│ │ │ ├── ChangePermission.java
│ │ │ ├── Compress.java
│ │ │ ├── Copy.java
│ │ │ ├── CreateFolder.java
│ │ │ ├── Edit.java
│ │ │ ├── Extract.java
│ │ │ ├── GetContent.java
│ │ │ ├── GetList.java
│ │ │ ├── Move.java
│ │ │ ├── Remove.java
│ │ │ └── Rename.java
│ │ └── response
│ │ │ ├── ErrorResponse.java
│ │ │ ├── Item.java
│ │ │ ├── ResponseModel.java
│ │ │ ├── ResponseStatus.java
│ │ │ └── SuccessfulResponse.java
│ │ ├── service
│ │ ├── FileManager.java
│ │ └── impl
│ │ │ └── FileManagerImpl.java
│ │ └── utils
│ │ └── PermissionUtils.java
└── resources
│ ├── application.properties
│ └── static
│ ├── app
│ └── app.js
│ ├── index.html
│ └── libs
│ ├── angular
│ └── angular.min.js
│ └── bootswatch
│ ├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ ├── glyphicons-halflings-regular.woff
│ └── glyphicons-halflings-regular.woff2
│ └── paper
│ └── bootstrap.min.css
└── test
└── java
└── it
└── ms
└── filemanager
└── FilemanagerApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.ear
17 | *.zip
18 | *.tar.gz
19 | *.rar
20 |
21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22 | hs_err_pid*
23 |
24 | target/
25 | !.mvn/wrapper/maven-wrapper.jar
26 |
27 | ### STS ###
28 | .apt_generated
29 | .classpath
30 | .factorypath
31 | .project
32 | .settings
33 | .springBeans
34 |
35 | ### IntelliJ IDEA ###
36 | .idea
37 | *.iws
38 | *.iml
39 | *.ipr
40 |
41 | ### NetBeans ###
42 | nbproject/private/
43 | build/
44 | nbbuild/
45 | dist/
46 | nbdist/
47 | .nb-gradle/
48 |
49 | .project
50 | .classpath
51 | .settings/
52 | target/
53 | bower_components/
54 |
55 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Marco Serafini
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # angular-filemanager-spring-bridge
2 | This project provides a backend for [angular-filemanager](https://github.com/joni2back/angular-filemanager/) UI written in Java with [Spring-Boot](https://projects.spring.io/spring-boot/).
3 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | it.ms
7 | filemanager
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | filemanager
12 | A bridge for angular-filemanager using Java and Spring
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.9.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 | commons-io
39 | commons-io
40 | 2.3
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-configuration-processor
45 | true
46 |
47 |
48 |
49 |
50 |
51 |
52 | org.springframework.boot
53 | spring-boot-maven-plugin
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/FilemanagerApplication.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class FilemanagerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(FilemanagerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/ConfigurerAdapter.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
7 |
8 | import it.ms.filemanager.api.handler.AllowedInterceptor;
9 | import it.ms.filemanager.api.handler.LogInterceptor;
10 |
11 | @Configuration
12 | public class ConfigurerAdapter extends WebMvcConfigurerAdapter {
13 |
14 | @Autowired
15 | AllowedInterceptor allowedInterceptor;
16 |
17 | @Autowired
18 | LogInterceptor logInterceptor;
19 |
20 | @Override
21 | public void addInterceptors(InterceptorRegistry registry) {
22 | registry.addInterceptor(logInterceptor).addPathPatterns("/action/*");
23 | registry.addInterceptor(allowedInterceptor).addPathPatterns("/action/*");
24 | }
25 | }
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/handler/AllowedInterceptor.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api.handler;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Component;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.method.HandlerMethod;
12 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
13 |
14 | import it.ms.filemanager.configuration.ConfigFileManager;
15 | import it.ms.filemanager.model.Mode;
16 |
17 | @Component
18 | public class AllowedInterceptor extends HandlerInterceptorAdapter {
19 |
20 | private final static Logger LOG = LoggerFactory.getLogger(AllowedInterceptor.class);
21 |
22 | @Autowired
23 | ConfigFileManager configFileManager;
24 |
25 | @Override
26 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
27 | throws Exception {
28 | RequestMapping requestMappingMethod = ((HandlerMethod) handler).getMethod().getAnnotation(RequestMapping.class);
29 | if (requestMappingMethod != null) {
30 | //Response 505
31 | if(!allowedMethod(requestMappingMethod.name())){
32 | LOG.debug("Request {} not allowed, response 405", requestMappingMethod.name());
33 | response.reset();
34 | response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
35 | }
36 | }
37 |
38 | return super.preHandle(request, response, handler);
39 | }
40 |
41 |
42 | private boolean allowedMethod(String name){
43 | try{
44 | Mode action = Mode.valueOf(name);
45 | switch (action) {
46 | case changePermission:
47 | return configFileManager.getAllowedActions().isChangePermissions();
48 | case compress:
49 | return configFileManager.getAllowedActions().isCompress();
50 | case copy:
51 | return configFileManager.getAllowedActions().isCopy();
52 | case createFolder:
53 | return configFileManager.getAllowedActions().isCreateFolder();
54 | case edit:
55 | return configFileManager.getAllowedActions().isEdit();
56 | case extract:
57 | return configFileManager.getAllowedActions().isExtract();
58 | case move:
59 | return configFileManager.getAllowedActions().isMove();
60 | case remove:
61 | return configFileManager.getAllowedActions().isRemove();
62 | case rename:
63 | return configFileManager.getAllowedActions().isRename();
64 | case upload:
65 | return configFileManager.getAllowedActions().isUpload();
66 | default:
67 | //Default allow action true
68 | return true;
69 | }
70 | }catch(IllegalArgumentException ex){
71 | //Default allow action true
72 | return true;
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/handler/LogInterceptor.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api.handler;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletResponse;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.stereotype.Component;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.method.HandlerMethod;
11 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
12 |
13 | @Component
14 | public class LogInterceptor extends HandlerInterceptorAdapter {
15 |
16 | private final static Logger LOG = LoggerFactory.getLogger(LogInterceptor.class);
17 |
18 | @Override
19 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
20 | throws Exception {
21 | RequestMapping requestMappingMethod = ((HandlerMethod)handler).getMethod().getAnnotation(RequestMapping.class);
22 | if(requestMappingMethod != null){
23 | requestMappingMethod.path();
24 | LOG.info("Start Request {} ", request.getServletPath());
25 | request.setAttribute("startTimeExecution", System.currentTimeMillis());
26 | }
27 | return super.preHandle(request, response, handler);
28 | }
29 |
30 | @Override
31 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
32 | throws Exception {
33 |
34 | long time = System.currentTimeMillis() - (long) request.getAttribute("startTimeExecution");
35 | LOG.info("End Request {} in {} ms", request.getServletPath(), time);
36 |
37 | super.afterCompletion(request, response, handler, ex);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/handler/RestExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api.handler;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.web.bind.annotation.ControllerAdvice;
7 | import org.springframework.web.bind.annotation.ExceptionHandler;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 | import org.springframework.web.bind.annotation.ResponseStatus;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | import it.ms.filemanager.api.lang.FileManagerException;
13 | import it.ms.filemanager.model.response.ErrorResponse;
14 |
15 | @ControllerAdvice
16 | @RestController
17 | public class RestExceptionHandler {
18 |
19 | private final static Logger LOG = LoggerFactory.getLogger(RestExceptionHandler.class);
20 |
21 | @ResponseStatus(HttpStatus.OK)
22 | @ExceptionHandler(value = FileManagerException.class)
23 | public @ResponseBody ErrorResponse handleFileManagerException(FileManagerException fileManagerException) {
24 | LOG.error("Error {}", fileManagerException.getMessage(), fileManagerException.getCause());
25 | return new ErrorResponse(fileManagerException.getMessage());
26 | }
27 |
28 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
29 | @ExceptionHandler(value = Throwable.class)
30 | public @ResponseBody String handleThrowable(Throwable throwable) {
31 | LOG.error("Error ", throwable);
32 | return throwable.getMessage();
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/lang/FileManagerException.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api.lang;
2 |
3 | public class FileManagerException extends RuntimeException {
4 |
5 | private static final long serialVersionUID = -83039863770255940L;
6 |
7 | public FileManagerException(String message, Throwable cause) {
8 | super(message, cause);
9 | }
10 |
11 | public FileManagerException(String message) {
12 | super(message);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/rest/ConfigurationRest.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api.rest;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.http.MediaType;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestMethod;
7 | import org.springframework.web.bind.annotation.ResponseBody;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | import it.ms.filemanager.configuration.ConfigFileManager;
11 |
12 | @RestController
13 | @RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
14 | public class ConfigurationRest {
15 |
16 | @Autowired
17 | ConfigFileManager configFileManagerg;
18 |
19 | /**
20 | * Configuratione REST
21 | *
22 | * @return
23 | */
24 | @RequestMapping(path = "/configuration", method = RequestMethod.GET, name = "configuration")
25 | public @ResponseBody ConfigFileManager configuration() {
26 | return this.configFileManagerg;
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/api/rest/FileManagerRest.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.api.rest;
2 |
3 | import java.util.List;
4 |
5 | import javax.servlet.http.HttpServletResponse;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.core.io.FileSystemResource;
9 | import org.springframework.http.MediaType;
10 | import org.springframework.web.bind.annotation.RequestBody;
11 | import org.springframework.web.bind.annotation.RequestMapping;
12 | import org.springframework.web.bind.annotation.RequestMethod;
13 | import org.springframework.web.bind.annotation.RequestParam;
14 | import org.springframework.web.bind.annotation.ResponseBody;
15 | import org.springframework.web.bind.annotation.RestController;
16 | import org.springframework.web.multipart.MultipartFile;
17 |
18 | import it.ms.filemanager.model.request.ChangePermission;
19 | import it.ms.filemanager.model.request.Compress;
20 | import it.ms.filemanager.model.request.Copy;
21 | import it.ms.filemanager.model.request.CreateFolder;
22 | import it.ms.filemanager.model.request.Edit;
23 | import it.ms.filemanager.model.request.Extract;
24 | import it.ms.filemanager.model.request.GetContent;
25 | import it.ms.filemanager.model.request.GetList;
26 | import it.ms.filemanager.model.request.Move;
27 | import it.ms.filemanager.model.request.Remove;
28 | import it.ms.filemanager.model.request.Rename;
29 | import it.ms.filemanager.model.response.Item;
30 | import it.ms.filemanager.model.response.ResponseModel;
31 | import it.ms.filemanager.model.response.ResponseStatus;
32 | import it.ms.filemanager.model.response.SuccessfulResponse;
33 | import it.ms.filemanager.service.FileManager;
34 |
35 | /**
36 | * @see https://github.com/joni2back/angular-filemanager/blob/master/API.md
37 | * @author Marco Serafini
38 | *
39 | */
40 | @RestController
41 | @RequestMapping(path = "action", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
42 | public class FileManagerRest {
43 |
44 | @Autowired
45 | FileManager fileManager;
46 |
47 | /**
48 | * Listing (URL: fileManagerConfig.listUrl, Method: POST)
49 | *
50 | * @return
51 | */
52 | @RequestMapping(path = "/list", method = RequestMethod.POST, name = "list")
53 | public @ResponseBody ResponseModel> list(@RequestBody GetList params) {
54 | return new ResponseModel<>(fileManager.list(params.getPath()));
55 | }
56 |
57 | /**
58 | * Rename (URL: fileManagerConfig.renameUrl, Method: POST)
59 | *
60 | * @return
61 | */
62 | @RequestMapping(path = "/rename", method = RequestMethod.POST, name = "rename")
63 | public @ResponseBody ResponseModel rename(@RequestBody Rename params) {
64 | fileManager.rename(params.getItem(), params.getNewItemPath());
65 | return new SuccessfulResponse();
66 | }
67 |
68 | /**
69 | * Move (URL: fileManagerConfig.moveUrl, Method: POST)
70 | *
71 | * @return
72 | */
73 | @RequestMapping(path = "/move", method = RequestMethod.POST, name = "move")
74 | public @ResponseBody ResponseModel move(@RequestBody Move params) {
75 | fileManager.move(params.getItems(), params.getNewPath());
76 | return new SuccessfulResponse();
77 | }
78 |
79 | /**
80 | * Copy (URL: fileManagerConfig.copyUrl, Method: POST)
81 | *
82 | * @return
83 | */
84 | @RequestMapping(path = "/copy", method = RequestMethod.POST, name = "copy")
85 | public @ResponseBody ResponseModel copy(@RequestBody Copy params) {
86 | fileManager.copy(params.getItems(), params.getNewPath(), params.getSingleFilename());
87 | return new SuccessfulResponse();
88 | }
89 |
90 | /**
91 | * Remove (URL: fileManagerConfig.removeUrl, Method: POST)
92 | *
93 | * @return
94 | */
95 | @RequestMapping(path = "/remove", method = RequestMethod.POST, name = "remove")
96 | public @ResponseBody ResponseModel remove(@RequestBody Remove params) {
97 | fileManager.remove(params.getItems());
98 | return new SuccessfulResponse();
99 | }
100 |
101 | /**
102 | * Edit file (URL: fileManagerConfig.editUrl, Method: POST)
103 | *
104 | * @return
105 | */
106 | @RequestMapping(path = "/edit", method = RequestMethod.POST, name = "edit")
107 | public @ResponseBody ResponseModel edit(@RequestBody Edit params) {
108 | return new ResponseModel<>(new ResponseStatus(fileManager.edit(params.getItem(), params.getContent())));
109 | }
110 |
111 | /**
112 | * Get content of a file (URL: fileManagerConfig.getContentUrl, Method:
113 | * POST)
114 | *
115 | * @return
116 | */
117 | @RequestMapping(path = "/get-content", method = RequestMethod.POST, name = "getContent")
118 | public @ResponseBody ResponseModel getContent(@RequestBody GetContent params) {
119 | return new ResponseModel<>(fileManager.getContent(params.getItem()));
120 | }
121 |
122 | /**
123 | * Create folder (URL: fileManagerConfig.createFolderUrl, Method: POST)
124 | *
125 | * @return
126 | */
127 | @RequestMapping(path = "/create-folder", method = RequestMethod.POST, name = "createFolder")
128 | public @ResponseBody ResponseModel createFolder(@RequestBody CreateFolder params) {
129 | fileManager.createFolder(params.getNewPath());
130 | return new SuccessfulResponse();
131 | }
132 |
133 | /**
134 | * Change Permission (URL: fileManagerConfig.permissionUrl, Method: POST)
135 | *
136 | * @return
137 | */
138 | @RequestMapping(path = "/permission", method = RequestMethod.POST, name = "changePermission")
139 | public @ResponseBody ResponseModel changePermission(@RequestBody ChangePermission params) {
140 | fileManager.changePermission(params.getItems(), params.getPerms(), params.getPermsCode(), params.isRecursive());
141 | return new SuccessfulResponse();
142 | }
143 |
144 | /**
145 | * Compress file (URL: fileManagerConfig.compressUrl, Method: POST)
146 | *
147 | * @return
148 | */
149 | @RequestMapping(path = "/compress", method = RequestMethod.POST, name = "compress")
150 | public @ResponseBody ResponseModel compress(@RequestBody Compress params) {
151 | fileManager.compress(params.getItems(), params.getDestination(), params.getCompressedFilename());
152 | return new SuccessfulResponse();
153 | }
154 |
155 | /**
156 | * Extract file (URL: fileManagerConfig.extractUrl, Method: POST)
157 | *
158 | * @return
159 | */
160 | @RequestMapping(path = "/extract", method = RequestMethod.POST, name = "extract")
161 | public @ResponseBody ResponseModel extract(@RequestBody Extract params) {
162 | fileManager.extract(params.getItem(), params.getFolderName(), params.getDestination());
163 | return new SuccessfulResponse();
164 | }
165 |
166 | /**
167 | * Upload file (URL: fileManagerConfig.uploadUrl, Method: POST,
168 | * Content-Type: multipart/form-data)
169 | *
170 | * @return
171 | *
172 | * @return
173 | */
174 | @RequestMapping(path = "/upload",
175 | consumes= MediaType.MULTIPART_FORM_DATA_VALUE, method = RequestMethod.POST, name = "upload")
176 | public @ResponseBody ResponseModel upload(
177 | @RequestParam(name="file") List files,
178 | @RequestParam(name = "destination", required = true) String destination) {
179 | files.stream().forEach((m) -> fileManager.store(m, destination));
180 | return new SuccessfulResponse();
181 | }
182 |
183 | /**
184 | * Download / Preview file (URL: fileManagerConfig.downloadMultipleUrl,
185 | * Method: GET)
186 | *
187 | * @return
188 | */
189 | @RequestMapping(path = "/download",
190 | method = RequestMethod.GET,
191 | consumes = MediaType.ALL_VALUE,
192 | produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, name = "download")
193 | public FileSystemResource download(HttpServletResponse response, @RequestParam(name = "path", required = true) String path) {
194 | return new FileSystemResource(fileManager.getFile(path));
195 | }
196 |
197 | /**
198 | * Download multiples files in ZIP/TAR (URL:
199 | * fileManagerConfig.downloadFileUrl, Method: GET)
200 | *
201 | * @return
202 | */
203 | @RequestMapping(path = "/download-multiple", method = RequestMethod.GET, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE, name = "downloadMultiple")
204 | public void downloadMultiple(HttpServletResponse response) {
205 | //TODO
206 | }
207 |
208 | }
209 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/configuration/ConfigFileManager.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.configuration;
2 |
3 | import java.io.Serializable;
4 |
5 | import org.springframework.boot.context.properties.ConfigurationProperties;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | @ConfigurationProperties(prefix = "config.filemanager")
10 | public class ConfigFileManager implements Serializable {
11 |
12 | private static final long serialVersionUID = -3772778773231286304L;
13 |
14 | private String repoBasePath;
15 |
16 | private String basePath;
17 |
18 | private boolean onlyFolders;
19 |
20 | private final AllowedAction allowedActions = new AllowedAction();
21 |
22 | /**
23 | * @return the repoBasePath
24 | */
25 | public String getRepoBasePath() {
26 | return repoBasePath;
27 | }
28 |
29 | /**
30 | * @param repoBasePath
31 | * the repoBasePath to set
32 | */
33 | public void setRepoBasePath(String repoBasePath) {
34 | this.repoBasePath = repoBasePath;
35 | }
36 |
37 | /**
38 | * @return the basePath
39 | */
40 | public String getBasePath() {
41 | return basePath;
42 | }
43 |
44 | /**
45 | * @param basePath
46 | * the basePath to set
47 | */
48 | public void setBasePath(String basePath) {
49 | this.basePath = basePath;
50 | }
51 |
52 | /**
53 | * @return the onlyFolders
54 | */
55 | public boolean isOnlyFolders() {
56 | return onlyFolders;
57 | }
58 |
59 | /**
60 | * @param onlyFolders
61 | * the onlyFolders to set
62 | */
63 | public void setOnlyFolders(boolean onlyFolders) {
64 | this.onlyFolders = onlyFolders;
65 | }
66 |
67 | /**
68 | * @return the allowedActions
69 | */
70 | public AllowedAction getAllowedActions() {
71 | return allowedActions;
72 | }
73 |
74 | public static class AllowedAction implements Serializable {
75 |
76 | private static final long serialVersionUID = -3297039605754969184L;
77 |
78 | private boolean upload;
79 |
80 | private boolean rename;
81 |
82 | private boolean move;
83 |
84 | private boolean copy;
85 |
86 | private boolean edit;
87 |
88 | private boolean changePermissions;
89 |
90 | private boolean compress;
91 |
92 | private boolean compressChooseName;
93 |
94 | private boolean extract;
95 |
96 | private boolean download;
97 |
98 | private boolean downloadMultiple;
99 |
100 | private boolean preview;
101 |
102 | private boolean remove;
103 |
104 | private boolean createFolder;
105 |
106 | private boolean pickFiles;
107 |
108 | private boolean pickFolders;
109 |
110 | /**
111 | * @return the upload
112 | */
113 | public boolean isUpload() {
114 | return upload;
115 | }
116 |
117 | /**
118 | * @param upload
119 | * the upload to set
120 | */
121 | public void setUpload(boolean upload) {
122 | this.upload = upload;
123 | }
124 |
125 | /**
126 | * @return the rename
127 | */
128 | public boolean isRename() {
129 | return rename;
130 | }
131 |
132 | /**
133 | * @param rename
134 | * the rename to set
135 | */
136 | public void setRename(boolean rename) {
137 | this.rename = rename;
138 | }
139 |
140 | /**
141 | * @return the move
142 | */
143 | public boolean isMove() {
144 | return move;
145 | }
146 |
147 | /**
148 | * @param move
149 | * the move to set
150 | */
151 | public void setMove(boolean move) {
152 | this.move = move;
153 | }
154 |
155 | /**
156 | * @return the copy
157 | */
158 | public boolean isCopy() {
159 | return copy;
160 | }
161 |
162 | /**
163 | * @param copy
164 | * the copy to set
165 | */
166 | public void setCopy(boolean copy) {
167 | this.copy = copy;
168 | }
169 |
170 | /**
171 | * @return the edit
172 | */
173 | public boolean isEdit() {
174 | return edit;
175 | }
176 |
177 | /**
178 | * @param edit
179 | * the edit to set
180 | */
181 | public void setEdit(boolean edit) {
182 | this.edit = edit;
183 | }
184 |
185 | /**
186 | * @return the changePermission
187 | */
188 | public boolean isChangePermissions() {
189 | return changePermissions;
190 | }
191 |
192 | /**
193 | * @param changePermission
194 | * the changePermission to set
195 | */
196 | public void setChangePermissions(boolean changePermissions) {
197 | this.changePermissions = changePermissions;
198 | }
199 |
200 | /**
201 | * @return the compress
202 | */
203 | public boolean isCompress() {
204 | return compress;
205 | }
206 |
207 | /**
208 | * @param compress
209 | * the compress to set
210 | */
211 | public void setCompress(boolean compress) {
212 | this.compress = compress;
213 | }
214 |
215 | /**
216 | * @return the compressChooseName
217 | */
218 | public boolean isCompressChooseName() {
219 | return compressChooseName;
220 | }
221 |
222 | /**
223 | * @param compressChooseName
224 | * the compressChooseName to set
225 | */
226 | public void setCompressChooseName(boolean compressChooseName) {
227 | this.compressChooseName = compressChooseName;
228 | }
229 |
230 | /**
231 | * @return the extract
232 | */
233 | public boolean isExtract() {
234 | return extract;
235 | }
236 |
237 | /**
238 | * @param extract
239 | * the extract to set
240 | */
241 | public void setExtract(boolean extract) {
242 | this.extract = extract;
243 | }
244 |
245 | /**
246 | * @return the download
247 | */
248 | public boolean isDownload() {
249 | return download;
250 | }
251 |
252 | /**
253 | * @param download
254 | * the download to set
255 | */
256 | public void setDownload(boolean download) {
257 | this.download = download;
258 | }
259 |
260 | /**
261 | * @return the downloadMultiple
262 | */
263 | public boolean isDownloadMultiple() {
264 | return downloadMultiple;
265 | }
266 |
267 | /**
268 | * @param downloadMultiple
269 | * the downloadMultiple to set
270 | */
271 | public void setDownloadMultiple(boolean downloadMultiple) {
272 | this.downloadMultiple = downloadMultiple;
273 | }
274 |
275 | /**
276 | * @return the preview
277 | */
278 | public boolean isPreview() {
279 | return preview;
280 | }
281 |
282 | /**
283 | * @param preview
284 | * the preview to set
285 | */
286 | public void setPreview(boolean preview) {
287 | this.preview = preview;
288 | }
289 |
290 | /**
291 | * @return the remove
292 | */
293 | public boolean isRemove() {
294 | return remove;
295 | }
296 |
297 | /**
298 | * @param remove
299 | * the remove to set
300 | */
301 | public void setRemove(boolean remove) {
302 | this.remove = remove;
303 | }
304 |
305 | /**
306 | * @return the createFolder
307 | */
308 | public boolean isCreateFolder() {
309 | return createFolder;
310 | }
311 |
312 | /**
313 | * @param createFolder
314 | * the createFolder to set
315 | */
316 | public void setCreateFolder(boolean createFolder) {
317 | this.createFolder = createFolder;
318 | }
319 |
320 | /**
321 | * @return the pickFiles
322 | */
323 | public boolean isPickFiles() {
324 | return pickFiles;
325 | }
326 |
327 | /**
328 | * @param pickFiles
329 | * the pickFiles to set
330 | */
331 | public void setPickFiles(boolean pickFiles) {
332 | this.pickFiles = pickFiles;
333 | }
334 |
335 | /**
336 | * @return the pickFolders
337 | */
338 | public boolean isPickFolders() {
339 | return pickFolders;
340 | }
341 |
342 | /**
343 | * @param pickFolders
344 | * the pickFolders to set
345 | */
346 | public void setPickFolders(boolean pickFolders) {
347 | this.pickFolders = pickFolders;
348 | }
349 |
350 | }
351 |
352 | }
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/Mode.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model;
2 |
3 | public enum Mode {
4 | list, rename, move, copy, remove, edit, getContent, createFolder, changePermission, compress, extract, upload
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/AbstractParams.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public abstract class AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = -446741936675338791L;
10 |
11 | protected Mode action;
12 |
13 | /**
14 | * @return the action
15 | */
16 | protected abstract Mode getAction();
17 |
18 | /**
19 | * @param action the action to set
20 | */
21 | public void setAction(Mode action) {
22 | this.action = action;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/ChangePermission.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import it.ms.filemanager.model.Mode;
7 |
8 | public class ChangePermission extends AbstractParams implements Serializable {
9 |
10 | private static final long serialVersionUID = 1138669741294951453L;
11 |
12 | private List items;
13 |
14 | private String perms;
15 |
16 | private String permsCode;
17 |
18 | private boolean recursive;
19 |
20 | public ChangePermission() {
21 | super();
22 | }
23 |
24 | public ChangePermission(List items, String perms, String permsCode, boolean recursive) {
25 | super();
26 | this.items = items;
27 | this.perms = perms;
28 | this.permsCode = permsCode;
29 | this.recursive = recursive;
30 | }
31 |
32 | /**
33 | * @return the items
34 | */
35 | public List getItems() {
36 | return items;
37 | }
38 |
39 | /**
40 | * @param items
41 | * the items to set
42 | */
43 | public void setItems(List items) {
44 | this.items = items;
45 | }
46 |
47 | /**
48 | * @return the perms
49 | */
50 | public String getPerms() {
51 | return perms;
52 | }
53 |
54 | /**
55 | * @param perms
56 | * the perms to set
57 | */
58 | public void setPerms(String perms) {
59 | this.perms = perms;
60 | }
61 |
62 | /**
63 | * @return the permsCode
64 | */
65 | public String getPermsCode() {
66 | return permsCode;
67 | }
68 |
69 | /**
70 | * @param permsCode
71 | * the permsCode to set
72 | */
73 | public void setPermsCode(String permsCode) {
74 | this.permsCode = permsCode;
75 | }
76 |
77 | /**
78 | * @return the recursive
79 | */
80 | public boolean isRecursive() {
81 | return recursive;
82 | }
83 |
84 | /**
85 | * @param recursive
86 | * the recursive to set
87 | */
88 | public void setRecursive(boolean recursive) {
89 | this.recursive = recursive;
90 | }
91 |
92 | @Override
93 | protected Mode getAction() {
94 | return Mode.changePermission;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Compress.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import it.ms.filemanager.model.Mode;
7 |
8 | public class Compress extends AbstractParams implements Serializable {
9 |
10 | private static final long serialVersionUID = 4885864919306125075L;
11 |
12 | private List items;
13 |
14 | private String destination;
15 |
16 | private String compressedFilename;
17 |
18 | public Compress() {
19 | super();
20 | }
21 |
22 | public Compress(List items, String destination, String compressedFilename) {
23 | super();
24 | this.items = items;
25 | this.destination = destination;
26 | this.compressedFilename = compressedFilename;
27 | }
28 |
29 | /**
30 | * @return the items
31 | */
32 | public List getItems() {
33 | return items;
34 | }
35 |
36 | /**
37 | * @param items
38 | * the items to set
39 | */
40 | public void setItems(List items) {
41 | this.items = items;
42 | }
43 |
44 | /**
45 | * @return the destination
46 | */
47 | public String getDestination() {
48 | return destination;
49 | }
50 |
51 | /**
52 | * @param destination
53 | * the destination to set
54 | */
55 | public void setDestination(String destination) {
56 | this.destination = destination;
57 | }
58 |
59 | /**
60 | * @return the compressedFilename
61 | */
62 | public String getCompressedFilename() {
63 | return compressedFilename;
64 | }
65 |
66 | /**
67 | * @param compressedFilename
68 | * the compressedFilename to set
69 | */
70 | public void setCompressedFilename(String compressedFilename) {
71 | this.compressedFilename = compressedFilename;
72 | }
73 |
74 | @Override
75 | public Mode getAction() {
76 | return Mode.compress;
77 | }
78 |
79 | }
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Copy.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import it.ms.filemanager.model.Mode;
7 |
8 | public class Copy extends AbstractParams implements Serializable {
9 |
10 | private static final long serialVersionUID = -3254468874811728423L;
11 |
12 | private List items;
13 |
14 | private String newPath;
15 |
16 | // <-- (only present in single selection copy)
17 | private String singleFilename;
18 |
19 | public Copy() {
20 | super();
21 | }
22 |
23 | public Copy(List items, String newPath, String singleFilename) {
24 | super();
25 | this.items = items;
26 | this.newPath = newPath;
27 | this.singleFilename = singleFilename;
28 | }
29 |
30 | /**
31 | * @return the items
32 | */
33 | public List getItems() {
34 | return items;
35 | }
36 |
37 | /**
38 | * @param items
39 | * the items to set
40 | */
41 | public void setItems(List items) {
42 | this.items = items;
43 | }
44 |
45 | /**
46 | * @return the newPath
47 | */
48 | public String getNewPath() {
49 | return newPath;
50 | }
51 |
52 | /**
53 | * @param newPath
54 | * the newPath to set
55 | */
56 | public void setNewPath(String newPath) {
57 | this.newPath = newPath;
58 | }
59 |
60 | /**
61 | * @return the singleFilename
62 | */
63 | public String getSingleFilename() {
64 | return singleFilename;
65 | }
66 |
67 | /**
68 | * @param singleFilename
69 | * the singleFilename to set
70 | */
71 | public void setSingleFilename(String singleFilename) {
72 | this.singleFilename = singleFilename;
73 | }
74 |
75 | @Override
76 | public Mode getAction() {
77 | return Mode.copy;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/CreateFolder.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public class CreateFolder extends AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = -815504840303622261L;
10 |
11 | private String newPath;
12 |
13 | public CreateFolder() {
14 | super();
15 | }
16 |
17 | public CreateFolder(String newPath) {
18 | super();
19 | this.newPath = newPath;
20 | }
21 |
22 | /**
23 | * @return the newPath
24 | */
25 | public String getNewPath() {
26 | return newPath;
27 | }
28 |
29 | /**
30 | * @param newPath
31 | * the newPath to set
32 | */
33 | public void setNewPath(String newPath) {
34 | this.newPath = newPath;
35 | }
36 |
37 | @Override
38 | public Mode getAction() {
39 | return Mode.createFolder;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Edit.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public class Edit extends AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = -1702131221260325942L;
10 |
11 | private String item;
12 |
13 | private String content;
14 |
15 | public Edit() {
16 | super();
17 | }
18 |
19 | public Edit(String item, String content) {
20 | super();
21 | this.item = item;
22 | this.content = content;
23 | }
24 |
25 | /**
26 | * @return the item
27 | */
28 | public String getItem() {
29 | return item;
30 | }
31 |
32 | /**
33 | * @param item
34 | * the item to set
35 | */
36 | public void setItem(String item) {
37 | this.item = item;
38 | }
39 |
40 | /**
41 | * @return the content
42 | */
43 | public String getContent() {
44 | return content;
45 | }
46 |
47 | /**
48 | * @param content
49 | * the content to set
50 | */
51 | public void setContent(String content) {
52 | this.content = content;
53 | }
54 |
55 | @Override
56 | public Mode getAction() {
57 | return Mode.edit;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Extract.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public class Extract extends AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = 6047997696186615118L;
10 |
11 | private String destination;
12 |
13 | private String item;
14 |
15 | private String folderName;
16 |
17 | public Extract() {
18 | super();
19 | }
20 |
21 | public Extract(String destination, String item, String folderName) {
22 | super();
23 | this.destination = destination;
24 | this.item = item;
25 | this.folderName = folderName;
26 | }
27 |
28 | /**
29 | * @return the destination
30 | */
31 | public String getDestination() {
32 | return destination;
33 | }
34 |
35 | /**
36 | * @param destination
37 | * the destination to set
38 | */
39 | public void setDestination(String destination) {
40 | this.destination = destination;
41 | }
42 |
43 | /**
44 | * @return the item
45 | */
46 | public String getItem() {
47 | return item;
48 | }
49 |
50 | /**
51 | * @param item
52 | * the item to set
53 | */
54 | public void setItem(String item) {
55 | this.item = item;
56 | }
57 |
58 | /**
59 | * @return the folderName
60 | */
61 | public String getFolderName() {
62 | return folderName;
63 | }
64 |
65 | /**
66 | * @param folderName
67 | * the folderName to set
68 | */
69 | public void setFolderName(String folderName) {
70 | this.folderName = folderName;
71 | }
72 |
73 | @Override
74 | public Mode getAction() {
75 | return Mode.extract;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/GetContent.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public class GetContent extends AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = -7053499191183967384L;
10 |
11 | private String item;
12 |
13 | public GetContent() {
14 | super();
15 | }
16 |
17 | public GetContent(String item) {
18 | super();
19 | this.item = item;
20 | }
21 |
22 | /**
23 | * @return the item
24 | */
25 | public String getItem() {
26 | return item;
27 | }
28 |
29 | /**
30 | * @param item
31 | * the item to set
32 | */
33 | public void setItem(String item) {
34 | this.item = item;
35 | }
36 |
37 | @Override
38 | public Mode getAction() {
39 | return Mode.getContent;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/GetList.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public class GetList extends AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = 9027465932521353837L;
10 |
11 | private String path;
12 |
13 | public GetList() {
14 | super();
15 | }
16 |
17 | public GetList(String path) {
18 | super();
19 | this.path = path;
20 | }
21 |
22 | /**
23 | * @return the path
24 | */
25 | public String getPath() {
26 | return path;
27 | }
28 |
29 | /**
30 | * @param path
31 | * the path to set
32 | */
33 | public void setPath(String path) {
34 | this.path = path;
35 | }
36 |
37 | @Override
38 | public Mode getAction() {
39 | return Mode.list;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Move.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import it.ms.filemanager.model.Mode;
7 |
8 | public class Move extends AbstractParams implements Serializable {
9 |
10 | private static final long serialVersionUID = -4952000663281894189L;
11 |
12 | private List items;
13 |
14 | private String newPath;
15 |
16 | public Move() {
17 | super();
18 | }
19 |
20 | /**
21 | * @return the items
22 | */
23 | public List getItems() {
24 | return items;
25 | }
26 |
27 | /**
28 | * @param items
29 | * the items to set
30 | */
31 | public void setItems(List items) {
32 | this.items = items;
33 | }
34 |
35 | /**
36 | * @return the newPath
37 | */
38 | public String getNewPath() {
39 | return newPath;
40 | }
41 |
42 | /**
43 | * @param newPath
44 | * the newPath to set
45 | */
46 | public void setNewPath(String newPath) {
47 | this.newPath = newPath;
48 | }
49 |
50 | @Override
51 | protected Mode getAction() {
52 | return Mode.move;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Remove.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import it.ms.filemanager.model.Mode;
7 |
8 | public class Remove extends AbstractParams implements Serializable {
9 |
10 | private static final long serialVersionUID = 1779561161086574855L;
11 |
12 | private List items;
13 |
14 | public Remove() {
15 | super();
16 | }
17 |
18 | public Remove(List items, String newPath, String singleFilename) {
19 | super();
20 | this.items = items;
21 | }
22 |
23 | /**
24 | * @return the items
25 | */
26 | public List getItems() {
27 | return items;
28 | }
29 |
30 | /**
31 | * @param items
32 | * the items to set
33 | */
34 | public void setItems(List items) {
35 | this.items = items;
36 | }
37 |
38 | /**
39 | * {@inheritDoc}
40 | */
41 | @Override
42 | public Mode getAction() {
43 | return Mode.remove;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/request/Rename.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.request;
2 |
3 | import java.io.Serializable;
4 |
5 | import it.ms.filemanager.model.Mode;
6 |
7 | public class Rename extends AbstractParams implements Serializable {
8 |
9 | private static final long serialVersionUID = 7549792024793358523L;
10 |
11 | private String item;
12 |
13 | private String newItemPath;
14 |
15 | public Rename() {
16 | super();
17 | }
18 |
19 | public Rename(String item, String newItemPath) {
20 | super();
21 | this.item = item;
22 | this.newItemPath = newItemPath;
23 | }
24 |
25 | /**
26 | * @return the item
27 | */
28 | public String getItem() {
29 | return item;
30 | }
31 |
32 | /**
33 | * @param item
34 | * the item to set
35 | */
36 | public void setItem(String item) {
37 | this.item = item;
38 | }
39 |
40 | /**
41 | * @return the newItemPath
42 | */
43 | public String getNewItemPath() {
44 | return newItemPath;
45 | }
46 |
47 | /**
48 | * @param newItemPath
49 | * the newItemPath to set
50 | */
51 | public void setNewItemPath(String newItemPath) {
52 | this.newItemPath = newItemPath;
53 | }
54 |
55 | @Override
56 | public Mode getAction() {
57 | return Mode.rename;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/response/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.response;
2 |
3 | import java.io.Serializable;
4 |
5 | public class ErrorResponse extends ResponseModel implements Serializable {
6 |
7 | private static final long serialVersionUID = -5397343449969224817L;
8 |
9 | public ErrorResponse(String error) {
10 | super(new ResponseStatus(false, error));
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/response/Item.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.response;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | public class Item implements Serializable {
7 |
8 | private static final long serialVersionUID = 6132406001754592219L;
9 |
10 | public enum Type {
11 | dir, file
12 | }
13 |
14 | private String name;
15 |
16 | private String rights;
17 |
18 | private Date date;
19 |
20 | private long size;
21 |
22 | private Type type;
23 |
24 |
25 | public Item() {
26 | super();
27 | }
28 |
29 | /**
30 | *
31 | * @param name
32 | * @param rights
33 | * @param date
34 | * @param size
35 | * @param type
36 | */
37 | public Item(String name, String rights, Date date, long size, Type type) {
38 | super();
39 | this.name = name;
40 | this.rights = rights;
41 | this.date = date;
42 | this.size = size;
43 | this.type = type;
44 | }
45 |
46 | /**
47 | * @return the name
48 | */
49 | public String getName() {
50 | return name;
51 | }
52 |
53 | /**
54 | * @param name
55 | * the name to set
56 | */
57 | public void setName(String name) {
58 | this.name = name;
59 | }
60 |
61 | /**
62 | * @return the rights
63 | */
64 | public String getRights() {
65 | return rights;
66 | }
67 |
68 | /**
69 | * @param rights
70 | * the rights to set
71 | */
72 | public void setRights(String rights) {
73 | this.rights = rights;
74 | }
75 |
76 | /**
77 | * @return the date
78 | */
79 | public Date getDate() {
80 | return date;
81 | }
82 |
83 | /**
84 | * @param date
85 | * the date to set
86 | */
87 | public void setDate(Date date) {
88 | this.date = date;
89 | }
90 |
91 | /**
92 | * @return the size
93 | */
94 | public long getSize() {
95 | return size;
96 | }
97 |
98 | /**
99 | * @param size
100 | * the size to set
101 | */
102 | public void setSize(long size) {
103 | this.size = size;
104 | }
105 |
106 | /**
107 | * @return the type
108 | */
109 | public Type getType() {
110 | return type;
111 | }
112 |
113 | /**
114 | * @param type
115 | * the type to set
116 | */
117 | public void setType(Type type) {
118 | this.type = type;
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/response/ResponseModel.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.response;
2 |
3 | import java.io.Serializable;
4 |
5 | public class ResponseModel implements Serializable {
6 |
7 | private static final long serialVersionUID = 8810017038211492109L;
8 |
9 | private T result;
10 |
11 | public ResponseModel(T result) {
12 | super();
13 | this.result = result;
14 | }
15 |
16 | /**
17 | * @return the result
18 | */
19 | public T getResult() {
20 | return result;
21 | }
22 |
23 | /**
24 | * @param result
25 | * the result to set
26 | */
27 | public void setResult(T result) {
28 | this.result = result;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/response/ResponseStatus.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.response;
2 |
3 | import java.io.Serializable;
4 |
5 | public class ResponseStatus implements Serializable {
6 |
7 | private static final long serialVersionUID = 1194042470517242682L;
8 |
9 | private boolean success;
10 |
11 | private String error;
12 |
13 | public ResponseStatus() {
14 | super();
15 | }
16 |
17 | public ResponseStatus(boolean success) {
18 | super();
19 | this.success = success;
20 | }
21 |
22 | public ResponseStatus(boolean success, String error) {
23 | super();
24 | this.success = success;
25 | this.error = error;
26 | }
27 |
28 | /**
29 | * @return the success
30 | */
31 | public boolean isSuccess() {
32 | return success;
33 | }
34 |
35 | /**
36 | * @param success
37 | * the success to set
38 | */
39 | public void setSuccess(boolean success) {
40 | this.success = success;
41 | }
42 |
43 | /**
44 | * @return the error
45 | */
46 | public String getError() {
47 | return error;
48 | }
49 |
50 | /**
51 | * @param error
52 | * the error to set
53 | */
54 | public void setError(String error) {
55 | this.error = error;
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/model/response/SuccessfulResponse.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.model.response;
2 |
3 | import java.io.Serializable;
4 |
5 | public class SuccessfulResponse extends ResponseModel implements Serializable {
6 |
7 | private static final long serialVersionUID = 662939377237365041L;
8 |
9 | public SuccessfulResponse() {
10 | super(new ResponseStatus(true));
11 | }
12 |
13 | public SuccessfulResponse(String message) {
14 | super(new ResponseStatus(true, message));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/service/FileManager.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.service;
2 |
3 | import java.io.File;
4 | import java.util.List;
5 |
6 | import org.springframework.web.multipart.MultipartFile;
7 |
8 | import it.ms.filemanager.model.response.Item;
9 |
10 | public interface FileManager {
11 |
12 | /**
13 | * List
14 | *
15 | * @param path
16 | * @return
17 | */
18 | List- list(String path);
19 |
20 | /**
21 | * Rename
22 | *
23 | * @param item
24 | * @param newItemPath
25 | * @return
26 | */
27 | boolean rename(String item, String newItemPath);
28 |
29 | /**
30 | * Move
31 | *
32 | * @param items
33 | * @param newItemPath
34 | * @return
35 | */
36 | boolean move(List items, String newItemPath);
37 |
38 | /**
39 | * Copy
40 | *
41 | * @param items
42 | * @param newPath
43 | * @param newFileName
44 | * @return
45 | */
46 | boolean copy(List items, String newPath, String newFileName);
47 |
48 | /**
49 | * Remove
50 | * @param list
51 | * @return
52 | */
53 | int remove(List list);
54 |
55 | /**
56 | * Edit
57 | *
58 | * @param item
59 | * @param content
60 | * @return
61 | */
62 | boolean edit(String item, String content);
63 |
64 | /**
65 | * Get Content
66 | *
67 | * @param string
68 | * @return
69 | */
70 | String getContent(String string);
71 |
72 | /**
73 | * Change Permission
74 | *
75 | * @param items
76 | * @param perms
77 | * @param permsCode
78 | * @param recursive
79 | * @return
80 | */
81 | boolean changePermission(List items, String perms, String permsCode, boolean recursive);
82 |
83 | /**
84 | * Create folder
85 | *
86 | * @param string
87 | * @return
88 | */
89 | boolean createFolder(String string);
90 |
91 | /**
92 | * Compress
93 | *
94 | * @param items
95 | * @param destination
96 | * @param compressedFilename
97 | * @return
98 | */
99 | boolean compress(List items, String destination, String compressedFilename);
100 |
101 | /**
102 | * Extract
103 | *
104 | * @param zip
105 | * @param destination
106 | * @param folderName
107 | * @return
108 | */
109 | boolean extract(String zip, String destination, String folderName);
110 |
111 |
112 | /**
113 | * Store
114 | * @param multipartFile
115 | * @param newItemPath
116 | * @return
117 | */
118 | boolean store(MultipartFile multipartFile, String newItemPath);
119 |
120 | /**
121 | * Get File
122 | * @return
123 | */
124 | File getFile(String path);
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/service/impl/FileManagerImpl.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.service.impl;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.net.URI;
6 | import java.nio.file.DirectoryStream;
7 | import java.nio.file.FileAlreadyExistsException;
8 | import java.nio.file.FileSystem;
9 | import java.nio.file.FileSystems;
10 | import java.nio.file.FileVisitResult;
11 | import java.nio.file.Files;
12 | import java.nio.file.Path;
13 | import java.nio.file.Paths;
14 | import java.nio.file.SimpleFileVisitor;
15 | import java.nio.file.StandardCopyOption;
16 | import java.nio.file.attribute.BasicFileAttributes;
17 | import java.util.ArrayList;
18 | import java.util.Date;
19 | import java.util.HashMap;
20 | import java.util.List;
21 | import java.util.Map;
22 |
23 | import org.apache.commons.io.FileUtils;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 | import org.springframework.beans.factory.annotation.Autowired;
27 | import org.springframework.stereotype.Service;
28 | import org.springframework.util.StringUtils;
29 | import org.springframework.web.multipart.MultipartFile;
30 |
31 | import it.ms.filemanager.api.handler.LogInterceptor;
32 | import it.ms.filemanager.api.lang.FileManagerException;
33 | import it.ms.filemanager.configuration.ConfigFileManager;
34 | import it.ms.filemanager.model.response.Item;
35 | import it.ms.filemanager.model.response.Item.Type;
36 | import it.ms.filemanager.service.FileManager;
37 | import it.ms.filemanager.utils.PermissionUtils;
38 |
39 | @Service
40 | public class FileManagerImpl implements FileManager {
41 |
42 | private final static Logger LOG = LoggerFactory.getLogger(LogInterceptor.class);
43 |
44 | @Autowired
45 | ConfigFileManager configFileManager;
46 |
47 | /**
48 | * {@inheritDoc}}
49 | *
50 | * @return
51 | */
52 | @Override
53 | public List
- list(String path) {
54 |
55 | LOG.debug("List path: Paths.get('{}', '{}'), onlyFolders: {}", configFileManager.getRepoBasePath(), path,
56 | configFileManager.isOnlyFolders());
57 |
58 | List
- items = new ArrayList<>();
59 |
60 | try (DirectoryStream directoryStream = Files
61 | .newDirectoryStream(Paths.get(configFileManager.getRepoBasePath(), path))) {
62 | for (Path p : directoryStream) {
63 | BasicFileAttributes attrs = Files.readAttributes(p, BasicFileAttributes.class);
64 | if (configFileManager.isOnlyFolders() && !attrs.isDirectory()) {
65 | continue;
66 | }
67 | Item item = new Item();
68 | item.setName(p.getFileName().toString());
69 | item.setRights(PermissionUtils.getPermissions(p));
70 | item.setDate(new Date(attrs.lastModifiedTime().toMillis()));
71 | item.setSize(attrs.size());
72 | item.setType(attrs.isDirectory() ? Type.dir : Type.file);
73 | items.add(item);
74 | }
75 |
76 | } catch (IOException e) {
77 | throw new FileManagerException("Expection in list action", e);
78 | }
79 |
80 | return items;
81 | }
82 |
83 | @Override
84 | public boolean rename(String itemPath, String newItemPath) {
85 |
86 | try {
87 | LOG.debug("rename from: {} to: {}", itemPath, newItemPath);
88 | File srcFile = new File(configFileManager.getRepoBasePath(), itemPath);
89 | File destFile = new File(configFileManager.getRepoBasePath(), newItemPath);
90 | if (srcFile.isFile()) {
91 | FileUtils.moveFile(srcFile, destFile);
92 | } else {
93 | FileUtils.moveDirectory(srcFile, destFile);
94 | }
95 | return true;
96 | } catch (IOException e) {
97 | throw new FileManagerException("Expection in rename action", e);
98 | }
99 | }
100 |
101 | @Override
102 | public boolean move(List items, String newItemPath) {
103 | try {
104 | Path newpath = Paths.get(configFileManager.getRepoBasePath(), newItemPath);
105 | for (String item : items) {
106 | Path path = Paths.get(configFileManager.getRepoBasePath(), item);
107 | Path mpath = newpath.resolve(path.getFileName());
108 | LOG.debug("mv {} to {} exists? {}", path, mpath, Files.exists(mpath));
109 | if (Files.exists(mpath)) {
110 | throw new FileManagerException("File already exist");
111 | }
112 | Files.move(path, mpath, StandardCopyOption.REPLACE_EXISTING);
113 | }
114 | return true;
115 | } catch (IOException e) {
116 | throw new FileManagerException("Error in move ation", e);
117 | }
118 | }
119 |
120 | @Override
121 | public boolean copy(List items, String newPath, String newFileName) {
122 | try {
123 | Path newpath = Paths.get(configFileManager.getRepoBasePath(), newPath);
124 | for (String item : items) {
125 | Path path = newFileName == null ? Paths.get(configFileManager.getRepoBasePath(), item)
126 | : Paths.get(".", newFileName);
127 | Path mpath = newpath.resolve(path.getFileName());
128 | LOG.debug("mv {} to {} exists? {}", path, mpath, Files.exists(mpath));
129 | if (Files.exists(mpath)) {
130 | throw new FileManagerException("File already exist");
131 | }
132 | path = Paths.get(configFileManager.getRepoBasePath(), item);
133 | mpath = newpath
134 | .resolve(newFileName == null ? path.getFileName() : Paths.get(".", newFileName).getFileName());
135 | Files.copy(path, mpath, StandardCopyOption.REPLACE_EXISTING);
136 | }
137 | return true;
138 | } catch (IOException e) {
139 | throw new FileManagerException("Error in copy ation", e);
140 | }
141 | }
142 |
143 | @Override
144 | public int remove(List items) {
145 | int countRemove = 0;
146 | for (String item : items) {
147 | Path path = Paths.get(configFileManager.getRepoBasePath(), item);
148 | if (FileUtils.deleteQuietly(path.toFile())) {
149 | LOG.debug("remove {}", path);
150 | countRemove++;
151 | }
152 | }
153 | if (countRemove == 0) {
154 | throw new FileManagerException("No item remove");
155 | } else {
156 | return countRemove;
157 | }
158 | }
159 |
160 | @Override
161 | public boolean edit(String path, String content) {
162 | try {
163 | LOG.debug("editFile path: {}", path);
164 | File srcFile = new File(configFileManager.getRepoBasePath(), path);
165 | FileUtils.writeStringToFile(srcFile, content);
166 | return true;
167 | } catch (IOException ex) {
168 | throw new FileManagerException("Error in edit action", ex);
169 | }
170 | }
171 |
172 | @Override
173 | public String getContent(String item) {
174 | try {
175 | return FileUtils.readFileToString(Paths.get(configFileManager.getRepoBasePath(), item).toFile());
176 | } catch (IOException ex) {
177 | throw new FileManagerException("Error in get content action", ex);
178 | }
179 | }
180 |
181 | @Override
182 | public boolean changePermission(List items, String perms, String permsCode, boolean recursive) {
183 | try {
184 | for (String item : items) {
185 | LOG.debug("changepermissions path: {} perms: {} permsCode: {} recursive: {}", item, perms, permsCode,
186 | recursive);
187 | File f = Paths.get(configFileManager.getRepoBasePath(), item).toFile();
188 | PermissionUtils.setPermissions(f, perms, recursive);
189 | }
190 | return true;
191 | } catch (IOException ex) {
192 | throw new FileManagerException("Error in changePermission action", ex);
193 | }
194 | }
195 |
196 | @Override
197 | public boolean createFolder(String newPath) {
198 | try {
199 | Path path = Paths.get(configFileManager.getRepoBasePath(), newPath);
200 | LOG.debug("createFolder path: {} name: {}", path);
201 | Files.createDirectories(path);
202 | return true;
203 | } catch (FileAlreadyExistsException ex) {
204 | throw new FileManagerException("Error in create-folder action, folder already exists", ex);
205 | } catch (IOException e) {
206 | throw new FileManagerException("Error in create-folder action", e);
207 | }
208 | }
209 |
210 | @Override
211 | public boolean compress(List items, String destination, String compressedFilename) {
212 | try {
213 | final Path dest = Paths.get(configFileManager.getRepoBasePath(), destination);
214 | Path zip = dest.resolve(compressedFilename);
215 | if (Files.exists(zip)) {
216 | throw new FileManagerException("Error in compress action, zip already exists");
217 | }
218 | Map env = new HashMap<>();
219 | env.put("create", "true");
220 | boolean zipped = false;
221 | try (FileSystem zipfs = FileSystems.newFileSystem(URI.create("jar:" + zip.toUri().toString()), env)) {
222 | for (String item : items) {
223 | Path realPath = Paths.get(configFileManager.getRepoBasePath(), item);
224 | if (Files.isDirectory(realPath)) {
225 | Files.walkFileTree(Paths.get(configFileManager.getRepoBasePath(), item),
226 | new SimpleFileVisitor() {
227 | @Override
228 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
229 | throws IOException {
230 | Files.createDirectories(
231 | zipfs.getPath(dir.toString().substring(dest.toString().length())));
232 | return FileVisitResult.CONTINUE;
233 | }
234 |
235 | @Override
236 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
237 | throws IOException {
238 | Path pathInZipFile = zipfs
239 | .getPath(file.toString().substring(dest.toString().length()));
240 | LOG.debug("compress: '{}'", pathInZipFile);
241 | Files.copy(file, pathInZipFile, StandardCopyOption.REPLACE_EXISTING);
242 | return FileVisitResult.CONTINUE;
243 | }
244 | });
245 | } else {
246 | Path pathInZipFile = zipfs.getPath("/", realPath.toString()
247 | .substring(configFileManager.getRepoBasePath().length() + destination.length()));
248 | Path pathInZipFolder = pathInZipFile.getParent();
249 | if (!Files.isDirectory(pathInZipFolder)) {
250 | Files.createDirectories(pathInZipFolder);
251 | }
252 | LOG.debug("compress: '{}]", pathInZipFile);
253 | Files.copy(realPath, pathInZipFile, StandardCopyOption.REPLACE_EXISTING);
254 | }
255 | }
256 | zipped = true;
257 | } finally {
258 | if (!zipped) {
259 | Files.deleteIfExists(zip);
260 | }
261 | }
262 | return true;
263 | } catch (IOException ex) {
264 | throw new FileManagerException("Error in compress action, folder already exists", ex);
265 | }
266 | }
267 |
268 | @Override
269 | public boolean extract(String zip, String destination, String folderName) {
270 | boolean genFolder = false;
271 | Path dest = Paths.get(configFileManager.getRepoBasePath(), destination);
272 | final Path folder = dest.resolve(folderName);
273 | try {
274 | if (!Files.isDirectory(folder)) {
275 | genFolder = true;
276 | Files.createDirectories(folder);
277 | }
278 | Map env = new HashMap<>();
279 | env.put("create", "false");
280 | try (FileSystem zipfs = FileSystems.newFileSystem(
281 | URI.create("jar:" + Paths.get(configFileManager.getRepoBasePath(), zip).toUri()), env)) {
282 | Files.walkFileTree(zipfs.getPath("/"), new SimpleFileVisitor() {
283 |
284 | @Override
285 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
286 | if (file.getNameCount() > 0) {
287 | Path dest = folder.resolve(
288 | file.getNameCount() < 1 ? "" : file.subpath(0, file.getNameCount()).toString());
289 | LOG.debug("extract {} to {}", file, dest);
290 | try {
291 | Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING);
292 | } catch (Exception ex) {
293 | LOG.error(ex.getMessage(), ex);
294 | }
295 | }
296 | return FileVisitResult.CONTINUE;
297 | }
298 |
299 | @Override
300 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
301 | Path subFolder = folder
302 | .resolve(dir.getNameCount() < 1 ? "" : dir.subpath(0, dir.getNameCount()).toString());
303 | if (!Files.exists(subFolder)) {
304 | Files.createDirectories(subFolder);
305 | }
306 | return FileVisitResult.CONTINUE;
307 | }
308 |
309 | });
310 | }
311 | return true;
312 | } catch (IOException ex) {
313 | if (genFolder) {
314 | FileUtils.deleteQuietly(folder.toFile());
315 | }
316 | throw new FileManagerException("Error in compress action, folder already exists", ex);
317 | }
318 | }
319 |
320 | @Override
321 | public boolean store(MultipartFile multipartFile, String newItemPath) {
322 | String filename = StringUtils.cleanPath(multipartFile.getOriginalFilename());
323 | try {
324 | if (multipartFile.isEmpty()) {
325 | throw new FileManagerException("Failed to store empty file " + filename);
326 | }
327 | if (filename.contains("..")) {
328 | // This is a security check
329 | throw new FileManagerException(
330 | "Cannot store file with relative path outside current directory "
331 | + filename);
332 | }
333 | Path newpath = Paths.get(configFileManager.getRepoBasePath(), newItemPath);
334 | Files.copy(multipartFile.getInputStream(), newpath.resolve(filename), StandardCopyOption.REPLACE_EXISTING);
335 | return true;
336 | } catch (IOException e) {
337 | throw new FileManagerException("Failed to store file " + filename, e);
338 | }
339 | }
340 |
341 | @Override
342 | public File getFile(String pathFile) {
343 | Path path = Paths.get(configFileManager.getRepoBasePath(), pathFile);
344 | return path.toFile();
345 | }
346 |
347 | }
348 |
--------------------------------------------------------------------------------
/src/main/java/it/ms/filemanager/utils/PermissionUtils.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager.utils;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.nio.file.Files;
6 | import java.nio.file.Path;
7 | import java.nio.file.attribute.PosixFileAttributeView;
8 | import java.nio.file.attribute.PosixFileAttributes;
9 | import java.nio.file.attribute.PosixFilePermission;
10 | import java.nio.file.attribute.PosixFilePermissions;
11 | import java.util.Set;
12 |
13 | public class PermissionUtils {
14 |
15 | public static String getPermissions(Path path) throws IOException {
16 | PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class);
17 | if (fileAttributeView != null) {
18 | PosixFileAttributes readAttributes = fileAttributeView.readAttributes();
19 | Set permissions = readAttributes.permissions();
20 | return PosixFilePermissions.toString(permissions);
21 | }
22 | return "";
23 |
24 | }
25 |
26 | public static String setPermissions(File file, String permsCode, boolean recursive) throws IOException {
27 | PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(file.toPath(),
28 | PosixFileAttributeView.class);
29 | fileAttributeView.setPermissions(PosixFilePermissions.fromString(permsCode));
30 | if (file.isDirectory() && recursive && file.listFiles() != null) {
31 | for (File f : file.listFiles()) {
32 | setPermissions(f, permsCode, recursive);
33 | }
34 | }
35 | return permsCode;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #############################################
2 | ########### FILEMANAGER CONFIG ##############
3 | #############################################
4 | config.filemanager.repoBasePath=C:\\u01
5 | config.filemanager.onlyFolders=false
6 |
7 | #ACTION
8 | config.filemanager.allowedActions.upload=true
9 | config.filemanager.allowedActions.rename=true
10 | config.filemanager.allowedActions.move=true
11 | config.filemanager.allowedActions.copy=true
12 | config.filemanager.allowedActions.edit=true
13 | config.filemanager.allowedActions.changePermissions=true
14 | config.filemanager.allowedActions.compress=true
15 | config.filemanager.allowedActions.extract=true
16 | config.filemanager.allowedActions.download=true
17 | config.filemanager.allowedActions.downloadMultiple=true
18 | config.filemanager.allowedActions.remove=true
19 | config.filemanager.allowedActions.createFolder=true
20 | #UI
21 | config.filemanager.allowedActions.compressChooseName=true
22 | config.filemanager.allowedActions.preview=true
23 | config.filemanager.allowedActions.pickFiles=true
24 | config.filemanager.allowedActions.pickFolders=true
--------------------------------------------------------------------------------
/src/main/resources/static/app/app.js:
--------------------------------------------------------------------------------
1 | (function(angular) {
2 |
3 | var app = angular.module("myApp", [ "FileManagerApp" ]);
4 |
5 | var fileManagerConfigProvider = null;
6 |
7 | app.config(["fileManagerConfigProvider", function (config) {
8 | fileManagerConfigProvider = config;
9 | }]);
10 |
11 | app.run([ "$rootScope", "$http", "apiHandler", "$q", "Upload", function($rootScope, $http, apiHandler, $q, Upload) {
12 | $rootScope.isLoading = true;
13 | $http.get("/configuration").then(function(response){
14 | var defaults = fileManagerConfigProvider.$get();
15 | fileManagerConfigProvider.set({
16 | appName : 'Spring-filemanager',
17 | listUrl : 'action/list',
18 | uploadUrl : 'action/upload',
19 | renameUrl : 'action/rename',
20 | copyUrl : 'action/copy',
21 | moveUrl : 'action/move',
22 | removeUrl : 'action/remove',
23 | editUrl : 'action/edit',
24 | getContentUrl : 'action/get-content',
25 | createFolderUrl : 'action/create-folder',
26 | downloadFileUrl : 'action/download',
27 | downloadMultipleUrl : 'action/download-multiple',
28 | compressUrl : 'action/compress',
29 | extractUrl : 'action/extract',
30 | permissionsUrl : 'action/permission',
31 | basePath : '/',
32 | allowedActions : response.data.allowedActions
33 | });
34 | }).finally(function(){
35 | $rootScope.isLoading = false;
36 | });
37 |
38 |
39 | apiHandler.prototype.upload = function(apiUrl, destination, files) {
40 | var self = this;
41 | var deferred = $q.defer();
42 | self.inprocess = true;
43 | self.progress = 0;
44 | self.error = '';
45 |
46 | if (files && files.length) {
47 | Upload.upload({
48 | url: apiUrl,
49 | data: {
50 | destination: destination,
51 | file: files
52 | },
53 | arrayKey: '' //Fix to work with Spring MVC Rest,
54 | }).then(function (data) {
55 | self.deferredHandler(data.data, deferred, data.status);
56 | }, function (data) {
57 | self.deferredHandler(data.data, deferred, data.status, 'Unknown error uploading files');
58 | }, function (evt) {
59 | self.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total)) - 1;
60 | })['finally'](function() {
61 | self.inprocess = false;
62 | self.progress = 0;
63 | });
64 | }
65 |
66 | return deferred.promise;
67 | };
68 | }]);
69 |
70 |
71 |
72 | }(angular));
--------------------------------------------------------------------------------
/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoserafini2/angular-filemanager-spring-bridge/a5d70a4c32f207f29fb7833a7255039479d751cc/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoserafini2/angular-filemanager-spring-bridge/a5d70a4c32f207f29fb7833a7255039479d751cc/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoserafini2/angular-filemanager-spring-bridge/a5d70a4c32f207f29fb7833a7255039479d751cc/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/marcoserafini2/angular-filemanager-spring-bridge/a5d70a4c32f207f29fb7833a7255039479d751cc/src/main/resources/static/libs/bootswatch/fonts/glyphicons-halflings-regular.woff2
--------------------------------------------------------------------------------
/src/test/java/it/ms/filemanager/FilemanagerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package it.ms.filemanager;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class FilemanagerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------