use of org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse in project identity-api-server by wso2.
the class ServerIdpManagementService method createFederatedAuthenticatorResponse.
private FederatedAuthenticatorListResponse createFederatedAuthenticatorResponse(IdentityProvider idp) {
FederatedAuthenticatorConfig[] fedAuthConfigs = idp.getFederatedAuthenticatorConfigs();
FederatedAuthenticatorListResponse fedAuthIDPResponse = new FederatedAuthenticatorListResponse();
List<FederatedAuthenticatorListItem> authenticators = new ArrayList<>();
for (FederatedAuthenticatorConfig fedAuthConfig : fedAuthConfigs) {
FederatedAuthenticatorListItem fedAuthListItem = new FederatedAuthenticatorListItem();
fedAuthListItem.setAuthenticatorId(base64URLEncode(fedAuthConfig.getName()));
fedAuthListItem.setName(fedAuthConfig.getName());
fedAuthListItem.setIsEnabled(fedAuthConfig.isEnabled());
FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(fedAuthConfig.getName());
if (federatedAuthenticatorConfig != null) {
String[] tags = federatedAuthenticatorConfig.getTags();
if (ArrayUtils.isNotEmpty(tags)) {
fedAuthListItem.setTags(Arrays.asList(tags));
}
}
fedAuthListItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/%s/federated-authenticators/%s", idp.getResourceId(), base64URLEncode(fedAuthConfig.getName()))).toString());
authenticators.add(fedAuthListItem);
}
fedAuthIDPResponse.setDefaultAuthenticatorId(idp.getDefaultAuthenticatorConfig() != null ? base64URLEncode(idp.getDefaultAuthenticatorConfig().getName()) : null);
fedAuthIDPResponse.setAuthenticators(authenticators);
return fedAuthIDPResponse;
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse in project identity-api-server by wso2.
the class ServerIdpManagementService method getFederatedAuthenticators.
/**
* Returns configured federated authenticators of a specific identity provider.
*
* @param idpId Identity provider resource ID.
* @return FederatedAuthenticatorListResponse Federated authenticator list.
*/
public FederatedAuthenticatorListResponse getFederatedAuthenticators(String idpId) {
FederatedAuthenticatorListResponse listResponse;
try {
IdentityProvider idP = IdentityProviderServiceHolder.getIdentityProviderManager().getIdPByResourceId(idpId, ContextLoader.getTenantDomainFromContext(), true);
if (idP == null) {
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_IDP_NOT_FOUND, idpId);
}
listResponse = new FederatedAuthenticatorListResponse();
FederatedAuthenticatorConfig[] fedAuthConfigs = idP.getFederatedAuthenticatorConfigs();
if (fedAuthConfigs != null) {
List<FederatedAuthenticatorListItem> fedAuthList = new ArrayList<>();
String defaultAuthenticator = null;
for (FederatedAuthenticatorConfig config : fedAuthConfigs) {
String fedAuthId = base64URLEncode(config.getName());
FederatedAuthenticatorListItem listItem = new FederatedAuthenticatorListItem();
listItem.setAuthenticatorId(fedAuthId);
listItem.setName(config.getName());
listItem.setIsEnabled(config.isEnabled());
FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(config.getName());
if (federatedAuthenticatorConfig != null) {
String[] tags = federatedAuthenticatorConfig.getTags();
if (ArrayUtils.isNotEmpty(tags)) {
listItem.setTags(Arrays.asList(tags));
}
}
listItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/%s/federated-authenticators/%s", idpId, fedAuthId)).toString());
fedAuthList.add(listItem);
if (idP.getDefaultAuthenticatorConfig() != null) {
defaultAuthenticator = base64URLEncode(idP.getDefaultAuthenticatorConfig().getName());
}
}
listResponse.setDefaultAuthenticatorId(defaultAuthenticator);
listResponse.setAuthenticators(fedAuthList);
}
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_IDP_AUTHENTICATORS, idpId);
}
return listResponse;
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse in project identity-api-server by wso2.
the class ServerIdpManagementService method updateFederatedAuthenticators.
/**
* Update federated authenticator of and IDP.
*
* @param idpId Identity Provider resource ID.
* @param authenticatorRequest Federated Authenticators Request.
* @return FederatedAuthenticatorListResponse.
*/
public FederatedAuthenticatorListResponse updateFederatedAuthenticators(String idpId, FederatedAuthenticatorRequest authenticatorRequest) {
try {
IdentityProvider idp = IdentityProviderServiceHolder.getIdentityProviderManager().getIdPByResourceId(idpId, ContextLoader.getTenantDomainFromContext(), true);
if (idp == null) {
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_IDP_NOT_FOUND, idpId);
}
// Need to create a clone, since modifying the fields of the original object, will modify the cached
// IDP object.
IdentityProvider idpToUpdate = createIdPClone(idp);
updateFederatedAuthenticatorConfig(idpToUpdate, authenticatorRequest);
IdentityProvider updatedIdp = IdentityProviderServiceHolder.getIdentityProviderManager().updateIdPByResourceId(idpId, idpToUpdate, ContextLoader.getTenantDomainFromContext());
return createFederatedAuthenticatorResponse(updatedIdp);
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP, null);
}
}
Aggregations