
org.molgenis.data.security.exception.InsufficientPermissionsException Maven / Gradle / Ivy
package org.molgenis.data.security.exception;
import static java.util.Objects.requireNonNull;
import static org.molgenis.i18n.MessageSourceHolder.getMessageSource;
import static org.springframework.context.i18n.LocaleContextHolder.getLocale;
import java.util.ArrayList;
import java.util.List;
import org.springframework.security.acls.model.ObjectIdentity;
@SuppressWarnings("squid:MaximumInheritanceDepth")
public class InsufficientPermissionsException extends PermissionDeniedException {
private static final String ERROR_CODE = "DS26";
private final String identifier;
private final String type;
private final List roles;
public InsufficientPermissionsException(ObjectIdentity objectIdentity, List roles) {
super(ERROR_CODE);
requireNonNull(objectIdentity);
this.identifier = objectIdentity.getIdentifier().toString();
this.type = objectIdentity.getType();
this.roles = requireNonNull(roles);
}
public InsufficientPermissionsException(String type, String identifier, List roles) {
super(ERROR_CODE);
this.type = requireNonNull(type);
this.identifier = requireNonNull(identifier);
this.roles = requireNonNull(roles);
}
@Override
public String getMessage() {
return String.format("type:%s, identifier:%s, roles:%s", type, identifier, roles);
}
@Override
protected Object[] getLocalizedMessageArguments() {
List translatedRoles = new ArrayList<>();
for (String role : roles) {
String code = "role-" + role;
translatedRoles.add(getMessageSource().getMessage(code, null, getLocale()));
}
return new Object[] {type, identifier, String.join(",", translatedRoles)};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy