use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class RegistryRecoveryDataStore method deleteOldConfirmationCodesByRegistrySearch.
private void deleteOldConfirmationCodesByRegistrySearch(Registry registry, String username, String confirmationCodePath) {
Map<String, String> fields = new HashMap<>();
fields.put(REGISTRY_SEARCH_FIELD_PROPERTY_NAME, UserRecoveryDataStore.USER_ID);
/*
Convert the username to lowercase as 'userId' property always includes the lowercase username.
@see #store
*/
fields.put(REGISTRT_SEARCH_FIELD_RIGHT_PROPERTY_VALUE, username.toLowerCase());
fields.put(REGISTRY_SEARCH_FIELD_RIGHT_OP, REGISTRY_SEARCH_FIELD_RIGHT_OP_EQ);
ResourceData[] searchResults = null;
try {
searchResults = IdentityMgtServiceComponent.getAttributeSearchService().search(fields);
} catch (RegistryException e) {
log.error("Error while deleting the old confirmation code. Unable to search resources in registry " + "for: [" + REGISTRY_SEARCH_FIELD_PROPERTY_NAME + " - " + UserRecoveryDataStore.USER_ID + ", " + REGISTRT_SEARCH_FIELD_RIGHT_PROPERTY_VALUE + " - " + username + ", " + REGISTRY_SEARCH_FIELD_RIGHT_OP + " - " + REGISTRY_SEARCH_FIELD_RIGHT_OP_EQ + "]", e);
}
if (searchResults != null && !ArrayUtils.isEmpty(searchResults)) {
if (log.isDebugEnabled()) {
log.debug("Found: " + searchResults.length + " no of resources for search: [" + REGISTRY_SEARCH_FIELD_PROPERTY_NAME + " - " + UserRecoveryDataStore.USER_ID + ", " + REGISTRT_SEARCH_FIELD_RIGHT_PROPERTY_VALUE + " - " + username + ", " + REGISTRY_SEARCH_FIELD_RIGHT_OP + " - " + REGISTRY_SEARCH_FIELD_RIGHT_OP_EQ + "]");
}
for (ResourceData resource : searchResults) {
String resourcePath = resource.getResourcePath();
if (resourcePath != null && resourcePath.contains(confirmationCodePath)) {
if (log.isDebugEnabled()) {
log.debug("Matching resource found for user: " + username + " at resource path : " + resource.getResourcePath());
}
String resourcePathRelativeToConfigRegistry = resource.getResourcePath().substring(RegistryConstants.CONFIG_REGISTRY_BASE_PATH.length());
deleteRegistryResource(registry, resourcePathRelativeToConfigRegistry);
}
}
} else {
if (log.isDebugEnabled()) {
if (log.isDebugEnabled()) {
log.debug("No registry resource found for search: [" + REGISTRY_SEARCH_FIELD_PROPERTY_NAME + " - " + "" + "" + "" + UserRecoveryDataStore.USER_ID + ", " + REGISTRT_SEARCH_FIELD_RIGHT_PROPERTY_VALUE + " - " + username + ", " + REGISTRY_SEARCH_FIELD_RIGHT_OP + " - " + REGISTRY_SEARCH_FIELD_RIGHT_OP_EQ + "]");
}
}
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getIdPNameByMetadataProperty.
/**
* Retrieves the first matching IDP for the given metadata property.
* Intended to ony be used to retrieve IDP name based on a unique metadata property.
*
* @param dbConnection Optional. DB connection.
* @param property IDP metadata property name.
* @param value Value associated with given Property.
* @param tenantId Tenant id whose information is requested.
* @return Identity Provider name.
* @throws IdentityProviderManagementException IdentityProviderManagementException.
*/
public String getIdPNameByMetadataProperty(Connection dbConnection, String property, String value, int tenantId) throws IdentityProviderManagementException {
PreparedStatement prepStmt = null;
ResultSet rs = null;
boolean dbConnectionInitialized = true;
if (dbConnection == null) {
dbConnection = IdentityDatabaseUtil.getDBConnection(false);
} else {
dbConnectionInitialized = false;
}
try {
String sqlStmt = isH2DB() ? IdPManagementConstants.SQLQueries.GET_IDP_NAME_BY_METADATA_H2 : IdPManagementConstants.SQLQueries.GET_IDP_NAME_BY_METADATA;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setString(1, property);
prepStmt.setString(2, value);
prepStmt.setInt(3, tenantId);
rs = prepStmt.executeQuery();
String idPName = null;
if (rs.next()) {
idPName = rs.getString(1);
}
return idPName;
} catch (DataAccessException | SQLException e) {
throw new IdentityProviderManagementException("Error occurred while retrieving Identity Provider " + "information for IDP metadata property name: " + property + " value: " + value, e);
} finally {
if (dbConnectionInitialized) {
IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
} else {
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
}
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getFederatedAuthenticatorConfigs.
/**
* @param dbConnection
* @param idPName
* @param tenantId
* @return
* @throws IdentityProviderManagementException
* @throws SQLException
*/
private FederatedAuthenticatorConfig[] getFederatedAuthenticatorConfigs(Connection dbConnection, String idPName, IdentityProvider federatedIdp, int tenantId) throws IdentityProviderManagementException, SQLException {
int idPId = getIdentityProviderIdentifier(dbConnection, idPName, tenantId);
PreparedStatement prepStmt1 = null;
PreparedStatement prepStmt2 = null;
ResultSet rs = null;
ResultSet proprs = null;
String defaultAuthName = null;
if (federatedIdp != null && federatedIdp.getDefaultAuthenticatorConfig() != null) {
defaultAuthName = federatedIdp.getDefaultAuthenticatorConfig().getName();
}
String sqlStmt = IdPManagementConstants.SQLQueries.GET_ALL_IDP_AUTH_SQL;
Set<FederatedAuthenticatorConfig> federatedAuthenticatorConfigs = new HashSet<FederatedAuthenticatorConfig>();
try {
prepStmt1 = dbConnection.prepareStatement(sqlStmt);
prepStmt1.setInt(1, idPId);
rs = prepStmt1.executeQuery();
while (rs.next()) {
FederatedAuthenticatorConfig authnConfig = new FederatedAuthenticatorConfig();
int authnId = rs.getInt("ID");
authnConfig.setName(rs.getString("NAME"));
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_ENABLED"))) {
authnConfig.setEnabled(true);
} else {
authnConfig.setEnabled(false);
}
authnConfig.setDisplayName(rs.getString("DISPLAY_NAME"));
if (defaultAuthName != null && authnConfig.getName().equals(defaultAuthName)) {
federatedIdp.getDefaultAuthenticatorConfig().setDisplayName(authnConfig.getDisplayName());
}
sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_AUTH_PROPS_SQL;
prepStmt2 = dbConnection.prepareStatement(sqlStmt);
prepStmt2.setInt(1, authnId);
proprs = prepStmt2.executeQuery();
Set<Property> properties = new HashSet<Property>();
while (proprs.next()) {
Property property = new Property();
property.setName(proprs.getString("PROPERTY_KEY"));
property.setValue(proprs.getString("PROPERTY_VALUE"));
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(proprs.getString("IS_SECRET"))) {
property.setConfidential(true);
}
properties.add(property);
}
authnConfig.setProperties(properties.toArray(new Property[properties.size()]));
federatedAuthenticatorConfigs.add(authnConfig);
}
return federatedAuthenticatorConfigs.toArray(new FederatedAuthenticatorConfig[federatedAuthenticatorConfigs.size()]);
} finally {
IdentityDatabaseUtil.closeAllConnections(null, proprs, prepStmt2);
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt1);
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method updateSingleValuedFederatedConfigProperties.
private void updateSingleValuedFederatedConfigProperties(Connection dbConnection, int authnId, int tenantId, List<Property> singleValuedProperties) throws SQLException {
PreparedStatement prepStmt2 = null;
PreparedStatement prepStmt3 = null;
String sqlStmt;
try {
for (Property property : singleValuedProperties) {
sqlStmt = IdPManagementConstants.SQLQueries.UPDATE_IDP_AUTH_PROP_SQL;
prepStmt2 = dbConnection.prepareStatement(sqlStmt);
prepStmt2.setString(1, property.getValue());
if (property.isConfidential()) {
prepStmt2.setString(2, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepStmt2.setString(2, IdPManagementConstants.IS_FALSE_VALUE);
}
prepStmt2.setInt(3, authnId);
prepStmt2.setString(4, property.getName());
int rows = prepStmt2.executeUpdate();
if (rows == 0) {
// this should be an insert.
sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_AUTH_PROP_SQL;
prepStmt3 = dbConnection.prepareStatement(sqlStmt);
prepStmt3.setInt(1, authnId);
prepStmt3.setInt(2, tenantId);
prepStmt3.setString(3, property.getName());
prepStmt3.setString(4, property.getValue());
if (property.isConfidential()) {
prepStmt3.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepStmt3.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
}
prepStmt3.executeUpdate();
}
}
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt3);
IdentityDatabaseUtil.closeStatement(prepStmt2);
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getProvisioningConnectorConfigs.
/**
* @param dbConnection
* @param idPName
* @param tenantId
* @return
* @throws IdentityProviderManagementException
* @throws SQLException
*/
public ProvisioningConnectorConfig[] getProvisioningConnectorConfigs(Connection dbConnection, String idPName, int idPId, int tenantId) throws IdentityProviderManagementException, SQLException {
PreparedStatement prepStmt = null;
PreparedStatement prepBaseStmt = null;
ResultSet rs1 = null;
ResultSet rs2 = null;
try {
// SP_IDP_PROV_CONNECTOR_TYPE,SP_IDP_PROV_CONFIG_KEY,
// SP_IDP_PROV_CONFIG_VALUE,SP_IDP_PROV_CONFIG_IS_SECRET
String sqlBaseStmt = IdPManagementConstants.SQLQueries.GET_IDP_PROVISIONING_CONFIGS_SQL;
prepBaseStmt = dbConnection.prepareStatement(sqlBaseStmt);
prepBaseStmt.setInt(1, idPId);
rs1 = prepBaseStmt.executeQuery();
Map<String, ProvisioningConnectorConfig> provisioningConnectorMap = new HashMap<String, ProvisioningConnectorConfig>();
while (rs1.next()) {
ProvisioningConnectorConfig provisioningConnector;
String type = rs1.getString("PROVISIONING_CONNECTOR_TYPE");
if (!provisioningConnectorMap.containsKey(type)) {
provisioningConnector = new ProvisioningConnectorConfig();
provisioningConnector.setName(type);
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs1.getString("IS_ENABLED"))) {
provisioningConnector.setEnabled(true);
} else {
provisioningConnector.setEnabled(false);
}
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs1.getString("IS_BLOCKING"))) {
provisioningConnector.setBlocking(true);
} else {
provisioningConnector.setBlocking(false);
}
if (provisioningConnector.getProvisioningProperties() == null || provisioningConnector.getProvisioningProperties().length == 0) {
String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_PROVISIONING_PROPERTY_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
int configId = rs1.getInt("ID");
prepStmt.setInt(1, tenantId);
prepStmt.setInt(2, configId);
rs2 = prepStmt.executeQuery();
List<Property> provisioningProperties = new ArrayList<Property>();
while (rs2.next()) {
Property property = new Property();
String name = rs2.getString("PROPERTY_KEY");
String value = rs2.getString("PROPERTY_VALUE");
String blobValue = getBlobValue(rs2.getBinaryStream("PROPERTY_BLOB_VALUE"));
String propertyType = rs2.getString("PROPERTY_TYPE");
String isSecret = rs2.getString("IS_SECRET");
property.setName(name);
if (propertyType != null && IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_BLOB.equals(propertyType.trim())) {
property.setValue(blobValue);
} else {
property.setValue(value);
}
property.setType(propertyType);
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(isSecret)) {
property.setConfidential(true);
} else {
property.setConfidential(false);
}
provisioningProperties.add(property);
}
provisioningConnector.setProvisioningProperties(provisioningProperties.toArray(new Property[provisioningProperties.size()]));
}
provisioningConnectorMap.put(type, provisioningConnector);
}
}
return provisioningConnectorMap.values().toArray(new ProvisioningConnectorConfig[provisioningConnectorMap.size()]);
} finally {
IdentityDatabaseUtil.closeAllConnections(null, rs2, prepBaseStmt);
IdentityDatabaseUtil.closeAllConnections(null, rs1, prepStmt);
}
}
Aggregations