mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 02:29:03 +00:00 
			
		
		
		
	Fix Sonar cloud flagged issues (#4987)
This commit is contained in:
		
							parent
							
								
									0ba22c1d2f
								
							
						
					
					
						commit
						9cab223a6f
					
				| @ -763,7 +763,7 @@ public abstract class EntityRepository<T extends EntityInterface> { | |||||||
|       from = toId; |       from = toId; | ||||||
|       to = fromId; |       to = fromId; | ||||||
|     } |     } | ||||||
|     return daoCollection.relationshipDAO().insert(fromId, toId, fromEntity, toEntity, relationship.ordinal(), json); |     return daoCollection.relationshipDAO().insert(from, to, fromEntity, toEntity, relationship.ordinal(), json); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public List<String> findBoth(UUID entity1, String entityType1, Relationship relationship, String entity2) { |   public List<String> findBoth(UUID entity1, String entityType1, Relationship relationship, String entity2) { | ||||||
|  | |||||||
| @ -31,7 +31,6 @@ import java.util.UUID; | |||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.openmetadata.catalog.Entity; | import org.openmetadata.catalog.Entity; | ||||||
| import org.openmetadata.catalog.entity.data.MlModel; | import org.openmetadata.catalog.entity.data.MlModel; | ||||||
| import org.openmetadata.catalog.jdbi3.EntityRepository.EntityUpdater; |  | ||||||
| import org.openmetadata.catalog.resources.mlmodels.MlModelResource; | import org.openmetadata.catalog.resources.mlmodels.MlModelResource; | ||||||
| import org.openmetadata.catalog.type.EntityReference; | import org.openmetadata.catalog.type.EntityReference; | ||||||
| import org.openmetadata.catalog.type.Include; | import org.openmetadata.catalog.type.Include; | ||||||
|  | |||||||
| @ -215,7 +215,7 @@ public class UserRepository extends EntityRepository<User> { | |||||||
|     List<String> teamIds = findFrom(user.getId(), Entity.USER, Relationship.HAS, Entity.TEAM); |     List<String> teamIds = findFrom(user.getId(), Entity.USER, Relationship.HAS, Entity.TEAM); | ||||||
|     List<EntityReference> teams = EntityUtil.populateEntityReferences(teamIds, Entity.TEAM); |     List<EntityReference> teams = EntityUtil.populateEntityReferences(teamIds, Entity.TEAM); | ||||||
|     // return only the non-deleted teams |     // return only the non-deleted teams | ||||||
|     return teams.stream().filter((team) -> !team.getDeleted()).collect(Collectors.toList()); |     return teams.stream().filter(team -> !team.getDeleted()).collect(Collectors.toList()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private void assignRoles(User user, List<EntityReference> roles) { |   private void assignRoles(User user, List<EntityReference> roles) { | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity | |||||||
|   protected final Authorizer authorizer; |   protected final Authorizer authorizer; | ||||||
|   private final boolean supportsOwner; |   private final boolean supportsOwner; | ||||||
| 
 | 
 | ||||||
|   public EntityResource(Class<T> entityClass, K repository, Authorizer authorizer) { |   protected EntityResource(Class<T> entityClass, K repository, Authorizer authorizer) { | ||||||
|     this.entityClass = entityClass; |     this.entityClass = entityClass; | ||||||
|     allowedFields = Entity.getAllowedFields(entityClass); |     allowedFields = Entity.getAllowedFields(entityClass); | ||||||
|     supportsOwner = allowedFields.contains(FIELD_OWNER); |     supportsOwner = allowedFields.contains(FIELD_OWNER); | ||||||
|  | |||||||
| @ -17,7 +17,6 @@ import static org.openmetadata.catalog.security.SecurityUtil.ADMIN; | |||||||
| import static org.openmetadata.catalog.security.SecurityUtil.BOT; | import static org.openmetadata.catalog.security.SecurityUtil.BOT; | ||||||
| import static org.openmetadata.catalog.security.SecurityUtil.OWNER; | import static org.openmetadata.catalog.security.SecurityUtil.OWNER; | ||||||
| 
 | 
 | ||||||
| import com.fasterxml.jackson.annotation.JsonPropertyOrder; |  | ||||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||||
| import io.swagger.v3.oas.annotations.ExternalDocumentation; | import io.swagger.v3.oas.annotations.ExternalDocumentation; | ||||||
| import io.swagger.v3.oas.annotations.Operation; | import io.swagger.v3.oas.annotations.Operation; | ||||||
| @ -28,8 +27,6 @@ import io.swagger.v3.oas.annotations.media.Schema; | |||||||
| import io.swagger.v3.oas.annotations.parameters.RequestBody; | import io.swagger.v3.oas.annotations.parameters.RequestBody; | ||||||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.util.ArrayList; |  | ||||||
| import java.util.Arrays; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Objects; | import java.util.Objects; | ||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
| @ -79,11 +76,6 @@ public class FeedResource { | |||||||
|   private final FeedRepository dao; |   private final FeedRepository dao; | ||||||
|   private final Authorizer authorizer; |   private final Authorizer authorizer; | ||||||
| 
 | 
 | ||||||
|   private static List<String> getAllowedFields() { |  | ||||||
|     JsonPropertyOrder propertyOrder = Thread.class.getAnnotation(JsonPropertyOrder.class); |  | ||||||
|     return new ArrayList<>(Arrays.asList(propertyOrder.value())); |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   public static List<Thread> addHref(UriInfo uriInfo, List<Thread> threads) { |   public static List<Thread> addHref(UriInfo uriInfo, List<Thread> threads) { | ||||||
|     threads.forEach(t -> addHref(uriInfo, t)); |     threads.forEach(t -> addHref(uriInfo, t)); | ||||||
|     return threads; |     return threads; | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ package org.openmetadata.catalog.resources.metrics; | |||||||
| 
 | 
 | ||||||
| import static org.openmetadata.catalog.security.SecurityUtil.ADMIN; | import static org.openmetadata.catalog.security.SecurityUtil.ADMIN; | ||||||
| import static org.openmetadata.catalog.security.SecurityUtil.BOT; | import static org.openmetadata.catalog.security.SecurityUtil.BOT; | ||||||
|  | import static org.openmetadata.catalog.security.SecurityUtil.OWNER; | ||||||
| 
 | 
 | ||||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||||
| import io.swagger.v3.oas.annotations.Operation; | import io.swagger.v3.oas.annotations.Operation; | ||||||
| @ -173,7 +174,7 @@ public class MetricsResource extends EntityResource<Metrics, MetricsRepository> | |||||||
|   public Response createOrUpdate( |   public Response createOrUpdate( | ||||||
|       @Context UriInfo uriInfo, @Context SecurityContext securityContext, @Valid Metrics metrics) throws IOException { |       @Context UriInfo uriInfo, @Context SecurityContext securityContext, @Valid Metrics metrics) throws IOException { | ||||||
|     addToMetrics(securityContext, metrics); |     addToMetrics(securityContext, metrics); | ||||||
|     return createOrUpdate(uriInfo, securityContext, metrics); |     return createOrUpdate(uriInfo, securityContext, metrics, ADMIN | BOT | OWNER); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private void addToMetrics(SecurityContext securityContext, Metrics metrics) { |   private void addToMetrics(SecurityContext securityContext, Metrics metrics) { | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ package org.openmetadata.catalog.resources.reports; | |||||||
| 
 | 
 | ||||||
| import static org.openmetadata.catalog.security.SecurityUtil.ADMIN; | import static org.openmetadata.catalog.security.SecurityUtil.ADMIN; | ||||||
| import static org.openmetadata.catalog.security.SecurityUtil.BOT; | import static org.openmetadata.catalog.security.SecurityUtil.BOT; | ||||||
|  | import static org.openmetadata.catalog.security.SecurityUtil.OWNER; | ||||||
| 
 | 
 | ||||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||||
| import io.swagger.v3.oas.annotations.Operation; | import io.swagger.v3.oas.annotations.Operation; | ||||||
| @ -165,7 +166,7 @@ public class ReportResource extends EntityResource<Report, ReportRepository> { | |||||||
|   public Response createOrUpdate( |   public Response createOrUpdate( | ||||||
|       @Context UriInfo uriInfo, @Context SecurityContext securityContext, @Valid Report report) throws IOException { |       @Context UriInfo uriInfo, @Context SecurityContext securityContext, @Valid Report report) throws IOException { | ||||||
|     addToReport(securityContext, report); |     addToReport(securityContext, report); | ||||||
|     return createOrUpdate(uriInfo, securityContext, report); |     return createOrUpdate(uriInfo, securityContext, report, ADMIN | BOT | OWNER); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private void addToReport(SecurityContext securityContext, Report report) { |   private void addToReport(SecurityContext securityContext, Report report) { | ||||||
|  | |||||||
| @ -47,9 +47,7 @@ import javax.ws.rs.core.SecurityContext; | |||||||
| import javax.ws.rs.core.UriInfo; | import javax.ws.rs.core.UriInfo; | ||||||
| import org.openmetadata.catalog.Entity; | import org.openmetadata.catalog.Entity; | ||||||
| import org.openmetadata.catalog.api.services.CreateDatabaseService; | import org.openmetadata.catalog.api.services.CreateDatabaseService; | ||||||
| import org.openmetadata.catalog.api.services.DatabaseConnection; |  | ||||||
| import org.openmetadata.catalog.entity.services.DatabaseService; | import org.openmetadata.catalog.entity.services.DatabaseService; | ||||||
| import org.openmetadata.catalog.fernet.Fernet; |  | ||||||
| import org.openmetadata.catalog.jdbi3.CollectionDAO; | import org.openmetadata.catalog.jdbi3.CollectionDAO; | ||||||
| import org.openmetadata.catalog.jdbi3.DatabaseServiceRepository; | import org.openmetadata.catalog.jdbi3.DatabaseServiceRepository; | ||||||
| import org.openmetadata.catalog.jdbi3.ListFilter; | import org.openmetadata.catalog.jdbi3.ListFilter; | ||||||
| @ -72,7 +70,6 @@ public class DatabaseServiceResource extends EntityResource<DatabaseService, Dat | |||||||
|   public static final String COLLECTION_PATH = "v1/services/databaseServices/"; |   public static final String COLLECTION_PATH = "v1/services/databaseServices/"; | ||||||
| 
 | 
 | ||||||
|   static final String FIELDS = "pipelines,owner"; |   static final String FIELDS = "pipelines,owner"; | ||||||
|   private final Fernet fernet; |  | ||||||
| 
 | 
 | ||||||
|   @Override |   @Override | ||||||
|   public DatabaseService addHref(UriInfo uriInfo, DatabaseService service) { |   public DatabaseService addHref(UriInfo uriInfo, DatabaseService service) { | ||||||
| @ -84,7 +81,6 @@ public class DatabaseServiceResource extends EntityResource<DatabaseService, Dat | |||||||
| 
 | 
 | ||||||
|   public DatabaseServiceResource(CollectionDAO dao, Authorizer authorizer) { |   public DatabaseServiceResource(CollectionDAO dao, Authorizer authorizer) { | ||||||
|     super(DatabaseService.class, new DatabaseServiceRepository(dao), authorizer); |     super(DatabaseService.class, new DatabaseServiceRepository(dao), authorizer); | ||||||
|     this.fernet = Fernet.getInstance(); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public static class DatabaseServiceList extends ResultList<DatabaseService> { |   public static class DatabaseServiceList extends ResultList<DatabaseService> { | ||||||
| @ -357,18 +353,4 @@ public class DatabaseServiceResource extends EntityResource<DatabaseService, Dat | |||||||
|         .withUpdatedBy(securityContext.getUserPrincipal().getName()) |         .withUpdatedBy(securityContext.getUserPrincipal().getName()) | ||||||
|         .withUpdatedAt(System.currentTimeMillis()); |         .withUpdatedAt(System.currentTimeMillis()); | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
|   private void validateDatabaseConnection( |  | ||||||
|       DatabaseConnection databaseConnection, CreateDatabaseService.DatabaseServiceType databaseServiceType) { |  | ||||||
|     try { |  | ||||||
|       Object connectionConfig = databaseConnection.getConfig(); |  | ||||||
|       String clazzName = |  | ||||||
|           "org.openmetadata.catalog.services.connections.database." + databaseServiceType.value() + "Connection"; |  | ||||||
|       Class<?> clazz = Class.forName(clazzName); |  | ||||||
|       JsonUtils.convertValue(connectionConfig, clazz); |  | ||||||
|     } catch (Exception e) { |  | ||||||
|       throw new RuntimeException( |  | ||||||
|           String.format("Failed to construct connection instance of %s", databaseServiceType.value())); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -79,11 +79,11 @@ class ConfigResourceTest extends CatalogApplicationTest { | |||||||
|     WebTarget target = getConfigResource("jwks"); |     WebTarget target = getConfigResource("jwks"); | ||||||
|     JWKSResponse auth = TestUtils.get(target, JWKSResponse.class, TEST_AUTH_HEADERS); |     JWKSResponse auth = TestUtils.get(target, JWKSResponse.class, TEST_AUTH_HEADERS); | ||||||
|     assertNotNull(auth); |     assertNotNull(auth); | ||||||
|     assertEquals(auth.getJwsKeys().size(), 1); |     assertEquals(1, auth.getJwsKeys().size()); | ||||||
|     JWKSKey jwksKey = auth.getJwsKeys().get(0); |     JWKSKey jwksKey = auth.getJwsKeys().get(0); | ||||||
|     assertEquals(jwksKey.getAlg(), "RS256"); |     assertEquals("RS256", jwksKey.getAlg()); | ||||||
|     assertEquals(jwksKey.getUse(), "sig"); |     assertEquals("sig", jwksKey.getUse()); | ||||||
|     assertEquals(jwksKey.getKty(), "RSA"); |     assertEquals("RSA", jwksKey.getKty()); | ||||||
|     assertNotNull(jwksKey.getN()); |     assertNotNull(jwksKey.getN()); | ||||||
|     assertNotNull(jwksKey.getE()); |     assertNotNull(jwksKey.getE()); | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -694,13 +694,13 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> { | |||||||
|     Date date = jwt.getExpiresAt(); |     Date date = jwt.getExpiresAt(); | ||||||
|     long daysBetween = ((date.getTime() - jwt.getIssuedAt().getTime()) / (1000 * 60 * 60 * 24)); |     long daysBetween = ((date.getTime() - jwt.getIssuedAt().getTime()) / (1000 * 60 * 60 * 24)); | ||||||
|     assertTrue(daysBetween >= 6); |     assertTrue(daysBetween >= 6); | ||||||
|     assertEquals(jwt.getClaims().get("sub").asString(), "ingestion-bot-jwt"); |     assertEquals("ingestion-bot-jwt", jwt.getClaims().get("sub").asString()); | ||||||
|     assertEquals(jwt.getClaims().get("isBot").asBoolean(), true); |     assertEquals(true, jwt.getClaims().get("isBot").asBoolean()); | ||||||
|     TestUtils.put(getResource(String.format("users/revokeToken/%s", user.getId())), User.class, OK, ADMIN_AUTH_HEADERS); |     TestUtils.put(getResource(String.format("users/revokeToken/%s", user.getId())), User.class, OK, ADMIN_AUTH_HEADERS); | ||||||
|     jwtAuthMechanism = |     jwtAuthMechanism = | ||||||
|         TestUtils.get( |         TestUtils.get( | ||||||
|             getResource(String.format("users/token/%s", user.getId())), JWTAuthMechanism.class, ADMIN_AUTH_HEADERS); |             getResource(String.format("users/token/%s", user.getId())), JWTAuthMechanism.class, ADMIN_AUTH_HEADERS); | ||||||
|     assertEquals(jwtAuthMechanism.getJWTToken(), StringUtils.EMPTY); |     assertEquals(StringUtils.EMPTY, jwtAuthMechanism.getJWTToken()); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private DecodedJWT decodedJWT(String token) throws MalformedURLException, JwkException, HttpResponseException { |   private DecodedJWT decodedJWT(String token) throws MalformedURLException, JwkException, HttpResponseException { | ||||||
|  | |||||||
| @ -53,7 +53,7 @@ public class JWTTokenGeneratorTest { | |||||||
|             .withDisplayName("ingestion-bot"); |             .withDisplayName("ingestion-bot"); | ||||||
|     JWTAuthMechanism jwtAuthMechanism = jwtTokenGenerator.generateJWTToken(user, JWTTokenExpiry.Seven); |     JWTAuthMechanism jwtAuthMechanism = jwtTokenGenerator.generateJWTToken(user, JWTTokenExpiry.Seven); | ||||||
|     DecodedJWT jwt = decodedJWT(jwtAuthMechanism.getJWTToken()); |     DecodedJWT jwt = decodedJWT(jwtAuthMechanism.getJWTToken()); | ||||||
|     assertEquals(jwt.getClaims().get("sub").asString(), "ingestion-bot"); |     assertEquals("ingestion-bot", jwt.getClaims().get("sub").asString()); | ||||||
|     Date date = jwt.getExpiresAt(); |     Date date = jwt.getExpiresAt(); | ||||||
|     long daysBetween = ((date.getTime() - jwt.getIssuedAt().getTime()) / (1000 * 60 * 60 * 24)); |     long daysBetween = ((date.getTime() - jwt.getIssuedAt().getTime()) / (1000 * 60 * 60 * 24)); | ||||||
|     assertTrue(daysBetween >= 6); |     assertTrue(daysBetween >= 6); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Suresh Srinivas
						Suresh Srinivas