Skip to content

Commit

Permalink
Merge branch '2024.06.x'
Browse files Browse the repository at this point in the history
* 2024.06.x:
  MCR-3214 Add handlings for non validatable pdf documents (#2299)
  MCR-3329 allow for absent additional values
  MCR-3246 Enable PMD rule UnnecessaryAnnotationValueElement (#2408)
  MCR-3241 enable PMD rule AvoidProtectedMethodInFinalClassNotExtending
  MCR-3269 enable PMD rule MIssingSerialVersionUID
  MCR-3332 revert MCR.LayoutService.TransformerFactoryClass to empty default (#2421)
  MCR-3332 big performance issues in MCRParameterCollector (#2416)
  MCR-3240 enable PMD rule AvoidProtectedFieldInFinalClass
  MCR-3264 Enable PMD rule AvoidDuplicateLiterals (#2401)
  MCR-3318 Enhance ORCID export check with trusted name identifiers (#2380)
  MCR-3283 Enable PMD rule DoubleCheckedLocking (#2407)
  • Loading branch information
yagee-de committed Feb 21, 2025
2 parents 9a73961 + 826a8fa commit 8246e17
Show file tree
Hide file tree
Showing 301 changed files with 3,535 additions and 1,702 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public final class MCRAccessKeyManager {
private static final int HASHING_ITERATIONS = MCRConfiguration2
.getInt(SECRET_STORAGE_MODE_PROP_PREFX + ".Hash.Iterations").orElse(1000);

private static final String PARAMETER_OBJECT_ID = "objectId";

private static final String PARAMETER_SECRET = "secret";

private static final String PARAMETER_TYPE = "type";

/**
* Returns all access keys for given {@link MCRObjectID}.
*
Expand All @@ -71,7 +77,7 @@ public final class MCRAccessKeyManager {
public static synchronized List<MCRAccessKey> listAccessKeys(final MCRObjectID objectId) {
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
final List<MCRAccessKey> accessKeys = em.createNamedQuery("MCRAccessKey.getWithObjectId", MCRAccessKey.class)
.setParameter("objectId", objectId.toString())
.setParameter(PARAMETER_OBJECT_ID, objectId.toString())
.getResultList();
for (MCRAccessKey accessKey : accessKeys) {
em.detach(accessKey);
Expand Down Expand Up @@ -219,7 +225,7 @@ public static void clearAccessKeys() {
public static void clearAccessKeys(final MCRObjectID objectId) {
MCREntityManagerProvider.getCurrentEntityManager()
.createNamedQuery("MCRAccessKey.clearWithObjectId")
.setParameter("objectId", objectId.toString())
.setParameter(PARAMETER_OBJECT_ID, objectId.toString())
.executeUpdate();
}

Expand All @@ -232,14 +238,10 @@ public static void clearAccessKeys(final MCRObjectID objectId) {
public static synchronized void removeAccessKey(final MCRObjectID objectId, final String secret)
throws MCRAccessKeyNotFoundException {
final MCRAccessKey accessKey = getAccessKeyWithSecret(objectId, secret);
if (accessKey == null) {
LOGGER.debug("Key does not exist.");
throw new MCRAccessKeyNotFoundException("Key does not exist.");
} else {
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
em.remove(em.contains(accessKey) ? accessKey : em.merge(accessKey));
}
checkAccessKey(accessKey);
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
em.remove(em.contains(accessKey) ? accessKey : em.merge(accessKey));
}

/**
Expand All @@ -253,36 +255,39 @@ public static synchronized void removeAccessKey(final MCRObjectID objectId, fina
public static synchronized void updateAccessKey(final MCRObjectID objectId, final String secret,
final MCRAccessKey updatedAccessKey) throws MCRException {
final MCRAccessKey accessKey = getAccessKeyWithSecret(objectId, secret);
if (accessKey != null) {
final String type = updatedAccessKey.getType();
if (type != null && !accessKey.getType().equals(type)) {
if (isValidType(type)) {
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
accessKey.setType(type);
} else {
LOGGER.debug("Unkown Type.");
throw new MCRAccessKeyInvalidTypeException("Unknown permission type.");
}
}
final Boolean isActive = updatedAccessKey.getIsActive();
if (isActive != null) {
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
accessKey.setIsActive(isActive);
}
final Date expiration = updatedAccessKey.getExpiration();
if (expiration != null) {
checkAccessKey(accessKey);
final String type = updatedAccessKey.getType();
if (type != null && !accessKey.getType().equals(type)) {
if (isValidType(type)) {
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
accessKey.setExpiration(expiration);
accessKey.setType(type);
} else {
LOGGER.debug("Unkown Type.");
throw new MCRAccessKeyInvalidTypeException("Unknown permission type.");
}
final String comment = updatedAccessKey.getComment();
if (comment != null) {
accessKey.setComment(comment);
}
accessKey.setLastModifiedBy(MCRSessionMgr.getCurrentSession().getUserInformation().getUserID());
accessKey.setLastModified(new Date());
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
em.merge(accessKey);
} else {
}
final Boolean isActive = updatedAccessKey.getIsActive();
if (isActive != null) {
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
accessKey.setIsActive(isActive);
}
final Date expiration = updatedAccessKey.getExpiration();
if (expiration != null) {
MCRAccessCacheHelper.clearAllPermissionCaches(objectId.toString());
accessKey.setExpiration(expiration);
}
final String comment = updatedAccessKey.getComment();
if (comment != null) {
accessKey.setComment(comment);
}
accessKey.setLastModifiedBy(MCRSessionMgr.getCurrentSession().getUserInformation().getUserID());
accessKey.setLastModified(new Date());
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
em.merge(accessKey);
}

private static void checkAccessKey(final MCRAccessKey accessKey) {
if(accessKey == null) {
LOGGER.debug("Key does not exist.");
throw new MCRAccessKeyNotFoundException("Key does not exist.");
}
Expand All @@ -298,8 +303,8 @@ public static synchronized void updateAccessKey(final MCRObjectID objectId, fina
public static synchronized MCRAccessKey getAccessKeyWithSecret(final MCRObjectID objectId, final String secret) {
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
final MCRAccessKey accessKey = em.createNamedQuery("MCRAccessKey.getWithSecret", MCRAccessKey.class)
.setParameter("objectId", objectId.toString())
.setParameter("secret", secret)
.setParameter(PARAMETER_OBJECT_ID, objectId.toString())
.setParameter(PARAMETER_SECRET, secret)
.getResultList()
.stream()
.findFirst()
Expand All @@ -321,12 +326,13 @@ public static synchronized List<MCRAccessKey> listAccessKeysWithType(final MCROb
final String type) {
final EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
final List<MCRAccessKey> accessKeys = em.createNamedQuery("MCRAccessKey.getWithType", MCRAccessKey.class)
.setParameter("objectId", objectId.toString())
.setParameter("type", type)
.setParameter(PARAMETER_OBJECT_ID, objectId.toString())
.setParameter(PARAMETER_TYPE, type)
.getResultList();
for (MCRAccessKey accessKey : accessKeys) {
em.detach(accessKey);
}
return accessKeys;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.mycore.common.MCRSessionMgr;
import org.mycore.common.MCRUserInformation;
import org.mycore.common.config.MCRConfiguration2;
import org.mycore.datamodel.metadata.MCRDerivate;
import org.mycore.datamodel.metadata.MCRMetadataManager;
import org.mycore.datamodel.metadata.MCRObjectID;
import org.mycore.mcr.acl.accesskey.exception.MCRAccessKeyException;
Expand Down Expand Up @@ -123,7 +124,7 @@ public static synchronized void addAccessKeySecret(final MCRSession session, fin
if (!isAccessKeyForSessionAllowed()) {
throw new MCRAccessKeyException("Access keys is not allowed.");
}
if ("derivate".equals(objectId.getTypeId())) {
if (MCRDerivate.OBJECT_TYPE.equals(objectId.getTypeId())) {
addAccessKeySecretForObject(session, objectId, value);
} else {
boolean success = false;
Expand Down Expand Up @@ -185,7 +186,7 @@ public static synchronized void addAccessKeySecretForObject(final MCRUser user,
*/
public static synchronized void addAccessKeySecret(final MCRUser user, final MCRObjectID objectId,
final String value) throws MCRException {
if ("derivate".equals(objectId.getTypeId())) {
if (MCRDerivate.OBJECT_TYPE.equals(objectId.getTypeId())) {
addAccessKeySecretForObject(user, objectId, value);
} else {
boolean success = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.mycore.mcr.acl.accesskey.dto.util;

import java.io.IOException;
import java.io.Serial;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -40,6 +41,7 @@
*/
public class MCRNullableDeserializer<T> extends StdDeserializer<MCRNullable<T>> implements ContextualDeserializer {

@Serial
private static final long serialVersionUID = 1L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to a collision of access keys.
* This refers to secret duplicates.
*/
public class MCRAccessKeyCollisionException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyCollisionException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to a disabled access key.
*/
public class MCRAccessKeyDisabledException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyDisabledException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

import org.mycore.common.MCRException;

import java.io.Serial;

/**
* Instances of this class represent a general exception related to access keys.
*/
public class MCRAccessKeyException extends MCRException {

@Serial
private static final long serialVersionUID = 1L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to an expired access key.
*/
public class MCRAccessKeyExpiredException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyExpiredException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to an invalid secret.
*/
public class MCRAccessKeyInvalidSecretException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyInvalidSecretException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to an invalid permission type.
*/
public class MCRAccessKeyInvalidTypeException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyInvalidTypeException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to an unknown access key.
*/
public class MCRAccessKeyNotFoundException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyNotFoundException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception that refers to an error during transformation of an access key.
*/
public class MCRAccessKeyTransformationException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

public MCRAccessKeyTransformationException(String errorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.mycore.mcr.acl.accesskey.exception;

import java.io.Serial;

/**
* Exception thrown when an access key validation fails.
*
Expand All @@ -27,6 +29,7 @@
*/
public class MCRAccessKeyValidationException extends MCRAccessKeyException {

@Serial
private static final long serialVersionUID = 1L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

/**
* Access keys for a reference.
* <p>
* Access keys contains a secret and a type.
* <p>
* Value is the key secret of the key and type the permission.
*/
@NamedQueries({
@NamedQuery(name = "MCRAccessKey.getWithObjectId",
query = "SELECT k"
Expand Down Expand Up @@ -80,15 +87,10 @@
@NamedQuery(name = MCRAccessKeyNamedQueries.NAME_FIND_ALL,
query = "SELECT k FROM MCRAccessKey k"),
})

/**
* Access keys for a reference.
* An access keys contains a secret and a type.
* Value is the key secret of the key and type the permission.
*/
@Entity
@Table(name = "MCRAccessKey")
@JsonInclude(JsonInclude.Include.NON_NULL)
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class MCRAccessKey {

/** The unique and internal information id */
Expand Down
Loading

0 comments on commit 8246e17

Please sign in to comment.