Skip to content

Commit

Permalink
chore: ORM filter logging changes and message issue on id_token (#7273)
Browse files Browse the repository at this point in the history
* feat: publish Lock message on id_token issue/revoke #7244

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>

* chore: don't dump ORM filter jdbc types exception #7272

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>

---------

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>
Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
  • Loading branch information
yurem and moabu committed Jan 5, 2024
1 parent cb14f46 commit 9978877
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void mergeSilently(TokenEntity token) {
public void persist(TokenEntity token) {
persistenceEntryManager.persist(token);

if (TokenType.ID_TOKEN.equals(token.getTokenType())) {
if (TokenType.ID_TOKEN.getValue().equals(token.getTokenType())) {
publishIdTokenLockMessage(token, "add");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.jans.lock.service.consumer.message.opa;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
Expand Down Expand Up @@ -135,7 +137,7 @@ private boolean putData(JsonNode messageNode) {
// request.addHeader("Content-Type", "application/json");
request.addHeader("If-None-Match", "*");

StringEntity stringEntity = new StringEntity("{}", "application/json");
StringEntity stringEntity = new StringEntity("{}", ContentType.APPLICATION_JSON);
request.setEntity(stringEntity);

try (CloseableHttpClient httpClient = httpService.getHttpsClient();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
Expand Down Expand Up @@ -105,7 +106,7 @@ public boolean putPolicies(String sourceUri, List<String> policies) {
String baseUrl = appConfiguration.getOpaConfiguration().getBaseUrl();
HttpPut request = new HttpPut(String.format("%s/policies/%s", baseUrl, policyId));

StringEntity stringEntity = new StringEntity(policy, "text/plain");
StringEntity stringEntity = new StringEntity(policy, ContentType.TEXT_PLAIN);
request.setEntity(stringEntity);

try (CloseableHttpClient httpClient = httpService.getHttpsClient();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package io.jans.orm.sql.impl;

import java.sql.JDBCType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -66,11 +67,21 @@ public class SqlFilterConverter {
private Path<Object> objectDocAlias = ExpressionUtils.path(Object.class, "doc");

public static String[] SPECIAL_REGEX_CHARACTERS = new String[] { "\\", "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}" };

private Map<String, JDBCType> jdbcEnumTypesMap;


public SqlFilterConverter(SqlOperationService operationService) {
this.operationService = operationService;
this.dbType = operationService.getConnectionProvider().getDbType();
initJdbcEnumTypesMap();
}

private void initJdbcEnumTypesMap() {
jdbcEnumTypesMap = new HashMap<>();
for( JDBCType sqlType : JDBCType.class.getEnumConstants()) {
jdbcEnumTypesMap.put(StringHelper.toLowerCase(sqlType.name()) , sqlType);
}
}

public ConvertedExpression convertToSqlFilter(TableMapping tableMapping, Filter genericFilter, Map<String, PropertyAnnotation> propertiesAnnotationsMap) throws SearchException {
Expand Down Expand Up @@ -493,29 +504,31 @@ private Object prepareTypedExpressionValue(TableMapping tableMapping, Filter fil
assertionValue = dateValue;
}
}
try {
if (attributeType != null) {
String columnType = attributeType.getType();

java.sql.JDBCType jdbcType;
// Fix for PostgreSQL
if (StringHelper.equalsIgnoreCase(columnType, "bool")) {
jdbcType = java.sql.JDBCType.BOOLEAN;

if (attributeType != null) {
String columnType = attributeType.getType();

java.sql.JDBCType jdbcType = null;
// Fix for PostgreSQL
if (StringHelper.equalsIgnoreCase(columnType, "bool")) {
jdbcType = java.sql.JDBCType.BOOLEAN;
} else {
String lowerCaseColumnType = StringHelper.toLowerCase(columnType);
if (jdbcEnumTypesMap.containsKey(lowerCaseColumnType)) {
jdbcType = jdbcEnumTypesMap.get(lowerCaseColumnType);
} else {
jdbcType = java.sql.JDBCType.valueOf(StringHelper.toUpperCase(columnType));
}

if (jdbcType == java.sql.JDBCType.SMALLINT) {
boolean res = StringHelper.equalsIgnoreCase((String) assertionValue, "true") || StringHelper.equalsIgnoreCase((String) assertionValue, "1");
assertionValue = res ? 1 : 0;
} else if (jdbcType == java.sql.JDBCType.BOOLEAN) {
boolean res = StringHelper.equalsIgnoreCase((String) assertionValue, "true") || StringHelper.equalsIgnoreCase((String) assertionValue, "1");
assertionValue = res;
LOG.trace("Failed to determine JDBC type '{}' ", attributeType.getType());
// Do nothing. Type is not defined in enum
}
}
} catch (java.lang.IllegalArgumentException ex) {
LOG.trace("Failed to determine JDBC type '{}' ", attributeType.getType(), ex);
// Do nothing. Type is not defined in enum

if (jdbcType == java.sql.JDBCType.SMALLINT) {
boolean res = StringHelper.equalsIgnoreCase((String) assertionValue, "true") || StringHelper.equalsIgnoreCase((String) assertionValue, "1");
assertionValue = res ? 1 : 0;
} else if (jdbcType == java.sql.JDBCType.BOOLEAN) {
boolean res = StringHelper.equalsIgnoreCase((String) assertionValue, "true") || StringHelper.equalsIgnoreCase((String) assertionValue, "1");
assertionValue = res;
}
}
}

Expand Down

0 comments on commit 9978877

Please sign in to comment.