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

Add support to connect to the LoginFlow AI service #6260

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e73a82c
Add support to connect to the LoginFlow AI service
sahandilshan Sep 30, 2024
2c24dee
Add AI Management component
sahandilshan Oct 18, 2024
22bcf9b
Add ai feature component
sahandilshan Oct 18, 2024
3532bd4
Add loginflow AI capability
sahandilshan Oct 18, 2024
c3431ee
Merge remote-tracking branch 'upstream/master' into loginflow-ai-2
sahandilshan Oct 18, 2024
2df174b
Bump new component version
sahandilshan Oct 18, 2024
5367ae1
Fix code quality
sahandilshan Oct 18, 2024
ddfaf3c
Bump AI version to latest framework version
sahandilshan Oct 18, 2024
ed01d0b
Add more unit tests to cover complex scenarios
sahandilshan Nov 15, 2024
a6f353b
Merge remote-tracking branch 'upstream/master' into loginflow-ai-2
sahandilshan Nov 15, 2024
bbf57d7
Bump framework version in AI components
sahandilshan Nov 15, 2024
d928d9a
Fix checkstyle issues
sahandilshan Nov 15, 2024
45ab16e
Add support to connect to the LoginFlow AI service
sahandilshan Sep 30, 2024
d9e0ba2
Add AI Management component
sahandilshan Oct 18, 2024
90ae363
Add ai feature component
sahandilshan Oct 18, 2024
b4df626
Add loginflow AI capability
sahandilshan Oct 18, 2024
57f6c5f
Bump new component version
sahandilshan Oct 18, 2024
ddc1733
Fix code quality
sahandilshan Oct 18, 2024
16e792e
Bump AI version to latest framework version
sahandilshan Oct 18, 2024
a5229cc
Add more unit tests to cover complex scenarios
sahandilshan Nov 15, 2024
da6360b
Bump framework version in AI components
sahandilshan Nov 15, 2024
95eef11
Fix checkstyle issues
sahandilshan Nov 15, 2024
aca5555
Add support for connection pool with other improvements
sahandilshan Jan 6, 2025
998b94f
Merge remote-tracking branch 'origin/loginflow-ai' into loginflow-ai-2
sahandilshan Jan 6, 2025
cdad525
Modify LoginFlowAI Implementation
sahandilshan Jan 6, 2025
127bdee
Add connection timeout support with other modifications
sahandilshan Jan 8, 2025
53e90da
Merge remote-tracking branch 'upstream/master' into loginflow-ai-2
sahandilshan Jan 9, 2025
3f1f8db
Refactor AI service
sahandilshan Jan 10, 2025
fbb6f4b
Merge remote-tracking branch 'upstream/master' into loginflow-ai-2
sahandilshan Jan 10, 2025
f177247
Update the new component version
sahandilshan Jan 10, 2025
458e913
Fix review suggestions
sahandilshan Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2025, 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.7.92-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.ai.service.mgt</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Identity - AI Service Management Bundle</name>
<description>This 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.apache.httpcomponents.wso2</groupId>
<artifactId>httpcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</artifactId>
<scope>provided</scope>
</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.concurrent; version="${httpcore.version.osgi.import.range}",
</Import-Package>
<Export-Package>
org.wso2.carbon.identity.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>
<configuration>
<excludes>
<exclude>**/*Exception.class</exclude>
<exclude>**/*Constants*.class</exclude>
</excludes>
</configuration>
<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.80</minimum>
</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,107 @@
/*
* Copyright (c) 2025, 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.identity.ai.service.mgt.constants;

/**
* Constants for the LoginFlowAI module.
*/
public class AIConstants {

private AIConstants () {

}

public static final String AI_SERVICE_KEY_PROPERTY_NAME = "AIServices.Key";
public static final String AI_TOKEN_ENDPOINT_PROPERTY_NAME = "AIServices.TokenEndpoint";
public static final String AI_TOKEN_SERVICE_MAX_RETRIES_PROPERTY_NAME = "AIServices.TokenRequestMaxRetries";
public static final String AI_TOKEN_CONNECTION_TIMEOUT_PROPERTY_NAME = "AIServices.TokenConnectionTimeout";
public static final String AI_TOKEN_CONNECTION_REQUEST_TIMEOUT_PROPERTY_NAME = "AIServices" +
".TokenConnectionRequestTimeout";
public static final String AI_TOKEN_SOCKET_TIMEOUT_PROPERTY_NAME = "AIServices.TokenConnectionSocketTimeout";

public static final String HTTP_CONNECTION_POOL_SIZE_PROPERTY_NAME = "AIServices.HTTPConnectionPoolSize";
public static final String HTTP_CONNECTION_TIMEOUT_PROPERTY_NAME = "AIServices.HTTPConnectionTimeout";
public static final String HTTP_CONNECTION_REQUEST_TIMEOUT_PROPERTY_NAME = "AIServices" +
".HTTPConnectionRequestTimeout";
public static final String HTTP_SOCKET_TIMEOUT_PROPERTY_NAME = "AIServices.HTTPSocketTimeout";

// Http constants.
public static final String HTTP_BASIC = "Basic";
public static final String HTTP_BEARER = "Bearer";
public static final String CONTENT_TYPE_FORM_URLENCODED = "application/x-www-form-urlencoded";
public static final String CONTENT_TYPE_JSON = "application/json";

// Access Token response constants.
public static final String ACCESS_TOKEN_KEY = "access_token";

public static final String TENANT_CONTEXT_PREFIX = "/t/";

// Default Property values.
public static final int DEFAULT_TOKEN_REQUEST_MAX_RETRIES = 3;
public static final int DEFAULT_TOKEN_CONNECTION_TIMEOUT = 3000;
public static final int DEFAULT_TOKEN_CONNECTION_REQUEST_TIMEOUT = 3000;
public static final int DEFAULT_TOKEN_SOCKET_TIMEOUT = 3000;

public static final int DEFAULT_HTTP_CONNECTION_POOL_SIZE = 20;
public static final int DEFAULT_HTTP_CONNECTION_TIMEOUT = 3000;
public static final int DEFAULT_HTTP_CONNECTION_REQUEST_TIMEOUT = 3000;
public static final int DEFAULT_HTTP_SOCKET_TIMEOUT = 3000;

/**
* 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 " +
"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.");

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,40 @@
/*
* Copyright (c) 2025, 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.identity.ai.service.mgt.exceptions;

/**
* Client Exception class for AI service.
*/
public class AIClientException extends AIException {

public AIClientException(String message, String errorCode) {

super(message, errorCode);
}

public AIClientException(String message, String errorCode, int serverStatusCode, String serverMessage) {

super(message, errorCode, serverStatusCode, serverMessage);
}

public AIClientException(String message, String errorCode, Throwable cause) {

super(message, errorCode, cause);
}
}
Loading
Loading