Search in sources :

Example 21 with RequestPathAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig in project identity-api-server by wso2.

the class ServerConfigManagementService method getAuthenticator.

/**
 * Get an authenticator identified by its resource ID.
 *
 * @param authenticatorId Authenticator resource ID.
 * @return Authenticator.
 */
public Authenticator getAuthenticator(String authenticatorId) {
    try {
        LocalAuthenticatorConfig authenticatorConfig = getAuthenticatorById(ConfigsServiceHolder.getInstance().getApplicationManagementService().getAllLocalAuthenticators(ContextLoader.getTenantDomainFromContext()), authenticatorId);
        if (authenticatorConfig != null) {
            return buildAuthenticatorResponse(authenticatorConfig);
        }
        RequestPathAuthenticatorConfig requestPathConfig = getAuthenticatorById(ConfigsServiceHolder.getInstance().getApplicationManagementService().getAllRequestPathAuthenticators(ContextLoader.getTenantDomainFromContext()), authenticatorId);
        if (requestPathConfig != null) {
            return buildAuthenticatorResponse(requestPathConfig);
        }
        throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_AUTHENTICATOR_NOT_FOUND, authenticatorId);
    } catch (IdentityApplicationManagementException e) {
        throw handleApplicationMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_AUTHENTICATOR, authenticatorId);
    }
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)

Example 22 with RequestPathAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig in project identity-api-server by wso2.

the class ServerConfigManagementService method buildAuthenticatorListResponse.

private List<AuthenticatorListItem> buildAuthenticatorListResponse(LocalAuthenticatorConfig[] localConfigs, RequestPathAuthenticatorConfig[] requestPathConfigs) {
    List<AuthenticatorListItem> authenticatorListItems = new ArrayList<>();
    if (localConfigs != null) {
        for (LocalAuthenticatorConfig config : localConfigs) {
            AuthenticatorListItem authenticatorListItem = new AuthenticatorListItem();
            String authenticatorId = base64URLEncode(config.getName());
            authenticatorListItem.setId(authenticatorId);
            authenticatorListItem.setName(config.getName());
            authenticatorListItem.setDisplayName(config.getDisplayName());
            authenticatorListItem.setIsEnabled(config.isEnabled());
            authenticatorListItem.setType(AuthenticatorListItem.TypeEnum.LOCAL);
            String[] tags = config.getTags();
            if (ArrayUtils.isNotEmpty(tags)) {
                authenticatorListItem.setTags(Arrays.asList(tags));
            }
            authenticatorListItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + CONFIGS_AUTHENTICATOR_PATH_COMPONENT + PATH_SEPERATOR + "%s", authenticatorId)).toString());
            authenticatorListItems.add(authenticatorListItem);
        }
    }
    if (requestPathConfigs != null) {
        for (RequestPathAuthenticatorConfig config : requestPathConfigs) {
            AuthenticatorListItem authenticatorListItem = new AuthenticatorListItem();
            String authenticatorId = base64URLEncode(config.getName());
            authenticatorListItem.setId(authenticatorId);
            authenticatorListItem.setName(config.getName());
            authenticatorListItem.setDisplayName(config.getDisplayName());
            authenticatorListItem.setIsEnabled(config.isEnabled());
            authenticatorListItem.setType(AuthenticatorListItem.TypeEnum.REQUEST_PATH);
            String[] tags = config.getTags();
            if (ArrayUtils.isNotEmpty(tags)) {
                authenticatorListItem.setTags(Arrays.asList(tags));
            }
            authenticatorListItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + CONFIGS_AUTHENTICATOR_PATH_COMPONENT + PATH_SEPERATOR + "%s", authenticatorId)).toString());
            authenticatorListItems.add(authenticatorListItem);
        }
    }
    return authenticatorListItems;
}
Also used : AuthenticatorListItem(org.wso2.carbon.identity.api.server.configs.v1.model.AuthenticatorListItem) ArrayList(java.util.ArrayList) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)

Example 23 with RequestPathAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig in project identity-api-server by wso2.

the class ServerConfigManagementService method buildAuthenticatorResponse.

private Authenticator buildAuthenticatorResponse(LocalAuthenticatorConfig config) {
    Authenticator authenticator = new Authenticator();
    authenticator.setId(base64URLEncode(config.getName()));
    authenticator.setName(config.getName());
    authenticator.setDisplayName(config.getDisplayName());
    authenticator.setIsEnabled(config.isEnabled());
    if (config instanceof RequestPathAuthenticatorConfig) {
        authenticator.setType(Authenticator.TypeEnum.REQUEST_PATH);
    } else {
        authenticator.setType(Authenticator.TypeEnum.LOCAL);
    }
    String[] tags = config.getTags();
    if (ArrayUtils.isNotEmpty(tags)) {
        authenticator.setTags(Arrays.asList(tags));
    }
    List<AuthenticatorProperty> authenticatorProperties = Arrays.stream(config.getProperties()).map(propertyToExternal).collect(Collectors.toList());
    authenticator.setProperties(authenticatorProperties);
    return authenticator;
}
Also used : AuthenticatorProperty(org.wso2.carbon.identity.api.server.configs.v1.model.AuthenticatorProperty) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) Authenticator(org.wso2.carbon.identity.api.server.configs.v1.model.Authenticator)

Aggregations

RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)16 ArrayList (java.util.ArrayList)8 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)8 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.xsd.RequestPathAuthenticatorConfig)7 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)6 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)5 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)5 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)5 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)5 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)4 SQLException (java.sql.SQLException)3 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)3 PreparedStatement (java.sql.PreparedStatement)2 BeforeClass (org.testng.annotations.BeforeClass)2 Test (org.testng.annotations.Test)2 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)2 FederatedApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator)2 LocalApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator)2 RequestPathApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.RequestPathApplicationAuthenticator)2 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)2