51 lines
1.9 KiB
Java
51 lines
1.9 KiB
Java
package gr.cite.notification.model.censorship;
|
|
|
|
import gr.cite.commons.web.authz.service.AuthorizationService;
|
|
import gr.cite.notification.authorization.OwnedResource;
|
|
import gr.cite.notification.authorization.Permission;
|
|
import gr.cite.notification.convention.ConventionService;
|
|
import gr.cite.notification.model.UserContactInfo;
|
|
import gr.cite.tools.data.censor.CensorFactory;
|
|
import gr.cite.tools.exception.MyForbiddenException;
|
|
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.annotation.Autowired;
|
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
@Component
|
|
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
public class UserContactInfoCensor extends BaseCensor {
|
|
|
|
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserContactInfoCensor.class));
|
|
|
|
protected final AuthorizationService authService;
|
|
protected final CensorFactory censorFactory;
|
|
|
|
@Autowired
|
|
public UserContactInfoCensor(
|
|
ConventionService conventionService,
|
|
AuthorizationService authService,
|
|
CensorFactory censorFactory
|
|
) {
|
|
super(conventionService);
|
|
this.authService = authService;
|
|
this.censorFactory = censorFactory;
|
|
}
|
|
|
|
public void censor(FieldSet fields, UUID userId) throws MyForbiddenException {
|
|
logger.debug(new DataLogEntry("censoring fields", fields));
|
|
if (this.isEmpty(fields)) return;
|
|
this.authService.authorizeAtLeastOneForce(userId != null ? List.of(new OwnedResource(userId)) : null, Permission.BrowseUserContactInfo);
|
|
FieldSet userFields = fields.extractPrefixed(this.asIndexerPrefix(UserContactInfo._user));
|
|
this.censorFactory.censor(UserCensor.class).censor(userFields, userId);
|
|
}
|
|
|
|
}
|