-
Notifications
You must be signed in to change notification settings - Fork 6
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
addding interface for AuthenticationHandlerProvider #217
Changes from all commits
75c2a1b
a9cb298
9391259
772776c
f43c912
433b0d3
fa8f531
2e3980f
36e447d
0166dcb
c312cda
30cb0b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package com.flipkart.varadhi.entities.auth; | ||
|
||
import java.util.Map; | ||
|
||
/* | ||
* UserContext represents the authenticated user. It is used to pass the user information across the system. | ||
* This can be enhanced to include more details like context around the authentication. | ||
*/ | ||
|
||
public interface UserContext { | ||
|
||
String getSubject(); | ||
|
||
boolean isExpired(); | ||
|
||
// TODO: enhance it to include more details like context around the authentication | ||
default Map<String, String> getAttributes() { | ||
return Map.of(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package com.flipkart.varadhi.entities.utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import lombok.Data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.net.URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import java.util.Map; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class RequestContext { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private URI uri; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private Map<String, String> params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private Map<String, String> headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private Map<String, Object> context; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve field declarations for better type safety and immutability. The current implementation has several potential issues:
Apply this diff: - private URI uri;
- private Map<String, String> params;
- private Map<String, String> headers;
- private Map<String, Object> context;
+ private final URI uri;
+ private final Map<String, String> params;
+ private final TreeMap<String, String> headers; // Use TreeMap with String.CASE_INSENSITIVE_ORDER
+ private final Map<String, RequestAttribute<?>> context;
+
+ public RequestContext(URI uri,
+ Map<String, String> params,
+ Map<String, String> headers,
+ Map<String, RequestAttribute<?>> context) {
+ this.uri = uri;
+ this.params = Map.copyOf(params); // Create immutable copy
+ this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ this.headers.putAll(headers);
+ this.context = Map.copyOf(context);
+ }
+
+ /**
+ * Type-safe container for request context attributes.
+ * @param <T> The type of the attribute value
+ */
+ public interface RequestAttribute<T> {
+ String getKey();
+ Class<T> getType();
+ T getValue();
+ } This improves the implementation by:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package com.flipkart.varadhi.spi.authn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import com.flipkart.varadhi.spi.ConfigFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import lombok.Data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@Data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public class AuthenticationOptions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private String providerClassName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@ConfigFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private String configFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add documentation and proper encapsulation. The class lacks essential documentation and proper encapsulation. As this is part of the SPI (Service Provider Interface), clear documentation is crucial for implementers. Consider applying these improvements: package com.flipkart.varadhi.spi.authn;
import com.flipkart.varadhi.spi.ConfigFile;
+/**
+ * Configuration options for authentication providers.
+ * This class holds the necessary configuration parameters required to initialize
+ * and configure an authentication provider implementation.
+ */
public class AuthenticationOptions {
+ /**
+ * The fully qualified class name of the authentication provider implementation.
+ */
private String providerClassName;
+ /**
+ * Path to the configuration file containing provider-specific settings.
+ */
@ConfigFile
private String configFile;
+ public String getProviderClassName() {
+ return providerClassName;
+ }
+
+ public void setProviderClassName(String providerClassName) {
+ this.providerClassName = providerClassName;
+ }
+
+ public String getConfigFile() {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile) {
+ this.configFile = configFile;
+ }
} 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||||||||||||||||||||||
package com.flipkart.varadhi.spi.authn; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import com.flipkart.varadhi.entities.Org; | ||||||||||||||||||||||||||
import com.flipkart.varadhi.entities.auth.UserContext; | ||||||||||||||||||||||||||
import com.flipkart.varadhi.entities.utils.RequestContext; | ||||||||||||||||||||||||||
import io.vertx.core.Future; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
public interface AuthenticationProvider { | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add interface documentation. Please add Javadoc to describe:
+/**
+ * Service provider interface for implementing authentication mechanisms.
+ * Implementations must be thread-safe and handle concurrent requests.
+ * <p>
+ * The lifecycle of an AuthenticationProvider:
+ * 1. Instance created
+ * 2. init() called once
+ * 3. handle() called multiple times concurrently
+ * </p>
+ */
public interface AuthenticationProvider { 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
Future<Boolean> init(AuthenticationOptions authenticationOptions); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance init method contract. The boolean return type doesn't provide enough context for initialization failures. Consider:
+ /**
+ * Initializes the authentication provider with the given options.
+ * This method is called once during provider initialization.
+ *
+ * @param authenticationOptions configuration options for the provider
+ * @return Future that completes with initialization result
+ * @throws IllegalArgumentException if options are invalid
+ */
- Future<Boolean> init(AuthenticationOptions authenticationOptions);
+ Future<Void> init(AuthenticationOptions authenticationOptions); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
Future<UserContext> authenticate(Org org, RequestContext requestContext); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve authenticate method contract. Add method documentation specifying:
Apply this diff: + /**
+ * Authenticates a request in the context of an organization.
+ *
+ * @param org organization context for the authentication
+ * @param requestContext context containing request details
+ * @return Future that completes with UserContext on successful authentication
+ * @throws IllegalArgumentException if org or requestContext is null
+ * @throws AuthenticationException if authentication fails
+ */
Future<UserContext> authenticate(Org org, RequestContext requestContext); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
} |
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.
🛠️ Refactor suggestion
Consider making the class immutable and adding documentation.
The class holds request context that should be immutable after creation to prevent unintended modifications during request processing.
Apply this diff:
Note:
@Value
is Lombok's immutable variant of@Data
that makes all fields private and final.📝 Committable suggestion