use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.
the class ServerIdpManagementService method createFederatedAuthenticatorConfig.
/**
* Create internal federated authenticator config from external federated authenticator PUT request.
*
* @param federatedAuthenticatorId Federated authenticator ID.
* @param authenticator Internal federated authenticator config.
* @return Federated authenticator config of the specified ID.
*/
private FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(String federatedAuthenticatorId, FederatedAuthenticatorPUTRequest authenticator) {
FederatedAuthenticatorConfig authConfig = new FederatedAuthenticatorConfig();
String authenticatorName = base64URLDecode(federatedAuthenticatorId);
authConfig.setName(authenticatorName);
authConfig.setDisplayName(getDisplayNameOfAuthenticator(authenticatorName));
authConfig.setEnabled(authenticator.getIsEnabled());
List<org.wso2.carbon.identity.api.server.idp.v1.model.Property> authProperties = authenticator.getProperties();
if (IdentityApplicationConstants.Authenticator.SAML2SSO.FED_AUTH_NAME.equals(authenticatorName)) {
validateSamlMetadata(authProperties);
}
List<Property> properties = authProperties.stream().map(propertyToInternal).collect(Collectors.toList());
authConfig.setProperties(properties.toArray(new Property[0]));
return authConfig;
}
use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.
the class ServerIdpManagementService method updateFederatedAuthenticator.
/**
* Update federated authenticator of and IDP.
*
* @param idpId Identity Provider resource ID.
* @param federatedAuthenticatorId Federated Authenticator ID.
* @param authenticator Federated Authenticator information.
* @return FederatedAuthenticator.
*/
public FederatedAuthenticator updateFederatedAuthenticator(String idpId, String federatedAuthenticatorId, FederatedAuthenticatorPUTRequest authenticator) {
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);
// Create new FederatedAuthenticatorConfig to store the federated authenticator information.
FederatedAuthenticatorConfig authConfig = createFederatedAuthenticatorConfig(federatedAuthenticatorId, authenticator);
FederatedAuthenticatorConfig[] fedAuthConfigs = createFederatedAuthenticatorArrayClone(federatedAuthenticatorId, idp.getFederatedAuthenticatorConfigs());
int configPos = getExistingAuthConfigPosition(fedAuthConfigs, federatedAuthenticatorId);
// If configPos != -1, modify the existing authenticatorConfig of IDP.
if (configPos != -1) {
fedAuthConfigs[configPos] = authConfig;
} else {
// If configPos is -1 add new authenticator to the list.
if (isValidAuthenticator(federatedAuthenticatorId)) {
List<FederatedAuthenticatorConfig> authConfigList = new ArrayList<>(Arrays.asList(fedAuthConfigs));
authConfigList.add(authConfig);
fedAuthConfigs = authConfigList.toArray(new FederatedAuthenticatorConfig[0]);
} else {
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_AUTHENTICATOR_NOT_FOUND_FOR_IDP, federatedAuthenticatorId);
}
}
idpToUpdate.setFederatedAuthenticatorConfigs(fedAuthConfigs);
if (authenticator.getIsDefault()) {
idpToUpdate.setDefaultAuthenticatorConfig(authConfig);
} else if (idpToUpdate.getDefaultAuthenticatorConfig() != null && idpToUpdate.getDefaultAuthenticatorConfig().getName().equals(authConfig.getName())) {
idpToUpdate.setDefaultAuthenticatorConfig(null);
}
IdentityProvider updatedIdP = IdentityProviderServiceHolder.getIdentityProviderManager().updateIdPByResourceId(idpId, idpToUpdate, ContextLoader.getTenantDomainFromContext());
return createFederatedAuthenticator(federatedAuthenticatorId, updatedIdP);
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP_AUTHENTICATOR, federatedAuthenticatorId);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.
the class ServerIdpManagementService method getMetaFederatedAuthenticators.
/**
* Get meta information about Identity Provider's federated authenticators.
*
* @return list of meta federated authenticators.
*/
public List<MetaFederatedAuthenticatorListItem> getMetaFederatedAuthenticators() {
List<MetaFederatedAuthenticatorListItem> metaAuthenticators = new ArrayList<>();
try {
FederatedAuthenticatorConfig[] authenticatorConfigs = IdentityProviderServiceHolder.getIdentityProviderManager().getAllFederatedAuthenticators();
if (ArrayUtils.isNotEmpty(authenticatorConfigs)) {
for (FederatedAuthenticatorConfig authenticatorConfig : authenticatorConfigs) {
MetaFederatedAuthenticatorListItem metaFederatedAuthenticator = createMetaFederatedAuthenticatorListItem(authenticatorConfig);
metaAuthenticators.add(metaFederatedAuthenticator);
}
}
return metaAuthenticators;
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_META_AUTHENTICATORS, null);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.
the class ServerIdpManagementService method getFederatedAuthenticator.
/**
* Get information of a specific federated authenticator of an IDP.
*
* @param idpId Identity Provider resource ID.
* @param authenticatorId Federated Authenticator ID.
* @return FederatedAuthenticator.
*/
public FederatedAuthenticator getFederatedAuthenticator(String idpId, String authenticatorId) {
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);
}
FederatedAuthenticatorConfig[] fedAuthConfigs = idp.getFederatedAuthenticatorConfigs();
if (fedAuthConfigs != null) {
for (FederatedAuthenticatorConfig config : fedAuthConfigs) {
if (StringUtils.equals(config.getName(), base64URLDecode(authenticatorId))) {
return createFederatedAuthenticator(authenticatorId, idp);
}
}
}
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_AUTHENTICATOR_NOT_FOUND_FOR_IDP, authenticatorId);
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_IDP_AUTHENTICATOR, authenticatorId);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.
the class ServerIdpManagementService method getMetaFederatedAuthenticator.
/**
* Get meta information about a specific federated authenticator supported by the IDPs.
*
* @param id Federated authenticator ID.
* @return MetaFederatedAuthenticator.
*/
public MetaFederatedAuthenticator getMetaFederatedAuthenticator(String id) {
MetaFederatedAuthenticator authenticator = null;
try {
String authenticatorName = decodeAuthenticatorID(id);
FederatedAuthenticatorConfig[] authenticatorConfigs = IdentityProviderServiceHolder.getIdentityProviderManager().getAllFederatedAuthenticators();
if (ArrayUtils.isNotEmpty(authenticatorConfigs)) {
for (FederatedAuthenticatorConfig authenticatorConfig : authenticatorConfigs) {
if (StringUtils.equals(authenticatorConfig.getName(), authenticatorName)) {
authenticator = createMetaFederatedAuthenticator(authenticatorConfig);
break;
}
}
}
return authenticator;
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_META_AUTHENTICATOR, id);
}
}
Aggregations