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 25 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
201 changes: 201 additions & 0 deletions components/ai-services-mgt/org.wso2.carbon.ai.service.mgt/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
sahandilshan marked this conversation as resolved.
Show resolved Hide resolved
~
~ 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.6.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.ai.service.mgt</artifactId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ai service is specific to IAM right?

Suggested change
<artifactId>org.wso2.carbon.ai.service.mgt</artifactId>
<artifactId>org.wso2.carbon.identity.ai.service.mgt</artifactId>

<packaging>bundle</packaging>
<name>WSO2 Carbon - AI Service Management Bundle</name>
sahandilshan marked this conversation as resolved.
Show resolved Hide resolved
<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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is one scoped as provided and the other is not?

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
sahandilshan marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
<artifactId>pax-logging-api</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.82</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,85 @@
/*
* 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 {

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_SERVICE_TIMEOUT_PROPERTY_NAME = "AIServices.TokenRequestTimeout";
public static final String HTTP_CONNECTION_POOL_SIZE_PROPERTY_NAME = "AIServices.HTTPConnectionPoolSize";

// 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/";

/**
* Enums for error messages.
*/
public enum ErrorMessages {

MAXIMUM_RETRIES_EXCEEDED("AI_10000", "Maximum retries exceeded to retrieve the access token."),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the error code consistent with other components. IIRC we don't us "_" instead use "-"

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,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;
sahandilshan marked this conversation as resolved.
Show resolved Hide resolved
}

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;
}
}
Loading
Loading