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;
}
}
}
}
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations