All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.epam.reportportal.extension.AdminCommand Maven / Gradle / Ivy

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.");
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy