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

Implement v2 of AgentCertRequestService witout VLV and resteasy #4672

Merged
merged 4 commits into from
Feb 19, 2024

Conversation

fmarco76
Copy link
Member

Implement the AgentCertRequestService using a plain servlet and without VLV. The interface is very similar but the start parameter when retrieving the list is not anymore the id to start from but the index to start. Using random indexes it is less useful to start from a specific attribute.

The authN/authZ was performed using interceptor but in a plain servlet these have been converted in filters maintaining the same behaviour.

Since v2 rest API are implemented without JAX-RS support the
interceptors used in current implementation for the authentication have
been converted to filters maintaining very similar functionality.

The only difference is in the audit log because it will not be logged
the access method but the accessed REST URI.
The GET method allow to list the cert requests and retrieve one for
review. The main difference with the old implementation is that the
start parameter is not anymore a request id but an index in the list of
requests.
The POST methods allow all the operation on the certrequest. These are
the same available in the previous implementation and support the same
parameters.
@fmarco76 fmarco76 requested a review from edewata February 16, 2024 14:54
@fmarco76
Copy link
Member Author

@edewata I have done some test enabling the client and they worked as expected. Before to move the client on v2 the start parameter has to be modified (at least the documentation) or, if for some reason the previous approach could be useful even with random ids, make the start an id. We can handle this step in a following commit.

Copy link
Contributor

@edewata edewata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments below. I think generally the code is consistent with the original v1 code. The only issue is the placement of RequestNotFoundException, but the rest are just suggestions for improvements that can be done separately later. Feel free to update & merge. Thanks!

Comment on lines 253 to 257
try {
reqInfos.addEntry(CertRequestInfoFactory.create(request));
} catch (NoSuchMethodException e) {
logger.warn("Error in creating certrequestinfo - no such method: " + e.getMessage(), e);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like CertRequestInfoFactory.create() doesn't actually need to throw anything so we could remove this try-catch block.

return reqInfos;
}

private String createSearchFilter(String requestState, String requestType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method and the one in AgentCertRequestService v1 probably can be consolidated into CertRequestDAO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure CertRequestDAO is needed. This will depend on the other service we have to move. We can decide later.

return filter;
}

private void changeRequestState(RequestId id, HttpServletRequest request, CertReviewResponse data,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be possible to reuse the CertRequestDAO.changeRequestState().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the idea was to not use classes from rest folder so we can deprecate/drop the folder. If needed we can move these utility classes in a separate folder to use for multiple API versions. This is the case if the same method is needed for other service.

import com.netscape.cmscore.authorization.AuthzSubsystem;
import com.netscape.cmscore.logging.Auditor;

public abstract class ACLFilter extends GenericFilter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use HttpFilter instead of GenericFilter?


@Override
public void init() throws ServletException {
super.init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@Override
public void init() throws ServletException {
super.init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

import org.dogtagpki.server.v2.ACLFilter;

@WebFilter(servletNames = "caCertRequest-agent")
public class AgentCertRequestACLFilter extends ACLFilter {
Copy link
Contributor

@edewata edewata Feb 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this means we will need to create quite a few WebFilter classes for all v2 servlets we're going to have, and each filter instance will have its own copy of aclProperties or authProperties. That should work fine but probably redundant.

I think alternatively we could probably define a subclass of each filter for the whole subsystem (e.g. CAACLFilter and CAAuthMethodFilter), then specify all URLs in that subsystem that the filters should apply to, then probably reuse the existing @ACLMapping and @AuthMethodMapping annotations to define the ACL and auth method for each servlet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same approach has a problem. Using jax-rs the interceptor take control after the routing so it is possible to know which method will be used. Here, filters know only which servlet is invoked but not the method so it is not easy to have the same ACL granularity. If we want to define an ACL on each operation then we need to evaluate the path for all the servlet or, alternatively, we need to write a routing utility which works like resteasy. I think we have to evaluate this when we have more servlet implemented.
By the way, we need to have a filter for all the servlet if we want the audit of the event even no ACL are applied so we need a filter for the servlet we have already implemented and which do not require authentication.

Comment on lines 221 to 224
if (info == null) {
// request does not exist
throw new RequestNotFoundException(id);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CertReviewResponseFactory.create() cannot return a null value so this check is not needed.

This code probably should be moved here:

CertReviewResponse req = getRequestData(request, id);
if (req == null) {
    // request does not exist
    throw new RequestNotFoundException(id);
}
out.println(req.toJSON());

@fmarco76 fmarco76 merged commit 2a24da9 into dogtagpki:master Feb 19, 2024
134 checks passed
@fmarco76
Copy link
Member Author

@edewata Thanks! I have updated following your comments and merged.

@fmarco76 fmarco76 deleted the RequestRepositoryFreeVLV branch February 19, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants