diff --git a/pom.xml b/pom.xml index 4bd5228..8702caf 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.github.zxbu webdav-aliyundriver - 2.1.0 + 2.2.0 webdav Demo project for Spring Boot diff --git a/src/main/java/com/github/zxbu/webdavteambition/config/AliYunDriveProperties.java b/src/main/java/com/github/zxbu/webdavteambition/config/AliYunDriveProperties.java index 311e0bd..410a1a8 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/config/AliYunDriveProperties.java +++ b/src/main/java/com/github/zxbu/webdavteambition/config/AliYunDriveProperties.java @@ -10,6 +10,7 @@ public class AliYunDriveProperties { private String workDir = "/etc/aliyun-driver/"; private String agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"; private String driveId; + private Auth auth; public String getUrl() { return url; @@ -58,4 +59,42 @@ public class AliYunDriveProperties { public void setDriveId(String driveId) { this.driveId = driveId; } + + public Auth getAuth() { + return auth; + } + + public void setAuth(Auth auth) { + this.auth = auth; + } + + public static class Auth { + private Boolean enable = true; + private String userName; + private String password; + + public Boolean getEnable() { + return enable; + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + } } diff --git a/src/main/java/com/github/zxbu/webdavteambition/config/EmbeddedTomcatConfig.java b/src/main/java/com/github/zxbu/webdavteambition/config/EmbeddedTomcatConfig.java index 634c419..56adee2 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/config/EmbeddedTomcatConfig.java +++ b/src/main/java/com/github/zxbu/webdavteambition/config/EmbeddedTomcatConfig.java @@ -1,12 +1,13 @@ package com.github.zxbu.webdavteambition.config; import org.apache.catalina.authenticator.DigestAuthenticator; -import org.apache.catalina.core.StandardContext; import org.apache.catalina.realm.GenericPrincipal; import org.apache.catalina.realm.MessageDigestCredentialHandler; import org.apache.catalina.realm.RealmBase; import org.apache.tomcat.util.descriptor.web.SecurityCollection; import org.apache.tomcat.util.descriptor.web.SecurityConstraint; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; @@ -17,8 +18,12 @@ import java.security.Principal; import java.util.Collections; @Component +@ConditionalOnProperty(prefix = "aliyundrive.auth", name = "enable", matchIfMissing = true) public class EmbeddedTomcatConfig implements WebServerFactoryCustomizer, Ordered { + @Autowired + private AliYunDriveProperties aliYunDriveProperties; + @Override public void customize(ConfigurableServletWebServerFactory factory) { @@ -29,39 +34,31 @@ public class EmbeddedTomcatConfig implements WebServerFactoryCustomizer headerNames = req.getHeaderNames(); - System.out.println(req.getMethod() + " " + req.getRequestURI()); - System.out.println("principal:" + principal); - while (headerNames.hasMoreElements()) { - String s = headerNames.nextElement(); - System.out.println(s + ":" + req.getHeader(s)); - } - - - System.out.println("-----------------------"); - System.out.println(); - aliYunDriverClientService.clearCache(); return new Transaction(principal, req, resp); } @@ -61,7 +49,6 @@ public class AliYunDriverFileSystemStore implements IWebdavStore { @Override public void checkAuthentication(ITransaction transaction) { LOGGER.debug("checkAuthentication"); - HttpServletRequest req = transaction.getRequest(); if (transaction.getPrincipal() == null) { throw new UnauthenticatedException(WebdavStatus.SC_UNAUTHORIZED); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index b7eeb0d..ccfd3fe 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,3 +1,7 @@ -logging.level.net.sf.webdav=trace +#logging.level.net.sf.webdav=trace logging.file.path=/var/log/ logging.file.name=webdav.log + +aliyundrive.auth.enable=true +aliyundrive.auth.user-name=admin +aliyundrive.auth.password=admin