-
Notifications
You must be signed in to change notification settings - Fork 546
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
Add support to connect to the LoginFlow AI service #5971
base: master
Are you sure you want to change the base?
Conversation
ec247a1
to
e73a82c
Compare
components/application-mgt/org.wso2.carbon.identity.application.mgt/pom.xml
Show resolved
Hide resolved
...src/main/java/org/wso2/carbon/identity/application/mgt/ai/constant/LoginFlowAIConstants.java
Show resolved
Hide resolved
...src/main/java/org/wso2/carbon/identity/application/mgt/ai/constant/LoginFlowAIConstants.java
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
...n.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAITokenService.java
Outdated
Show resolved
Hide resolved
8ee9876
to
5367ae1
Compare
@@ -0,0 +1,23 @@ | |||
package org.wso2.carbon.identity.application.mgt.ai; |
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.
missing copywrite text
features/ai-services-mgt/pom.xml
Outdated
<module>org.wso2.carbon.ai.service.mgt.server.feature</module> | ||
</modules> | ||
|
||
</project> |
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.
Missing new line
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5971 +/- ##
============================================
- Coverage 40.88% 40.71% -0.17%
- Complexity 14516 14601 +85
============================================
Files 1772 1781 +9
Lines 117769 118681 +912
Branches 19116 20275 +1159
============================================
+ Hits 48146 48321 +175
- Misses 62316 63053 +737
Partials 7307 7307
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
features/ai-services-mgt/org.wso2.carbon.ai.service.mgt.server.feature/pom.xml
Outdated
Show resolved
Hide resolved
...on.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManagerTest.java
Show resolved
Hide resolved
...on.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ai/LoginFlowAIManagerTest.java
Show resolved
Hide resolved
...src/main/java/org/wso2/carbon/identity/application/mgt/ai/constant/LoginFlowAIConstants.java
Show resolved
Hide resolved
components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/pom.xml
Outdated
Show resolved
Hide resolved
...arbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/constants/AIConstants.java
Show resolved
Hide resolved
...arbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/constants/AIConstants.java
Show resolved
Hide resolved
....ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java
Show resolved
Hide resolved
....ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java
Outdated
Show resolved
Hide resolved
Quality Gate passedIssues Measures |
org.apache.http.concurrent; version="${httpcore.version.osgi.import.range}", | ||
</Import-Package> | ||
<Export-Package> | ||
org.wso2.carbon.ai.service.mgt.*; version="${carbon.identity.package.export.version}" |
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.
Export only the necessary packages. Refer https://github.com/wso2-extensions/identity-organization-management/pull/415/files#diff-14b084926843894a0c5ada151f6e58de555097d5fb869d352a4a0c4e75986153R116-R124
private AccessTokenRequestHelper createDefaultHelper() { | ||
|
||
return new AccessTokenRequestHelper(LOGIN_FLOW_AI_KEY, LOGIN_FLOW_AI_TOKEN_ENDPOINT, | ||
HttpAsyncClients.createDefault()); |
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.
Can we use connection pooling here ?
private static volatile AIAccessTokenManager instance; // Volatile for thread safety. | ||
private static final Object lock = new Object(); // Lock for synchronization. |
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.
Check if we want to change the naming
private String clientId; | ||
|
||
private AIAccessTokenManager() { | ||
// Prevent from initialization. |
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.
Remove comment
private final String key; | ||
private final String aiServiceTokenEndpoint; | ||
private static final int MAX_RETRIES = IdentityUtil.getProperty( | ||
"AIServices.LoginFlow.TokenRequestMaxRetries") != null ? |
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.
Remove LoginFlow config since this a common component
private final String aiServiceTokenEndpoint; | ||
private static final int MAX_RETRIES = IdentityUtil.getProperty( | ||
"AIServices.LoginFlow.TokenRequestMaxRetries") != null ? | ||
Integer.parseInt(IdentityUtil.getProperty("AIServices.LoginFlow.TokenRequestMaxRetries")) : 3; |
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.
Use constants
private static final int MAX_RETRIES = IdentityUtil.getProperty( | ||
"AIServices.LoginFlow.TokenRequestMaxRetries") != null ? | ||
Integer.parseInt(IdentityUtil.getProperty("AIServices.LoginFlow.TokenRequestMaxRetries")) : 3; | ||
private static final long TIMEOUT = IdentityUtil.getProperty( |
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.
Move these into a method
post.setHeader("Content-Type", "application/x-www-form-urlencoded"); | ||
|
||
StringEntity entity = new StringEntity("grant_type=client_credentials"); | ||
entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded")); |
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.
Use constants for headers (There should be reusable constants
post.setEntity(entity); | ||
|
||
CountDownLatch latch = new CountDownLatch(1); | ||
final String[] accessToken = new String[1]; |
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.
***NOTE: What should we do in multi node setup, should we use multiple JWT tokens or persist the access token in DB?
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | ||
String responseBody = EntityUtils.toString(response.getEntity()); | ||
Map<String, Object> responseMap = gson.fromJson(responseBody, Map.class); | ||
accessToken[0] = (String) responseMap.get("access_token"); |
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.
Use constants for all keys. Check all places
// Decode the JWT to extract client ID. | ||
String[] jwtParts = accessToken[0].split("\\."); | ||
if (jwtParts.length == 3) { | ||
String payloadJson = new String(Base64.getUrlDecoder().decode(jwtParts[1]), |
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.
Check if we need to decode the token also check if we actually need the token type
response.getStatusLine().getStatusCode()); | ||
} | ||
} catch (IOException | JsonSyntaxException e) { | ||
LOG.error("Error parsing token response: " + e.getMessage(), e); |
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.
Change to debug logs
…ts-sign-and-signature-validation Add util methods for signing and signature validation
…lopment iteration
…lopment iteration
…lopment iteration
Introduce SAMLSSOPersistenceManagerFactory to switch between different persistence implementation
…lopment iteration
…lopment iteration
…nd-prov-issue Revert "Revert "Fix: Unable to Update Google Connector after Configuring Outbound Provisioning for Google""
…lopment iteration
- Define constants for reusable keys - Remove token decoding and get the clientId from the AI KEY
# Conflicts: # components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/constants/AIConstants.java # components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/token/AIAccessTokenManager.java # components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/src/main/java/org/wso2/carbon/ai/service/mgt/util/AIHttpClientUtil.java # components/application-mgt/org.wso2.carbon.identity.application.mgt/pom.xml # pom.xml
- Get tokens with token binding - Add j2 configs - Modify AIHttpUtil tests to use call mockwebserver
Quality Gate passedIssues Measures |
Proposed changes in this pull request
With this PR, the product-is will be able to connect the loginflow AI microservice and generate AI results accordingly
Related Issue(s)