Skip to content

Commit

Permalink
perf: 优化WebDAV登录失败返回的错误码
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed May 13, 2024
1 parent 2cb3786 commit 101da05
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main/java/com/jmal/clouddisk/webdav/BasicAuthenticator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jmal.clouddisk.webdav;

import cn.hutool.core.util.StrUtil;
import com.jmal.clouddisk.config.FileProperties;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -76,15 +77,13 @@ protected boolean doAuthenticate(Request request, HttpServletResponse response)
credentials = new BasicCredentials(authorizationBC, charset, getTrimCredentials());
String username = credentials.getUsername();
String usernameByUri = MyRealm.getUsernameByUri(fileProperties.getWebDavPrefixPath(), request.getRequestURI());
if (usernameByUri == null || !usernameByUri.equals(username)) {
return false;
}
String password = credentials.getPassword();

Principal principal = context.getRealm().authenticate(username, password);
if (principal != null) {
register(request, response, principal, HttpServletRequest.BASIC_AUTH, username, password);
return true;
if (StrUtil.isNotBlank(usernameByUri) && usernameByUri.equals(username)) {
String password = credentials.getPassword();
Principal principal = context.getRealm().authenticate(username, password);
if (principal != null) {
register(request, response, principal, HttpServletRequest.BASIC_AUTH, username, password);
return true;
}
}
} catch (IllegalArgumentException iae) {
if (log.isDebugEnabled()) {
Expand Down

0 comments on commit 101da05

Please sign in to comment.