-
Notifications
You must be signed in to change notification settings - Fork 541
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?
Changes from all commits
e73a82c
2c24dee
22bcf9b
3532bd4
c3431ee
2df174b
5367ae1
ddfaf3c
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 |
---|---|---|
@@ -0,0 +1,187 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
~ | ||
~ WSO2 LLC. licenses this file to you under the Apache License, | ||
~ Version 2.0 (the "License"); you may not use this file except | ||
~ in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, | ||
~ software distributed under the License is distributed on an | ||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~ KIND, either express or implied. See the License for the | ||
~ specific language governing permissions and limitations | ||
~ under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.wso2.carbon.identity.framework</groupId> | ||
<artifactId>ai-services-mgt</artifactId> | ||
<version>7.5.73-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>org.wso2.carbon.ai.service.mgt</artifactId> | ||
<packaging>bundle</packaging> | ||
<name>WSO2 Carbon - AI Service Management Bundle</name> | ||
<description>This is a Carbon bundle that represents the AI Service Management Bundle.</description> | ||
<url>http://wso2.org</url> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.ops4j.pax.logging</groupId> | ||
<artifactId>pax-logging-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.carbon.identity.framework</groupId> | ||
<artifactId>org.wso2.carbon.identity.core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.wso2.orbit.org.apache.httpcomponents</groupId> | ||
<artifactId>httpasyncclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents.wso2</groupId> | ||
<artifactId>httpcore</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<instructions> | ||
<Bundle-SymbolicName> | ||
${project.artifactId} | ||
</Bundle-SymbolicName> | ||
<Bundle-Name>${project.artifactId}</Bundle-Name> | ||
<Import-Package> | ||
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}", | ||
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}", | ||
com.google.gson;version="${com.google.code.gson.osgi.version.range}", | ||
org.wso2.carbon.identity.core.util; version="${carbon.identity.package.import.version.range}", | ||
org.apache.commons.lang; version="${commons-lang.wso2.osgi.version.range}", | ||
org.apache.commons.logging; version="${import.package.version.commons.logging}", | ||
com.fasterxml.jackson.databind.*; version="${com.fasterxml.jackson.annotation.version.range}", | ||
org.wso2.carbon.context; version="${carbon.kernel.package.import.version.range}", | ||
|
||
org.apache.http; version="${httpcore.version.osgi.import.range}", | ||
org.apache.http.client; version="${httpcomponents-httpclient.imp.pkg.version.range}", | ||
org.apache.http.client.methods; version="${httpcomponents-httpclient.imp.pkg.version.range}", | ||
org.apache.http.entity; version="${httpcore.version.osgi.import.range}", | ||
org.apache.http.message; version="${httpcore.version.osgi.import.range}", | ||
org.apache.http.protocol; version="${httpcore.version.osgi.import.range}", | ||
org.apache.http.util; version="${httpcore.version.osgi.import.range}", | ||
org.apache.http.impl.client; version="${httpcomponents-httpclient.imp.pkg.version.range}", | ||
org.apache.http.impl.nio.client; version="${httpasyncclient.version.osgi.import.range}", | ||
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}" | ||
</Export-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${maven.surefire.plugin.version}</version> | ||
<configuration> | ||
<!--suppress UnresolvedMavenProperty --> | ||
<argLine> | ||
${argLine} | ||
--add-opens=java.base/java.lang=ALL-UNNAMED | ||
--add-opens=java.base/java.util=ALL-UNNAMED | ||
--add-opens java.xml/jdk.xml.internal=ALL-UNNAMED | ||
--add-opens=java.base/java.io=ALL-UNNAMED | ||
--add-opens=java.base/sun.nio.fs=ALL-UNNAMED | ||
</argLine> | ||
<suiteXmlFiles> | ||
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> | ||
</suiteXmlFiles> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>${jacoco.version}</version> | ||
<executions> | ||
<execution> | ||
<id>default-prepare-agent</id> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-prepare-agent-integration</id> | ||
<goals> | ||
<goal>prepare-agent-integration</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-report</id> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-report-integration</id> | ||
<goals> | ||
<goal>report-integration</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>default-check</id> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<rule implementation="org.jacoco.maven.RuleConfiguration"> | ||
<element>BUNDLE</element> | ||
<limits> | ||
<limit implementation="org.jacoco.report.check.Limit"> | ||
<counter>COMPLEXITY</counter> | ||
<value>COVEREDRATIO</value> | ||
<minimum>0.50</minimum> | ||
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. This test coverage threshold is not enough. |
||
</limit> | ||
</limits> | ||
</rule> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
<configuration> | ||
<threshold>High</threshold> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.ai.service.mgt.constants; | ||
|
||
/** | ||
* Constants for the LoginFlowAI module. | ||
*/ | ||
public class AIConstants { | ||
|
||
/** | ||
* Enums for error messages. | ||
*/ | ||
public enum ErrorMessages { | ||
|
||
MAXIMUM_RETRIES_EXCEEDED("AI_10000", "Maximum retries exceeded to retrieve the access token."), | ||
UNABLE_TO_ACCESS_AI_SERVICE_WITH_RENEW_ACCESS_TOKEN("AI_10003", "Unable to access the " + | ||
Comment on lines
+31
to
+32
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. Let's make the error codes in consistent oreder |
||
"AI service with the renewed access token."), | ||
REQUEST_TIMEOUT("AI_10004", "Request to the AI service timed out."), | ||
ERROR_RETRIEVING_ACCESS_TOKEN("AI_10007", "Error occurred while retrieving the " + | ||
"access token."), | ||
CLIENT_ERROR_WHILE_CONNECTING_TO_AI_SERVICE("AI_10008", "Client error occurred " + | ||
"for %s tenant while connecting to AI service."), | ||
SERVER_ERROR_WHILE_CONNECTING_TO_AI_SERVICE("AI_10009", "Server error occurred " + | ||
"for %s tenant while connecting to AI service."); | ||
|
||
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. extra new line |
||
|
||
private final String code; | ||
private final String message; | ||
|
||
ErrorMessages(String code, String message) { | ||
|
||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
public String getCode() { | ||
|
||
return code; | ||
} | ||
|
||
public String getMessage() { | ||
|
||
return message; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
|
||
return code + ":" + message; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.ai.service.mgt.exceptions; | ||
|
||
import org.wso2.carbon.ai.service.mgt.util.AIHttpClientUtil; | ||
|
||
/** | ||
* Client Exception class for AI service. | ||
*/ | ||
public class AIClientException extends Exception { | ||
|
||
private final String errorCode; | ||
private AIHttpClientUtil.HttpResponseWrapper loginFlowAIResponse; | ||
|
||
public AIClientException(String message, String errorCode) { | ||
|
||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public AIClientException(AIHttpClientUtil.HttpResponseWrapper httpResponseWrapper, | ||
String message, String errorCode) { | ||
|
||
super(message); | ||
this.errorCode = errorCode; | ||
this.loginFlowAIResponse = httpResponseWrapper; | ||
} | ||
|
||
public AIClientException(String message, String errorCode, Throwable cause) { | ||
|
||
super(message, cause); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public String getErrorCode() { | ||
|
||
return errorCode; | ||
} | ||
|
||
public AIHttpClientUtil.HttpResponseWrapper getLoginFlowAIResponse() { | ||
|
||
return loginFlowAIResponse; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.carbon.ai.service.mgt.exceptions; | ||
|
||
import org.wso2.carbon.ai.service.mgt.util.AIHttpClientUtil; | ||
|
||
/** | ||
* Client Exception class for AI service. | ||
*/ | ||
public class AIServerException extends Exception { | ||
|
||
private String errorCode; | ||
private AIHttpClientUtil.HttpResponseWrapper loginFlowAIResponse; | ||
|
||
public AIServerException(String message, String errorCode) { | ||
|
||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public AIServerException(AIHttpClientUtil.HttpResponseWrapper httpResponseWrapper, | ||
String message, String errorCode) { | ||
|
||
super(message); | ||
this.errorCode = errorCode; | ||
this.loginFlowAIResponse = httpResponseWrapper; | ||
} | ||
|
||
public AIServerException(String message, Throwable cause) { | ||
|
||
super(cause); | ||
} | ||
|
||
public AIServerException(String message, String errorCode, Throwable cause) { | ||
|
||
super(message, cause); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public String getErrorCode() { | ||
|
||
return errorCode; | ||
} | ||
|
||
public AIHttpClientUtil.HttpResponseWrapper getBrandingAIResponse() { | ||
|
||
return loginFlowAIResponse; | ||
} | ||
} |
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.
Why these are added?