Skip to content

Commit

Permalink
Improve /authenticators/custom endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Dec 14, 2024
1 parent ba3a3b0 commit e550b2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.authenticators.v1.AuthenticatorsApiService;
import org.wso2.carbon.identity.api.server.authenticators.v1.core.ServerAuthenticatorManagementService;
import org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator;
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.common.ContextLoader;

import java.net.URI;
import javax.ws.rs.core.Response;

import static org.wso2.carbon.identity.api.server.common.Constants.V1_API_PATH_COMPONENT;

/**
* Implementation of the Server Authenticators Rest API.
*/
Expand All @@ -48,8 +53,11 @@ public Response authenticatorsMetaTagsGet() {
public Response addUserDefinedLocalAuthenticator(
UserDefinedLocalAuthenticatorCreation userDefinedLocalAuthenticatorCreation) {

return Response.ok().entity(authenticatorManagementService
.addUserDefinedLocalAuthenticator(userDefinedLocalAuthenticatorCreation)).build();
Authenticator response = authenticatorManagementService
.addUserDefinedLocalAuthenticator(userDefinedLocalAuthenticatorCreation);
URI location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT +
"/authenticator/custom/" + response.getId());
return Response.created(location).entity(response).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ public class LocalAuthenticatorConfigBuilderFactory {
public static Authenticator build(UserDefinedLocalAuthenticatorConfig config) {

Authenticator authenticator = new Authenticator();
String authenticatorId = base64URLEncode(config.getName());
authenticator.setName(config.getName());
authenticator.setId(base64URLEncode(config.getName()));
authenticator.setId(authenticatorId);
authenticator.setDisplayName(config.getDisplayName());
authenticator.setIsEnabled(config.isEnabled());
authenticator.setDefinedBy(Authenticator.DefinedByEnum.USER);
authenticator.setType(Authenticator.TypeEnum.LOCAL);
authenticator.setTags(Arrays.asList(config.getTags()));
authenticator.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT +
CONFIGS_AUTHENTICATOR_PATH_COMPONENT, config.getName())).toString());
CONFIGS_AUTHENTICATOR_PATH_COMPONENT, authenticatorId)).toString());

return authenticator;
}
Expand Down

0 comments on commit e550b2c

Please sign in to comment.