com.epam.reportportal.extension.AdminCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plugin-api Show documentation
Show all versions of plugin-api Show documentation
EPAM Report portal. Plugin extension APIs
The newest version!
package com.epam.reportportal.extension;
import com.epam.reportportal.rules.commons.validation.BusinessRule;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.ta.reportportal.commons.ReportPortalUser;
import com.epam.ta.reportportal.entity.user.UserRole;
import org.springframework.security.core.context.SecurityContextHolder;
import java.util.Map;
import java.util.function.Predicate;
/**
* @author Pavel Bortnik
*/
public abstract class AdminCommand extends AbstractRoleBasedCommand {
@Override
public void validateRole(Map params) {
ReportPortalUser user = (ReportPortalUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
BusinessRule.expect(UserRole.ADMINISTRATOR.equals(user.getUserRole()), Predicate.isEqual(true))
.verify(ErrorType.ACCESS_DENIED, "Only user with role 'ADMINISTRATOR' is allowed to execute command.");
}
}