// find the best matching rule. Rules are sorted by specificity so any rule matching
// last will be more specific than the ones matching earlier (e.g., wms.GetMap is moer
// specific than just wms.* which is more specific than *.*)
List<ServiceAccessRule> rules = dao.getRules();
ServiceAccessRule bestMatch = null;
for (ServiceAccessRule rule : rules) {
if(rule.getService().equals(ServiceAccessRule.ANY) || rule.getService().equalsIgnoreCase(service)) {
if(rule.getMethod().equals(ServiceAccessRule.ANY) || rule.getMethod().equalsIgnoreCase(method)) {
bestMatch = rule;
}
}
}
// if there is a matching rule apply it
if(bestMatch != null) {
Set<String> allowedRoles = bestMatch.getRoles();
// if the rule is not the kind that allows everybody in check if the current
// user is authenticated and has one of the required roles
if(!allowedRoles.contains(ServiceAccessRule.ANY) && !allowedRoles.isEmpty()) {
Authentication user = SecurityContextHolder.getContext().getAuthentication();