-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # README.md # admin-tools-core/README.md # admin-tools-core/pom.xml # admin-tools-dbbrowser/README.md # admin-tools-dbbrowser/pom.xml # admin-tools-demo-core/pom.xml # admin-tools-demo-jar/pom.xml # admin-tools-demo-war/pom.xml # admin-tools-filebrowser/README.md # admin-tools-filebrowser/pom.xml # admin-tools-jminix/README.md # admin-tools-jminix/pom.xml # admin-tools-log4j2/README.md # admin-tools-log4j2/pom.xml # admin-tools-melody/README.md # admin-tools-melody/pom.xml # admin-tools-properties/README.md # admin-tools-properties/pom.xml # admin-tools-quartz/README.md # admin-tools-quartz/pom.xml # admin-tools-security/admin-tools-security-simple/pom.xml # pom.xml
- Loading branch information
Showing
17 changed files
with
1,733 additions
and
1,629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 74 additions & 63 deletions
137
...ilebrowser/src/main/java/de/chandre/admintool/filebrowser/AbstractFileBrowserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,74 @@ | ||
package de.chandre.admintool.filebrowser; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLEncoder; | ||
import java.util.Map; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* | ||
* @author Andre | ||
* | ||
*/ | ||
public abstract class AbstractFileBrowserService { | ||
|
||
@Autowired | ||
private AdminToolFilebrowserConfig config; | ||
|
||
public String encodeURL(String path) throws UnsupportedEncodingException { | ||
return URLEncoder.encode(path, "UTF-8"); | ||
} | ||
|
||
/** | ||
* | ||
* @param path | ||
* @param write | ||
* @param configReadOnly | ||
* @return | ||
* @throws IOException | ||
*/ | ||
public boolean isAllowed(File path, boolean write, boolean configReadOnly) throws IOException { | ||
try { | ||
if (configReadOnly && write) return false; | ||
if (config.isRestrictedBrowsing()) { | ||
if (null != config.getRestrictedPaths() && null != path) { | ||
for (String restricedPath : config.getRestrictedPaths()) { | ||
if(path.getCanonicalPath().startsWith(restricedPath)) { | ||
return config.isRestrictedBrowsingIsWhitelist(); | ||
} | ||
} | ||
} | ||
return !config.isRestrictedBrowsingIsWhitelist(); | ||
} | ||
} catch (IOException e) { | ||
throw new IOException("Could not check if path '" + path.getAbsolutePath() + "' is allowed ", e); | ||
} | ||
return true; | ||
} | ||
|
||
public String getExtension(File file) { | ||
return getExtension(file.getName()); | ||
} | ||
|
||
public String getExtension(String fileName) { | ||
if (fileName.lastIndexOf('.') > -1) { | ||
return (fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length())).toLowerCase(); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
package de.chandre.admintool.filebrowser; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLEncoder; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* | ||
* @author Andre | ||
* | ||
*/ | ||
public abstract class AbstractFileBrowserService { | ||
|
||
@Autowired | ||
private AdminToolFilebrowserConfig config; | ||
|
||
public String encodeURL(String path) throws UnsupportedEncodingException { | ||
return URLEncoder.encode(path, "UTF-8"); | ||
} | ||
|
||
/** | ||
* checks file against configured path restrictions and read-write configuration<br> | ||
* doesn't check file permissions | ||
* | ||
* @param path the file to show/manipulate | ||
* @param write if current action want to change the file | ||
* @param configReadOnly if configuration value read-only is true | ||
* @return true if accessible | ||
* @throws IOException | ||
*/ | ||
public boolean isAllowed(File path, boolean write, boolean configReadOnly) throws IOException { | ||
try { | ||
if (configReadOnly && write) return false; | ||
if (config.isRestrictedBrowsing()) { | ||
if (null != config.getRestrictedPaths() && null != path) { | ||
for (String restricedPath : config.getRestrictedPaths()) { | ||
if(path.getCanonicalPath().startsWith(restricedPath)) { | ||
return config.isRestrictedBrowsingIsWhitelist(); | ||
} | ||
} | ||
} | ||
return !config.isRestrictedBrowsingIsWhitelist(); | ||
} | ||
} catch (IOException e) { | ||
throw new IOException("Could not check if path '" + path.getAbsolutePath() + "' is allowed ", e); | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* returns the file extension by filename separated by last dot | ||
* @param file | ||
* @return null or extension | ||
*/ | ||
public String getExtension(File file) { | ||
return getExtension(file.getName()); | ||
} | ||
|
||
/** | ||
* returns the file extension by filename separated by last dot | ||
* @param fileName | ||
* @return null or extension | ||
*/ | ||
public String getExtension(String fileName) { | ||
if (fileName.lastIndexOf('.') > -1) { | ||
return (fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length())).toLowerCase(); | ||
} | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.