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

New API /authenticators/custom to manage user defined local authenticators #736

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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 getApplicationAuthenticatorService() {

return AuthenticatorsServiceHolder.getInstance().applicationAuthenticatorService;
}

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

AuthenticatorsServiceHolder.getInstance().applicationAuthenticatorService = applicationAuthenticatorService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private Constants() {
public static final String AUTHENTICATOR_ERROR_PREFIX = "AUT-";
public static final String FEDERATED_AUTHENTICATORS = "federatedAuthenticators";
public static final String AUTHENTICATOR_PATH_COMPONENT = "/authenticators";
public static final String CONFIGS_AUTHENTICATOR_PATH_COMPONENT = "/configs/authenticators/%s";
public static final String PATH_SEPERATOR = "/";
public static final String PAGE_LINK_REL_NEXT = "next";
public static final String PAGE_LINK_REL_PREVIOUS = "previous";
Expand Down Expand Up @@ -70,6 +71,11 @@ 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_INVALID_ENDPOINT_CONFIG("60003", "Invalid endpoint configuration provided.",
"Invalid endpoint configuration is provided for the authenticator %s."),
ERROR_CODE_ERROR_AUTHENTICATOR_NOT_FOUND("60004", "Authenticator not found.",
"Authenticator not found by the given name: %s."),

malithie marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -42,6 +44,29 @@ public class AuthenticatorsApi {
@Autowired
private AuthenticatorsApiService delegate;

@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 = 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
@GET

Expand Down Expand Up @@ -91,6 +116,29 @@ public Response authenticatorsMetaTagsGet() {
return delegate.authenticatorsMetaTagsGet();
}

@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 = 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 +149,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 +163,27 @@ public Response getConnectedAppsOfLocalAuthenticator(@ApiParam(value = "ID of an
return delegate.getConnectedAppsOfLocalAuthenticator(authenticatorId, limit, offset );
}

@Valid
@PUT
@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 = 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,14 +25,22 @@
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;


public interface AuthenticatorsApiService {

public Response addUserDefinedLocalAuthenticator(UserDefinedLocalAuthenticatorCreation userDefinedLocalAuthenticatorCreation);

public Response authenticatorsGet(String filter, Integer limit, Integer offset);

public Response authenticatorsMetaTagsGet();

public Response deleteUserDefinedLocalAuthenticator(String authenticatorId);

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

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