package gr.cite.annotation.model.censorship; import gr.cite.annotation.authorization.Permission; import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.model.Annotation; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.censor.CensorFactory; import gr.cite.tools.fieldset.FieldSet; import gr.cite.tools.logging.DataLogEntry; import gr.cite.tools.logging.LoggerService; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import java.util.UUID; @Component @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public class AnnotationCensor extends BaseCensor{ private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(AnnotationCensor.class)); protected final AuthorizationService authService; protected final CensorFactory censorFactory; public AnnotationCensor(ConventionService conventionService, AuthorizationService authService, CensorFactory censorFactory) { super(conventionService); this.authService = authService; this.censorFactory = censorFactory; } public void censor(FieldSet fields, UUID userId) { logger.debug(new DataLogEntry("censoring fields", fields)); if (fields == null || fields.isEmpty()) return; this.authService.authorizeForce(Permission.BrowseAnnotation, Permission.DeferredAffiliation); FieldSet authorFields = fields.extractPrefixed(this.asIndexerPrefix(Annotation._author)); this.censorFactory.censor(AnnotationAuthorCensor.class).censor(authorFields, userId); } }