You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
package com.aiprose.scauth.handler;
|
|
|
|
import com.aiprose.scauth.service.IRoleService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.security.access.ConfigAttribute;
|
|
import org.springframework.security.access.SecurityConfig;
|
|
import org.springframework.security.web.FilterInvocation;
|
|
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
@Service
|
|
public class UrlRolesFilterHandler implements FilterInvocationSecurityMetadataSource {
|
|
|
|
@Autowired
|
|
private IRoleService roleService;
|
|
|
|
@Override
|
|
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
|
|
String requestUrl = ((FilterInvocation) object).getRequestUrl();
|
|
List<String> roleNames = roleService.findByUrl(requestUrl);
|
|
String[] names = new String[roleNames.size()];
|
|
for (int i = 0; i < roleNames.size(); i++) {
|
|
names[i] = roleNames.get(i);
|
|
}
|
|
return SecurityConfig.createList(names);
|
|
}
|
|
|
|
@Override
|
|
public Collection<ConfigAttribute> getAllConfigAttributes() {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public boolean supports(Class<?> clazz) {
|
|
return FilterInvocation.class.isAssignableFrom(clazz);
|
|
}
|
|
}
|
|
|