Rev 23786 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.util;import java.util.HashSet;import java.util.List;import java.util.Set;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import org.springframework.transaction.annotation.Transactional;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.dao.entity.dtr.Api;import com.spice.profitmandi.dao.entity.dtr.RoleApi;import com.spice.profitmandi.dao.enumuration.dtr.Method;import com.spice.profitmandi.dao.repository.dtr.ApiRepository;import com.spice.profitmandi.dao.repository.dtr.RoleApiRepository;@Transactional@Componentpublic class RoleManager {@Autowiredprivate RoleApiRepository roleApiRepository;@Autowiredprivate ApiRepository apiRepository;public boolean isAuthorizedURI(Set<Integer> roleIds, String contextPath, String uri, String method) throws ProfitMandiBusinessException{List<RoleApi> roleApis = roleApiRepository.selectByRoleIds(roleIds);Set<Integer> apiIds = new HashSet<>();for(RoleApi roleApi : roleApis) {apiIds.add(roleApi.getApiId());}List<Api> apis = apiRepository.selectByIds(apiIds);for(Api api : apis) {if(uri.matches(contextPath + api.getUri()) && api.getMethod().equals(Method.valueOf(method))) {return true;}}throw new ProfitMandiBusinessException(ProfitMandiConstants.URI, uri, "GE_1004");}}