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

support intercept specified command handler #2587

Merged
merged 4 commits into from
Mar 29, 2022

Conversation

icodening
Copy link
Contributor

@icodening icodening commented Mar 3, 2022

Describe what this PR does / why we need it

support intercept specified command handler
example, users can extend support for authentication, suitable for "Zero Trust" network architecture

Does this pull request fix one issue?

Fixes #2578

Describe how you did it

wrap command handlers when based on conditions

Describe how to verify it

implement 'com.alibaba.csp.sentinel.command.CommandHandlerInterceptor' interface, and add file 'com.alibaba.csp.sentinel.command.CommandHandlerInterceptor' in META-INF/services dir

Special notes for reviews

example:

public class GetRulesCommandHandlerInterceptor implements CommandHandlerInterceptor {

    @Override
    public boolean shouldIntercept(String commandName) {
        // intercept the handler whose @CommandMapping name is "getRules"
        return "getRules".equals(commandName);
    }

    @Override
    public CommandResponse intercept(CommandRequest commandRequest, CommandRequestExecution commandRequestExecution) {
        // before handle
        CommandResponse response = commandRequestExecution.execute(commandRequest);
        // after handle
        return response;
    }
}

@sczyh30 sczyh30 added kind/enhancement Category issues or prs related to enhancement. to-review To review labels Mar 4, 2022
@sczyh30
Copy link
Member

sczyh30 commented Mar 21, 2022

Any suggestions on this PR? @cdfive @brotherlu-xcq @alibaba/sentinel-committer

Copy link
Collaborator

@brotherlu-xcq brotherlu-xcq left a comment

Choose a reason for hiding this comment

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

@icodening Nice work. but I think we need more discussion about your design. when one handler has more than one interceptors, I think we need execute all the interceptors if no one fail. and could you provide a flow chart to help us to know your idea?

@icodening
Copy link
Contributor Author

@icodening Nice work. but I think we need more discussion about your design. when one handler has more than one interceptors, I think we need execute all the interceptors if no one fail. and could you provide a flow chart to help us to know your idea?

this is a simple flow chart

image

@icodening icodening requested a review from brotherlu-xcq March 24, 2022 12:51
Copy link
Collaborator

@brotherlu-xcq brotherlu-xcq left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@sczyh30 sczyh30 left a comment

Choose a reason for hiding this comment

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

LGTM

@sczyh30 sczyh30 merged commit f6108f3 into alibaba:master Mar 29, 2022
@sczyh30
Copy link
Member

sczyh30 commented Mar 29, 2022

Thanks for contributing and look forward to more!

@sczyh30 sczyh30 removed the to-review To review label Mar 29, 2022
@sczyh30 sczyh30 added this to the 1.8.4 milestone Mar 29, 2022
sczyh30 pushed a commit that referenced this pull request Mar 29, 2022
* support intercept specified command handler
* add unit test and demo
@icodening icodening deleted the intercepting-command-handler branch March 29, 2022 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
3 participants