Skip to content

Commit

Permalink
Update APIs to support custom authentication management.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Nov 28, 2024
1 parent 6dd1f33 commit 54a3aef
Show file tree
Hide file tree
Showing 16 changed files with 1,435 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.application.common</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.wso2.carbon.identity.api.server.authenticators.common;

import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.idp.mgt.IdentityProviderManager;

Expand All @@ -28,6 +29,7 @@ public class AuthenticatorsServiceHolder {

private ApplicationManagementService applicationManagementService;
private IdentityProviderManager identityProviderManager;
private ApplicationAuthenticatorService applicationAuthenticatorService;

private AuthenticatorsServiceHolder() {

Expand Down Expand Up @@ -77,4 +79,24 @@ public void setIdentityProviderManager(IdentityProviderManager identityProviderM

AuthenticatorsServiceHolder.getInstance().identityProviderManager = identityProviderManager;
}

/**
* Get ApplicationAuthenticatorService osgi service.
*
* @return ApplicationAuthenticatorService
*/
public ApplicationAuthenticatorService getApplicationCommonService() {

return applicationAuthenticatorService;
}

/**
* Set ApplicationAuthenticatorService osgi service.
*
* @param applicationAuthenticatorService ApplicationAuthenticatorService.
*/
public void setApplicationCommonService(ApplicationAuthenticatorService applicationAuthenticatorService) {

this.applicationAuthenticatorService = applicationAuthenticatorService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public enum ErrorMessage {
"Filter needs to be in the format <attribute>+<operation>+<value>. Eg: tag+eq+2FA"),
ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE("60002", "Unsupported filter attribute.",
"The filter attribute '%s' is not supported."),
ERROR_CODE_ENDPOINT_CONFIG("60003", "Unsupported filter attribute.",
"The filter attribute '%s' is not supported."),

ERROR_CODE_ERROR_LISTING_AUTHENTICATORS("65001", "Unable to list the existing authenticators.",
"Server encountered an error while listing the authenticators."),
ERROR_CODE_ERROR_LISTING_IDPS("65002", "Unable to list the existing identity providers.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.authenticators.common.factory;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService;

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

private ApplicationAuthenticatorService applicationAuthenticatorService;

@Override
public Class<?> getObjectType() {

return Object.class;
}

@Override
protected ApplicationAuthenticatorService createInstance() throws Exception {

if (this.applicationAuthenticatorService == null) {
ApplicationAuthenticatorService taskOperationService = (ApplicationAuthenticatorService)
PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(
ApplicationAuthenticatorService.class, null);
if (taskOperationService != null) {
this.applicationAuthenticatorService = taskOperationService;
} else {
throw new Exception("Unable to retrieve ApplicationAuthenticatorService service.");
}
}
return this.applicationAuthenticatorService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.ConnectedApps;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Error;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorCreation;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorUpdate;
import org.wso2.carbon.identity.api.server.authenticators.v1.AuthenticatorsApiService;

import javax.validation.Valid;
Expand Down Expand Up @@ -91,6 +93,54 @@ public Response authenticatorsMetaTagsGet() {
return delegate.authenticatorsMetaTagsGet();
}

@Valid
@POST
@Path("/custom")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Create a new user defined local authenticator. ", notes = "This API provides the capability to create a new user defined local authenticator. <br> <b>Permission required:</b> <br> * /permission/admin/manage/custom_authenticator/create <br> <b>Scope required:</b> <br> * internal_custom_authenticator_create <br> ", response = Authenticator.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "User defined local authenticators", })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Successful response", response = Authenticator.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 = 409, message = "Conflict", response = Error.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
})
public Response addUserDefinedLocalAuthenticator(@ApiParam(value = "This represents the user defined local authenticator to be created." ,required=true) @Valid UserDefinedLocalAuthenticatorCreation userDefinedLocalAuthenticatorCreation) {

return delegate.addUserDefinedLocalAuthenticator(userDefinedLocalAuthenticatorCreation );
}

@Valid
@DELETE
@Path("/custom/{authenticator-id}")

@Produces({ "application/json" })
@ApiOperation(value = "Delete a user defined local authenticator. ", notes = "This API provides the capability to delete a user defined local authenticators. <br> <b>Permission required:</b> <br> * /permission/admin/manage/custom_authenticator/delete <br> <b>Scope required:</b> <br> * internal_custom_authenticator_delete <br> ", response = Void.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "User defined local authenticators", })
@ApiResponses(value = {
@ApiResponse(code = 204, message = "Successful response", response = Void.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 = 409, message = "Conflict", response = Error.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
})
public Response deleteUserDefinedLocalAuthenticator(@ApiParam(value = "ID of an authenticator",required=true) @PathParam("authenticator-id") String authenticatorId) {

return delegate.deleteUserDefinedLocalAuthenticator(authenticatorId );
}

@Valid
@GET
@Path("/{authenticator-id}/connected-apps")
Expand All @@ -101,7 +151,7 @@ public Response authenticatorsMetaTagsGet() {
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "Connected apps of local authenticators" })
}, tags={ "Connected apps of local authenticators", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful Response", response = ConnectedApps.class),
@ApiResponse(code = 400, message = "Bad Request", response = Error.class),
Expand All @@ -115,4 +165,28 @@ public Response getConnectedAppsOfLocalAuthenticator(@ApiParam(value = "ID of an
return delegate.getConnectedAppsOfLocalAuthenticator(authenticatorId, limit, offset );
}

@Valid
@PATCH
@Path("/custom/{authenticator-id}")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Update a user defined local authenticator. ", notes = "This API provides the capability to update a user defined local authenticator configurations. <br> <b>Permission required:</b> <br> * /permission/admin/manage/custom_authenticator/update <br> <b>Scope required:</b> <br> * internal_custom_authenticator_update <br> ", response = Authenticator.class, authorizations = {
@Authorization(value = "BasicAuth"),
@Authorization(value = "OAuth2", scopes = {

})
}, tags={ "User defined local authenticators" })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful response", response = Authenticator.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 = 409, message = "Conflict", response = Error.class),
@ApiResponse(code = 500, message = "Server Error", response = Error.class)
})
public Response updateUserDefinedLocalAuthenticator(@ApiParam(value = "ID of an authenticator",required=true) @PathParam("authenticator-id") String authenticatorId, @ApiParam(value = "This represents the user defined local authenticator to be created." ,required=true) @Valid UserDefinedLocalAuthenticatorUpdate userDefinedLocalAuthenticatorUpdate) {

return delegate.updateUserDefinedLocalAuthenticator(authenticatorId, userDefinedLocalAuthenticatorUpdate );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.ConnectedApps;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Error;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorCreation;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.UserDefinedLocalAuthenticatorUpdate;
import javax.ws.rs.core.Response;


Expand All @@ -34,5 +36,11 @@ public interface AuthenticatorsApiService {

public Response authenticatorsMetaTagsGet();

public Response addUserDefinedLocalAuthenticator(UserDefinedLocalAuthenticatorCreation userDefinedLocalAuthenticatorCreation);

public Response deleteUserDefinedLocalAuthenticator(String authenticatorId);

public Response getConnectedAppsOfLocalAuthenticator(String authenticatorId, Integer limit, Integer offset);

public Response updateUserDefinedLocalAuthenticator(String authenticatorId, UserDefinedLocalAuthenticatorUpdate userDefinedLocalAuthenticatorUpdate);
}
Loading

0 comments on commit 54a3aef

Please sign in to comment.