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 api support to try out loginglow AI feature #681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -205,7 +205,15 @@ public enum ErrorMessage {
ERROR_RETRIEVING_USER_BY_ID("65503", "Error occurred while retrieving user",
"Error occurred while retrieving user by userid: %s."),
ERROR_RETRIEVING_USERSTORE_MANAGER("65504", "Error retrieving userstore manager.",
"Error occurred while retrieving userstore manager.");
"Error occurred while retrieving userstore manager."),

// Login Flow AI Service related error messages.
ERROR_CODE_ERROR_GETTING_LOGINFLOW_AI_RESULT_STATUS("65600",
"Error occurred while getting the Login Flow AI result status.",
"Error occurred while getting the Login Flow AI result status."),
ERROR_CODE_ERROR_GETTING_LOGINFLOW_AI_RESULT("65601",
"Error occurred while getting the Login Flow AI result.",
"Error occurred while getting the Login Flow AI result.");

private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.application.mgt.AuthorizedAPIManagementService;
import org.wso2.carbon.identity.application.mgt.ai.LoginFlowAIManager;
import org.wso2.carbon.identity.cors.mgt.core.CORSManagementService;
import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl;
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
Expand All @@ -43,6 +44,7 @@ public class ApplicationManagementServiceHolder {
private static APIResourceManager apiResourceManager;
private static AuthorizedAPIManagementService authorizedAPIManagementService;
private static OrgApplicationManager orgApplicationManager;
private static LoginFlowAIManager loginFlowAIManagementService;

public static ApplicationManagementService getApplicationManagementService() {

Expand Down Expand Up @@ -194,4 +196,22 @@ public static void setOrgApplicationManager(OrgApplicationManager orgApplication

ApplicationManagementServiceHolder.orgApplicationManager = orgApplicationManager;
}

/**
* Get LoginFlowAIManagementService.
* @return LoginFlowAIManagementService
*/
public static LoginFlowAIManager getLoginFlowAIManagementService() {

return loginFlowAIManagementService;
}

/**
* Set LoginFlowAIManagementService.
* @param loginFlowAIManagementService LoginFlowAIManager.
*/
public static void setLoginFlowAIManagementService(LoginFlowAIManager loginFlowAIManagementService) {

ApplicationManagementServiceHolder.loginFlowAIManagementService = loginFlowAIManagementService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.identity.api.server.application.management.common.factory;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.mgt.ai.LoginFlowAIManager;

/**
* Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to
* instantiate the LoginFlowAIManager type of object inside the container.
*/
public class LoginFlowAIManagementOSGiServiceFactory extends AbstractFactoryBean<LoginFlowAIManager> {

private LoginFlowAIManager loginFlowAIManager;

@Override
public Class<?> getObjectType() {
return Object.class;
}

@Override
protected LoginFlowAIManager createInstance() throws Exception {

if (this.loginFlowAIManager == null) {
LoginFlowAIManager loginFlowAIManagementOSGiServiceFactory =
(LoginFlowAIManager) PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(LoginFlowAIManager.class, null);

if (loginFlowAIManagementOSGiServiceFactory != null) {
this.loginFlowAIManager = loginFlowAIManagementOSGiServiceFactory;
} else {
throw new Exception("Unable to retrieve ApplicationManagementService service.");
}
}
return this.loginFlowAIManager;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import org.wso2.carbon.identity.api.server.application.management.v1.Error;
import java.io.File;
import org.wso2.carbon.identity.api.server.application.management.v1.InboundProtocolListItem;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowGenerateRequest;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowGenerateResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowResultResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowStatusResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.OIDCMetaData;
import org.wso2.carbon.identity.api.server.application.management.v1.OpenIDConnectConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.PassiveStsConfiguration;
Expand Down Expand Up @@ -410,6 +414,30 @@ public Response exportApplicationAsFile(@ApiParam(value = "ID of the application
return delegate.exportApplicationAsFile(applicationId, exportSecrets, accept );
}

@Valid
@POST
@Path("/loginflow/generate")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Initiate login flow generation", notes = "This API provides the capability to initiate the generation of a login flow. <br> <b>Permission required:</b> * /permission/admin/manage/identity/applicationmgt/update <br> <b>Scope required:</b> * internal_application_mgt_update ", response = LoginFlowGenerateResponse.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "LoginFlow", })
@ApiResponses(value = {
@ApiResponse(code = 202, message = "Accepted", response = LoginFlowGenerateResponse.class),
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
@ApiResponse(code = 401, message = "Unauthorized", response = Void.class),
@ApiResponse(code = 403, message = "Forbidden", response = Void.class),
@ApiResponse(code = 404, message = "Not Found", response = Error.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
})
public Response generateLoginFlow(@ApiParam(value = "" ,required=true) @Valid LoginFlowGenerateRequest loginFlowGenerateRequest) {

return delegate.generateLoginFlow(loginFlowGenerateRequest );
}

@Valid
@GET
@Path("/meta/adaptive-auth-templates")
Expand Down Expand Up @@ -723,6 +751,48 @@ public Response getInboundSAMLConfiguration(@ApiParam(value = "ID of the applica
return delegate.getInboundSAMLConfiguration(applicationId );
}

@Valid
@GET
@Path("/loginflow/result/{operation_id}")

@Produces({ "application/json" })
@ApiOperation(value = "Get the final login flow result", notes = "", response = LoginFlowResultResponse.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "LoginFlow", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = LoginFlowResultResponse.class),
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
@ApiResponse(code = 404, message = "Not Found", response = Error.class)
})
public Response getLoginFlowResult(@ApiParam(value = "",required=true) @PathParam("operation_id") String operationId) {

return delegate.getLoginFlowResult(operationId );
}

@Valid
@GET
@Path("/loginflow/status/{operation_id}")

@Produces({ "application/json" })
@ApiOperation(value = "Get the status of the login flow generation process", notes = "", response = LoginFlowStatusResponse.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "LoginFlow", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = LoginFlowStatusResponse.class),
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
@ApiResponse(code = 404, message = "Not Found", response = Error.class)
})
public Response getLoginFlowStatus(@ApiParam(value = "",required=true) @PathParam("operation_id") String operationId) {

return delegate.getLoginFlowStatus(operationId );
}

@Valid
@GET
@Path("/meta/inbound-protocols/oidc")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* 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
Expand Down Expand Up @@ -41,6 +41,10 @@
import org.wso2.carbon.identity.api.server.application.management.v1.Error;
import java.io.File;
import org.wso2.carbon.identity.api.server.application.management.v1.InboundProtocolListItem;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowGenerateRequest;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowGenerateResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowResultResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.LoginFlowStatusResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.OIDCMetaData;
import org.wso2.carbon.identity.api.server.application.management.v1.OpenIDConnectConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.PassiveStsConfiguration;
Expand Down Expand Up @@ -84,6 +88,8 @@ public interface ApplicationsApiService {

public Response exportApplicationAsFile(String applicationId, Boolean exportSecrets, String accept);

public Response generateLoginFlow(LoginFlowGenerateRequest loginFlowGenerateRequest);

public Response getAdaptiveAuthTemplates();

public Response getAllApplicationTemplates(Integer limit, Integer offset, SearchContext searchContext);
Expand All @@ -110,6 +116,10 @@ public interface ApplicationsApiService {

public Response getInboundSAMLConfiguration(String applicationId);

public Response getLoginFlowResult(String operationId);

public Response getLoginFlowStatus(String operationId);

public Response getOIDCMetadata();

public Response getPassiveStsConfiguration(String applicationId);
Expand Down
Loading
Loading