Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix v2 problems #4836

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.netscape.certsrv.request.RequestId;
import com.netscape.certsrv.request.RequestNotFoundException;
import com.netscape.certsrv.util.JSONSerializer;
import com.netscape.cms.authentication.DirBasedAuthentication;
import com.netscape.cms.profile.common.Profile;
import com.netscape.cms.servlet.cert.CertRequestInfoFactory;
import com.netscape.cms.servlet.cert.EnrollmentProcessor;
Expand Down Expand Up @@ -227,17 +228,18 @@ private CertRequestInfos submitRequest(
CertRequestInfos ret = new CertRequestInfos();

AuthCredentials credentials = new AuthCredentials();
String uid = data.getAttribute("uid");
String uid = data.getAttribute(DirBasedAuthentication.CRED_UID);
if (uid != null) {
credentials.set("uid", uid);
credentials.set(DirBasedAuthentication.CRED_UID, uid);
}
String password = data.getAttribute("pwd");
String password = data.getAttribute(DirBasedAuthentication.CRED_PWD);
if (password != null) {
credentials.set("pwd", password);
credentials.set(DirBasedAuthentication.CRED_PWD, password);
}
String pin = data.getAttribute(DirBasedAuthentication.CRED_PIN);
if (pin != null) {
credentials.set(DirBasedAuthentication.CRED_PIN, pin);
}

CAEngine engine = CAEngine.getInstance();

HashMap<String, Object> results = null;
if (data.isRenewal()) {
RenewalProcessor processor = new RenewalProcessor("caProfileSubmit", request.getLocale());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.security.Principal;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -163,6 +164,7 @@ public Method getActionMethod(HttpMethod met, String path) {
String keyRegex = key.replace("{}", "([^/]+)");
return reqMethod.matches(keyRegex);
} ).
sorted(Comparator.naturalOrder()).
findFirst().
orElse(null);
return keyPath == null ? null : webActions.get(keyPath);
Expand All @@ -187,7 +189,9 @@ public String getAllowedMethods(String path) {
}
StringBuilder methods = new StringBuilder();
for (String k: keyPaths) {
methods.append(k.substring(0, k.indexOf(":"))).append(", ");
if (methods.indexOf(k) == -1) {
methods.append(k.substring(0, k.indexOf(":"))).append(", ");
}
}
return methods.substring(0, methods.lastIndexOf(","));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.security.Principal;
import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

import javax.servlet.FilterChain;
Expand Down Expand Up @@ -55,8 +54,7 @@
*
* key= <method>:<path>
*
* The method is one of the HTTP method as defined in Java servlet request (e.g. GET, POST, etc.). If the ACL has to be applied for all
* the methods then it can be replaced with the symbol '*'.
* The method is one of the HTTP method as defined in Java servlet request (e.g. GET, POST, etc.).
* The path is the endpoint in the associated servlet where the ACL has to be applied. If there is a REST path param this can be indicated
* with the sequence "{}".
*
Expand Down Expand Up @@ -97,15 +95,16 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
path = req.getPathInfo() != null ? req.getPathInfo().substring(1) : "";
final String aclSearch = method + ":" + path;
if (aclMap!=null) {
Optional<String> aclKey = aclMap.keySet().stream().
String aclKey = aclMap.keySet().stream().
filter( key -> {
String keyRegex = key.replaceFirst("\\*", ".*").replace("{}", "([^/]+)");
String keyRegex = key.replace("{}", "([^/]+)");
return aclSearch.matches(keyRegex);
} ).
sorted(Comparator.reverseOrder()).
findFirst();
if (aclKey.isPresent()) {
acl = aclMap.get(aclKey.get());
findFirst().
orElse(null);
if (aclKey != null) {
acl = aclMap.get(aclKey);
}
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.Comparator;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;

import javax.servlet.FilterChain;
Expand Down Expand Up @@ -47,8 +46,7 @@
*
* key= <method>:<path>
*
* The method is one of the HTTP method as defined in Java servlet request (e.g. GET, POST, etc.). If the ACL has to be applied for all
* the methods then it can be replaced with the symbol '*'.
* The method is one of the HTTP method as defined in Java servlet request (e.g. GET, POST, etc.).
* The path is the endpoint in the associated servlet where the ACL has to be applied. If there is a REST path param this can be indicated
* with the sequence "{}".
*
Expand Down Expand Up @@ -84,15 +82,16 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
path = req.getPathInfo() != null ? req.getPathInfo().substring(1) : "";
final String authMethodSearch = method + ":" + path;
if (authMethodMap!=null) {
Optional<String> autMethodKey = authMethodMap.keySet().stream().
String autMethodKey = authMethodMap.keySet().stream().
filter( key -> {
String keyRegex = key.replaceFirst("\\*", ".*").replace("{}", "([^/]+)");
String keyRegex = key.replace("{}", "([^/]+)");
return authMethodSearch.matches(keyRegex);
} ).
sorted(Comparator.reverseOrder()).
findFirst();
if (autMethodKey.isPresent()) {
authMethod = authMethodMap.get(autMethodKey.get());
sorted(Comparator.naturalOrder()).
findFirst().
orElse(null);
if (autMethodKey != null) {
authMethod = authMethodMap.get(autMethodKey);
}
}
try {
Expand Down
Loading