Search in sources :

Example 26 with LocalAuthenticatorConfig

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

the class ServerAuthenticatorManagementService method filterTags.

/**
 * Adds local authenticator to the list of authenticators if it satisfies the given filter.
 *
 * @param config         The local authenticator configuration.
 * @param authenticators The list of authenticators.
 * @param filterTagsList The list of tags passed in the filter string.
 */
private void filterTags(LocalAuthenticatorConfig config, List<Authenticator> authenticators, ArrayList<String> filterTagsList) {
    boolean tagFound = false;
    for (String filterTag : filterTagsList) {
        if (tagFound) {
            break;
        }
        String[] authenticatorConfigTags = config.getTags();
        if (ArrayUtils.isNotEmpty(authenticatorConfigTags)) {
            for (String tag : authenticatorConfigTags) {
                if (StringUtils.equalsIgnoreCase(tag, filterTag)) {
                    Authenticator authenticator = addLocalAuthenticator(config);
                    authenticators.add(authenticator);
                    tagFound = true;
                    break;
                }
            }
        }
    }
}
Also used : Authenticator(org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator)

Example 27 with LocalAuthenticatorConfig

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

the class ServerAuthenticatorManagementService method addLocalAuthenticator.

private Authenticator addLocalAuthenticator(LocalAuthenticatorConfig config) {
    Authenticator authenticator = new Authenticator();
    String authenticatorId = base64URLEncode(config.getName());
    authenticator.setId(authenticatorId);
    authenticator.setName(config.getName());
    authenticator.setDisplayName(config.getDisplayName());
    authenticator.setIsEnabled(config.isEnabled());
    authenticator.setType(Authenticator.TypeEnum.LOCAL);
    String[] tags = config.getTags();
    if (ArrayUtils.isNotEmpty(tags)) {
        authenticator.setTags(Arrays.asList(tags));
    }
    authenticator.setSelf(ContextLoader.buildURIForBody(String.format("/v1/configs/authenticators/%s", authenticatorId)).toString());
    return authenticator;
}
Also used : Authenticator(org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator)

Example 28 with LocalAuthenticatorConfig

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

the class ServerAuthenticatorManagementService method buildAuthenticatorsListResponse.

private List<Authenticator> buildAuthenticatorsListResponse(String filter, List<String> requestedAttributeList, String localAuthNames, String authenticatorNameFilterOperator, ArrayList<String> filterTagsList, LocalAuthenticatorConfig[] localAuthenticatorConfigs, RequestPathAuthenticatorConfig[] requestPathAuthenticatorConfigs, List<IdentityProvider> identityProviders) {
    int maximumItemsPerPage = IdentityUtil.getMaximumItemPerPage();
    List<Authenticator> authenticators = new ArrayList<>();
    if (localAuthenticatorConfigs != null) {
        for (LocalAuthenticatorConfig config : localAuthenticatorConfigs) {
            addLocalAuthenticator(config, authenticators, localAuthNames, authenticatorNameFilterOperator, filterTagsList, maximumItemsPerPage);
        }
    }
    if ((authenticators.size() < maximumItemsPerPage) && requestPathAuthenticatorConfigs != null) {
        for (RequestPathAuthenticatorConfig config : requestPathAuthenticatorConfigs) {
            addLocalAuthenticator(config, authenticators, localAuthNames, authenticatorNameFilterOperator, filterTagsList, maximumItemsPerPage);
        }
    }
    if (StringUtils.isBlank(filter)) {
        if ((authenticators.size() < maximumItemsPerPage) && identityProviders != null) {
            for (IdentityProvider identityProvider : identityProviders) {
                if (authenticators.size() < maximumItemsPerPage) {
                    List<String> configTagsListDistinct = getDistinctTags(identityProvider);
                    addIdp(identityProvider, authenticators, configTagsListDistinct);
                }
            }
        }
    } else {
        List<ExpressionNode> expressionNodesForIdp = getExpressionNodesForIdp(filter);
        int idPCountToBeRetrieved = maximumItemsPerPage - authenticators.size();
        IdpSearchResult idpSearchResult;
        try {
            idpSearchResult = AuthenticatorsServiceHolder.getInstance().getIdentityProviderManager().getIdPs(idPCountToBeRetrieved, null, null, null, ContextLoader.getTenantDomainFromContext(), requestedAttributeList, expressionNodesForIdp);
            identityProviders = idpSearchResult.getIdPs();
            if (identityProviders != null) {
                addIdPsToAuthenticatorList(maximumItemsPerPage, identityProviders, authenticators, filterTagsList);
                int limit = idpSearchResult.getLimit();
                int offSet = idpSearchResult.getOffSet();
                int totalIdpCount = idpSearchResult.getTotalIDPCount();
                while (authenticators.size() < maximumItemsPerPage && limit > 0 && offSet >= 0 && totalIdpCount > (limit + offSet)) {
                    identityProviders = new ArrayList<>();
                    getFilteredIdPs(limit, offSet, requestedAttributeList, identityProviders, expressionNodesForIdp);
                    addIdPsToAuthenticatorList(maximumItemsPerPage, identityProviders, authenticators, filterTagsList);
                    offSet = offSet + limit;
                }
            }
        } catch (IdentityProviderManagementException e) {
            throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_LISTING_IDPS, null);
        }
    }
    return authenticators;
}
Also used : ArrayList(java.util.ArrayList) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdpSearchResult(org.wso2.carbon.idp.mgt.model.IdpSearchResult) ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) Authenticator(org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator)

Example 29 with LocalAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig 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 30 with LocalAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig 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)

Aggregations

LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)19 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)11 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)9 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)8 AuthenticationStep (org.wso2.carbon.identity.application.common.model.xsd.AuthenticationStep)8 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.xsd.LocalAuthenticatorConfig)8 ArrayList (java.util.ArrayList)7 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)7 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.LocalAndOutboundAuthenticationConfig)6 HashMap (java.util.HashMap)4 AuthenticatorConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)4 Map (java.util.Map)3 Authenticator (org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator)3 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)3 Property (org.wso2.carbon.identity.application.common.model.Property)3 IOException (java.io.IOException)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2