| 23784 |
ashik.ali |
1 |
package com.spice.profitmandi.web.util;
|
|
|
2 |
|
|
|
3 |
import java.util.HashSet;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
import java.util.Set;
|
|
|
6 |
|
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.stereotype.Component;
|
|
|
9 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
10 |
|
|
|
11 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
12 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
13 |
import com.spice.profitmandi.dao.entity.dtr.Api;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.dtr.RoleApi;
|
|
|
15 |
import com.spice.profitmandi.dao.enumuration.dtr.Method;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.dtr.ApiRepository;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.dtr.RoleApiRepository;
|
|
|
18 |
|
|
|
19 |
@Transactional
|
|
|
20 |
@Component
|
|
|
21 |
public class RoleManager {
|
|
|
22 |
|
|
|
23 |
@Autowired
|
|
|
24 |
private RoleApiRepository roleApiRepository;
|
|
|
25 |
|
|
|
26 |
@Autowired
|
|
|
27 |
private ApiRepository apiRepository;
|
|
|
28 |
|
|
|
29 |
public boolean isAuthorizedURI(Set<Integer> roleIds, String contextPath, String uri, String method) throws ProfitMandiBusinessException{
|
|
|
30 |
List<RoleApi> roleApis = roleApiRepository.selectByRoleIds(roleIds);
|
|
|
31 |
Set<Integer> apiIds = new HashSet<>();
|
|
|
32 |
for(RoleApi roleApi : roleApis) {
|
|
|
33 |
apiIds.add(roleApi.getApiId());
|
|
|
34 |
}
|
|
|
35 |
List<Api> apis = apiRepository.selectByIds(apiIds);
|
|
|
36 |
for(Api api : apis) {
|
|
|
37 |
if(uri.matches(contextPath + api.getUri()) && api.getMethod().equals(Method.valueOf(method))) {
|
|
|
38 |
return true;
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.URI, uri, "GE_1004");
|
|
|
42 |
}
|
|
|
43 |
}
|