Extract method from NpmLoginAuthenticationSupplier.supply()
@@ -38,13 +38,8 @@ public class NpmLoginAuthenticationSupplier
{
NpmUser npmUser = deserializeNpmUser(request);
- String usernamePattern = "(?:" + NpmLayoutProvider.NPM_USER_PATH + ")(.*)";
- Pattern pattern = Pattern.compile(usernamePattern);
- Matcher urlUsernameMatcher = pattern.matcher(request.getRequestURI());
-
if (!isValidNpmUser(npmUser) ||
- !urlUsernameMatcher.find() ||
- !urlUsernameMatcher.group(1).equals(npmUser.getName()))
+ !usernamesMatch(request.getRequestURI(), npmUser.getName()))
{
throw new BadCredentialsException("invalid.credentials");
}
@@ -87,4 +82,14 @@ public class NpmLoginAuthenticationSupplier
npmUser.getPassword() != null;
}
+ private boolean usernamesMatch(String url, String bodyUsername)
+ {
+ String usernamePattern = "(?:" + NpmLayoutProvider.NPM_USER_PATH + ")(.*)";
+ Pattern pattern = Pattern.compile(usernamePattern);
+ Matcher urlUsernameMatcher = pattern.matcher(url);
+
+ return urlUsernameMatcher.find() &&
+ urlUsernameMatcher.group(1).equals(bodyUsername);
+ }
+
}
