use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class ProvisioningManagementDAO method updateProvisionedIdentifier.
/**
* @param newIdentityProvider
* @param currentIdentityProvider
* @param tenantId
* @throws IdentityApplicationManagementException
*/
public void updateProvisionedIdentifier(IdentityProvider newIdentityProvider, IdentityProvider currentIdentityProvider, int tenantId) throws IdentityApplicationManagementException {
Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
PreparedStatement prepStmt = null;
try {
int idPId = getIdentityProviderIdByName(dbConnection, newIdentityProvider.getIdentityProviderName(), tenantId);
if (idPId <= 0) {
String msg = "Trying to update non-existent Identity Provider for tenant " + tenantId;
throw new IdentityApplicationManagementException(msg);
}
// SP_IDP_NAME=?, SP_IDP_PRIMARY=?,SP_IDP_HOME_REALM_ID=?,
// SP_IDP_THUMBPRINT=?,
// SP_IDP_TOKEN_EP_ALIAS=?,
// SP_IDP_INBOUND_PROVISIONING_ENABLED=?,SP_IDP_INBOUND_PROVISIONING_USER_STORE_ID=?,SP_IDP_USER_CLAIM_URI=?,
// SP_IDP_ROLE_CLAIM_URI=?,SP_IDP_DEFAULT_AUTHENTICATOR_NAME=?,SP_IDP_DEFAULT_PRO_CONNECTOR_NAME=?
String sqlStmt = IdPManagementConstants.SQLQueries.UPDATE_IDP_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setString(1, newIdentityProvider.getIdentityProviderName());
if (newIdentityProvider.isPrimary()) {
prepStmt.setString(2, IdentityProvisioningConstants.IS_TRUE_VALUE);
} else {
prepStmt.setString(2, IdentityProvisioningConstants.IS_FALSE_VALUE);
}
prepStmt.setString(3, newIdentityProvider.getHomeRealmId());
JSONArray certificateInfoJsonArray = new JSONArray(newIdentityProvider.getCertificateInfoArray());
prepStmt.setBinaryStream(4, setBlobValue(certificateInfoJsonArray.toString()));
if (log.isDebugEnabled()) {
log.debug("Certificate has been saved in the database as a JSON array: " + certificateInfoJsonArray);
}
prepStmt.setString(5, newIdentityProvider.getAlias());
if (newIdentityProvider.getJustInTimeProvisioningConfig() != null && newIdentityProvider.getJustInTimeProvisioningConfig().isProvisioningEnabled()) {
prepStmt.setString(6, IdentityProvisioningConstants.IS_TRUE_VALUE);
prepStmt.setString(7, newIdentityProvider.getJustInTimeProvisioningConfig().getProvisioningUserStore());
} else {
prepStmt.setString(6, IdentityProvisioningConstants.IS_FALSE_VALUE);
prepStmt.setString(7, null);
}
if (newIdentityProvider.getClaimConfig() != null) {
prepStmt.setString(8, newIdentityProvider.getClaimConfig().getUserClaimURI());
prepStmt.setString(9, newIdentityProvider.getClaimConfig().getRoleClaimURI());
} else {
prepStmt.setString(8, null);
prepStmt.setString(9, null);
}
// update the default authenticator
if (newIdentityProvider.getDefaultAuthenticatorConfig() != null && newIdentityProvider.getDefaultAuthenticatorConfig().getName() != null) {
prepStmt.setString(10, newIdentityProvider.getDefaultAuthenticatorConfig().getName());
} else {
// its not a must to have a default authenticator.
prepStmt.setString(10, null);
}
// update the default provisioning connector.
if (newIdentityProvider.getDefaultProvisioningConnectorConfig() != null && newIdentityProvider.getDefaultProvisioningConnectorConfig().getName() != null) {
prepStmt.setString(11, newIdentityProvider.getDefaultProvisioningConnectorConfig().getName());
} else {
// its not a must to have a default provisioning connector..
prepStmt.setString(11, null);
}
prepStmt.setString(12, newIdentityProvider.getIdentityProviderDescription());
prepStmt.setInt(13, tenantId);
prepStmt.setString(14, currentIdentityProvider.getIdentityProviderName());
prepStmt.executeUpdate();
prepStmt.clearParameters();
IdentityDatabaseUtil.commitTransaction(dbConnection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
String msg = "Error occurred while updating Identity Provider information for tenant " + tenantId;
throw new IdentityApplicationManagementException(msg, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt);
}
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class FileBasedConfigurationBuilder method processStepElement.
/**
* Create StepDOs for each step entry
*
* @param stepElem
* @return
*/
private StepConfig processStepElement(OMElement stepElem) {
StepConfig stepConfig = new StepConfig();
OMAttribute loginPageAttr = stepElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_STEP_LOGIN_PAGE));
if (loginPageAttr != null) {
stepConfig.setLoginPage(loginPageAttr.getAttributeValue());
}
OMAttribute orderAttr = stepElem.getAttribute(new QName(FrameworkConstants.Config.ATTR_STEP_ORDER));
if (orderAttr == null) {
log.warn("Each Step Configuration should have an order. +" + "Authenticators under this Step will not be registered.");
return null;
}
stepConfig.setOrder(Integer.parseInt(orderAttr.getAttributeValue()));
for (Iterator authenticatorElements = stepElem.getChildrenWithLocalName(FrameworkConstants.Config.ELEM_AUTHENTICATOR); authenticatorElements.hasNext(); ) {
OMElement authenticatorElem = (OMElement) authenticatorElements.next();
String authenticatorName = authenticatorElem.getAttributeValue(new QName(FrameworkConstants.Config.ATTR_AUTHENTICATOR_NAME));
AuthenticatorConfig authenticatorConfig = authenticatorConfigMap.get(authenticatorName);
String idps = authenticatorElem.getAttributeValue(new QName(FrameworkConstants.Config.ATTR_AUTHENTICATOR_IDPS));
if (authenticatorConfig == null) {
log.error("There was no authenticator configured for name: " + authenticatorName + " Please add relevant configuration in element: " + FrameworkConstants.Config.QNAME_AUTHENTICATOR_CONFIGS);
} else {
// if IDP defined
if (idps != null && !idps.isEmpty()) {
String[] idpArr = idps.split(",");
for (String idp : idpArr) {
authenticatorConfig.getIdpNames().add(idp);
}
} else {
authenticatorConfig.getIdpNames().add(FrameworkConstants.LOCAL_IDP_NAME);
}
stepConfig.getAuthenticatorList().add(authenticatorConfig);
}
}
return stepConfig;
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class UIBasedConfigurationLoader method loadStepAuthenticator.
private void loadStepAuthenticator(StepConfig stepConfig, IdentityProvider idp, String authenticatorName) {
AuthenticatorConfig authenticatorConfig = null;
// check if authenticator already exists
for (AuthenticatorConfig authConfig : stepConfig.getAuthenticatorList()) {
if (authenticatorName.equals(authConfig.getName())) {
authenticatorConfig = authConfig;
break;
}
}
if (authenticatorConfig == null) {
authenticatorConfig = new AuthenticatorConfig();
authenticatorConfig.setName(authenticatorName);
for (ApplicationAuthenticator appAuthenticator : FrameworkServiceComponent.getAuthenticators()) {
if (authenticatorName.equalsIgnoreCase(appAuthenticator.getName())) {
authenticatorConfig.setApplicationAuthenticator(appAuthenticator);
break;
}
}
stepConfig.getAuthenticatorList().add(authenticatorConfig);
}
if (idp != null) {
authenticatorConfig.getIdpNames().add(idp.getIdentityProviderName());
authenticatorConfig.getIdps().put(idp.getIdentityProviderName(), idp);
}
if (!stepConfig.isMultiOption() && (stepConfig.getAuthenticatorList().size() > 1 || authenticatorConfig.getIdps().size() > 1)) {
stepConfig.setMultiOption(true);
}
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class JsGraphBuilder method authenticatorParamsOptions.
/**
* Add authenticator params in the message context.
*
* @param options Authentication options
*/
protected void authenticatorParamsOptions(Map<String, Object> options, StepConfig stepConfig) {
Map<String, Map<String, String>> authenticatorParams = new HashMap<>();
Object localOptions = options.get(FrameworkConstants.JSAttributes.JS_LOCAL_IDP);
if (localOptions instanceof Map) {
((Map<String, Object>) localOptions).forEach((authenticatorName, params) -> {
if (params instanceof Map) {
authenticatorParams.put(authenticatorName, new HashMap<>((Map<String, String>) params));
}
});
}
Object federatedOptionsObj = options.get(FrameworkConstants.JSAttributes.JS_FEDERATED_IDP);
if (federatedOptionsObj instanceof Map) {
Map<String, Map<String, String>> federatedOptions = (Map<String, Map<String, String>>) federatedOptionsObj;
stepConfig.getAuthenticatorList().forEach(authenticatorConfig -> authenticatorConfig.getIdps().forEach((idpName, idp) -> {
if (!FrameworkConstants.LOCAL_IDP_NAME.equals(idpName) && federatedOptions.containsKey(idpName)) {
for (FederatedAuthenticatorConfig federatedAuthConfig : idp.getFederatedAuthenticatorConfigs()) {
String authenticatorName = authenticatorConfig.getApplicationAuthenticator().getName();
if (authenticatorConfig.getName().equals(federatedAuthConfig.getName())) {
authenticatorParams.put(authenticatorName, new HashMap<>(federatedOptions.get(idpName)));
}
}
}
}));
}
Object commonOptions = options.get(FrameworkConstants.JSAttributes.JS_COMMON_OPTIONS);
if (commonOptions instanceof Map) {
authenticatorParams.put(FrameworkConstants.JSAttributes.JS_COMMON_OPTIONS, new HashMap<>((Map<String, String>) commonOptions));
}
if (!authenticatorParams.isEmpty()) {
authenticationContext.addAuthenticatorParams(authenticatorParams);
}
}
use of org.wso2.carbon.identity.api.server.authenticators.v1.model.Authenticator in project carbon-identity-framework by wso2.
the class JsClaims method getRemoteClaimMappedToLocalClaim.
/**
* Gets the remote claim that is mapped to the given local claim
*
* @param localClaim local claim URI
* @param remoteClaimsMap Remote claim URI - value map
* @return Mapped remote claim URI if present. null otherwise
*/
private String getRemoteClaimMappedToLocalClaim(String localClaim, Map<String, String> remoteClaimsMap) {
String authenticatorDialect = null;
Map<String, String> localToIdpClaimMapping = null;
String tenantDomain = getContext().getTenantDomain();
try {
// Check if the IDP use an standard dialect (like oidc), If it does, dialect claim mapping are
// prioritized over IdP claim mapping
ApplicationAuthenticator authenticator = getContext().getSequenceConfig().getStepMap().get(step).getAuthenticatedAutenticator().getApplicationAuthenticator();
authenticatorDialect = authenticator.getClaimDialectURI();
ExternalIdPConfig idPConfig = ConfigurationFacade.getInstance().getIdPConfigByName(idp, tenantDomain);
boolean useDefaultIdpDialect = idPConfig.useDefaultLocalIdpDialect();
if (authenticatorDialect != null || useDefaultIdpDialect) {
if (authenticatorDialect == null) {
authenticatorDialect = ApplicationConstants.LOCAL_IDP_DEFAULT_CLAIM_DIALECT;
}
localToIdpClaimMapping = ClaimMetadataHandler.getInstance().getMappingsMapFromOtherDialectToCarbon(authenticatorDialect, remoteClaimsMap.keySet(), tenantDomain, true);
} else {
localToIdpClaimMapping = IdentityProviderManager.getInstance().getMappedIdPClaimsMap(idp, tenantDomain, Collections.singletonList(localClaim));
}
if (localToIdpClaimMapping != null) {
return localToIdpClaimMapping.get(localClaim);
}
} catch (IdentityProviderManagementException e) {
LOG.error(String.format("Error when getting claim : %s of user: %s", localClaim, authenticatedUser), e);
} catch (ClaimMetadataException e) {
LOG.error("Error when getting claim mappings from " + authenticatorDialect + " for tenant domain: " + tenantDomain);
}
return null;
}
Aggregations