Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Nov 26, 2024
1 parent 4d242f4 commit 3d069a9
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5987,15 +5987,38 @@ public List<FederatedAuthenticatorConfig> getAllUserDefinedFederatedAuthenticato
federatedAuthenticatorConfig.setEnabled(resultSet.getBoolean("IS_ENABLED"));
federatedAuthenticatorConfig.setDefinedByType(DefinedByType.USER);
federatedAuthenticatorConfigs.add(federatedAuthenticatorConfig);
int authnId = resultSet.getInt("ID");

getFederatedProperties(connection, authnId, federatedAuthenticatorConfig);
}
}
IdentityDatabaseUtil.commitTransaction(connection);
return federatedAuthenticatorConfigs;
} catch (SQLException e) {
throw new IdentityProviderManagementException("Error occurred while retrieving all user defined federated " +
"authenticators for tenant: " + tenantId, e);
}
}

private void getFederatedProperties(Connection connection, int authnId,
FederatedAuthenticatorConfig federatedAuthenticatorConfig) throws SQLException{

try (PreparedStatement prepStmtProp = connection.prepareStatement(
IdPManagementConstants.SQLQueries.GET_IDP_AUTH_PROPS_SQL)) {
prepStmtProp.setInt(1, authnId);
Set<Property> properties = new HashSet<Property>();
try (ResultSet resultSetProp = prepStmtProp.executeQuery()) {
while (resultSetProp.next()) {
Property property = new Property();
property.setName(resultSetProp.getString(IdPManagementConstants.SQLConstants.PROPERTY_KEY));
property.setValue(resultSetProp.getString(IdPManagementConstants.SQLConstants.PROPERTY_VALUE));
properties.add(property);
}
federatedAuthenticatorConfig.setProperties(properties.toArray(new Property[properties.size()]));
}
}
}

private void resolveOtpConnectorProperties(
Map<String, IdentityProviderProperty> propertiesFromConnectors) throws ConnectorException{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public class IdPManagementConstants {
public static class SQLConstants {

public static final String DEFINED_BY_COLUMN = "DEFINED_BY";
public static final String PROPERTY_KEY = "PROPERTY_KEY";
public static final String PROPERTY_VALUE = "PROPERTY_VALUE";
}

public static class SQLQueries {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1445,20 +1445,6 @@ private FederatedAuthenticatorConfig federatedAuthenticatorConfigWithIdpEntityId
return federatedAuthenticatorConfig;
}

private UserDefinedAuthenticatorEndpointConfig buildUserDefinedAuthenticatorEndpointConfig(
EndpointConfig endpointConfig) {

UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfigBuilder =
new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder();
endpointConfigBuilder.uri(endpointConfig.getUri());
endpointConfigBuilder.authenticationType(endpointConfig.getAuthentication().getType().getName());
Map<String, String> propMap = new HashMap<>();
endpointConfig.getAuthentication().getProperties()
.forEach(prop -> propMap.put(prop.getName(), prop.getValue()));
endpointConfigBuilder.authenticationProperties(propMap);
return endpointConfigBuilder.build();
}

private void assertIdPResult(IdentityProvider idpResult) {

for (FederatedAuthenticatorConfig config : idpResult.getFederatedAuthenticatorConfigs()) {
Expand Down
Loading

0 comments on commit 3d069a9

Please sign in to comment.