-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Parse authParamsString on plugin side #721
Parse authParamsString on plugin side #721
Conversation
*/ | ||
default void configure(String authParams) { | ||
Map<String, String> authParamsMap = new HashMap<>(); | ||
Logger LOG = LoggerFactory.getLogger(Authentication.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger should be declared as private static final
at the class scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final
can not be declared at the class scope because Authentication.java is an interface.
https://stackoverflow.com/questions/31452118/why-private-static-field-is-not-allowed-in-java-8-interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, though instead of having the parsing logic here in the interface, we could have it in a different place and then call it. eg:
default void configure(String authParamsStr) {
Map<String, String> authParams = AuthenticationUtil.configureFromJsonString(authParamsStr);
configure(authParams);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to have the two lines here? If we move parsing logic to somewhere else, we can deprecate the old interface and will have this only one universal configure interface eventually, which is more beautiful API I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the intention for using default
method was to avoid breaking the Authentication
API. I think we could as well break it right now, since I'm not aware of any 3rd party Authentication implementations at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so, but probably we can achieve the both, keeping compatibility and having one configure (and deprecated old one) if we introduce an interface I wrote on the issue.
authParamsMap = jsonMapper.readValue(authParams, new TypeReference<HashMap<String, String>>() {}); | ||
} catch (JsonParseException e) { | ||
// If authParams is not JSON, separate by “:” and “,” for compatibility | ||
LOG.warn("Authentication config parameter should be JSON: {}", e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to support both comma separated and Json, we shouldn't print a warning here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that comma separated should be deleted in the future.
What do you think that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case the deprecation should be at the interface level, not by having WARN message in log.
if (isNotBlank(authPluginClassName)) { | ||
Class<?> authClass = Class.forName(authPluginClassName); | ||
Authentication auth = (Authentication) authClass.newInstance(); | ||
auth.configure(authParamsString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel configure(Map<String, String> authParams)
is generic-enough and parsing/preparation of authParams-map can be done by AuthenticationFactory
because in future, if we decide yaml format then we can adapt it without changing interface-definition.
a quick thought on implementation:
Rather adding void configure(String authParams)
method in Authentication.java
and doing parsing, instead can we do parsing here in AuthenticationFactory
?
- First try to parse given auth-param into json and prepare
Map<String,String>
from json and call configure(map)
Map<String, String> authParamsMap = jsonMapper.readValue(authParamsString, new TypeReference<HashMap<String, String>>() {});
- If fails then try to parse in existing way with
:
and;
delimiters, and prepare config-map
any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rdhabalia's suggestion is good enough since what we want to do here is to allow String containing ":" or "," (such as URL) as a parameter.
Introducing new interface sounds nice, however, I think we should do that when we really need plugin-specific parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the new interface may be YAGNI. However, I still don't understand why you guys want limitations.
- Maybe
Map<String, String>
is enough, maybe not. Who knows? - colon-comma, JSON, YAML... What's next? Can we auto-detect all formats?
- When we finally agreed on having new interface, is it still easy to migrate? How many plugins exists?
What will we lose instead of freedom if we introduce the new one now?
In my opinion, we should maximize API capability and do smart things on top of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will we lose instead of freedom if we introduce the new one now?
Sure, I will be fine with new api as well. 👍
ed1ef85
to
8aa7e91
Compare
I added
|
@tkb77 Can you explain why we should parse JSON in Map<String, String> authParams = AuthenticationUtil.configureFromJsonString(authParamsStr); I don't see pros keeping the old Also, format auto-detecting is not so easy.
Note that |
8aa7e91
to
c633e60
Compare
@maskit |
retest this please |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outline looks good.
AuthParamsStringConfigurable
-- The name might be unclear.- Old
configure
-- Should be deprecated - New
configure
-- Future plan should be explained on Javadoc
I don't think they are blockers but would be better to change at this time.
If I understand you all correctly, our consensus here is:
and I think we should:
@tkb77 @merlimat @rdhabalia Makes sense? |
@ maskit
What did you feel unclear about the name?
Does the old interface need to be deprecated?
I will add javadoc for the new interface. |
I can understand the name because we have been talking about it but I'm not confident with that plugin developers easily understand what it is for. The name you suggested doesn't add any context (the same thing is already written as the method name and the parameter name). As I wrote on the issue, I'd suggest
Yes, I think it need to be deprecated because it makes API simple and solid, and it indicates that we are not going to add support for other formats on Honestly, I'd not write configuration values directly in |
c633e60
to
48831a8
Compare
@maskit
|
LGTM. @maskit can you do a final check on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Motivation
#671
Modifications
I added
EncodedAuthenticationParameterSupport
interface to parse authParamsString on plugin side.Result
configure(String authParamsString)
in EncodedAuthenticationParameterSupport interface.