|
|
|
@ -1,12 +1,17 @@
|
|
|
|
|
package cokr.xit.base.security.access;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
import org.springframework.security.access.AccessDecisionVoter;
|
|
|
|
|
import org.springframework.security.access.ConfigAttribute;
|
|
|
|
|
import org.springframework.security.authorization.AuthorizationDecision;
|
|
|
|
|
import org.springframework.security.authorization.AuthorizationManager;
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
import org.springframework.security.web.access.intercept.RequestAuthorizationContext;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import cokr.xit.base.security.AccessContext;
|
|
|
|
|
import cokr.xit.base.security.SecuredUserInfo;
|
|
|
|
@ -17,22 +22,14 @@ import cokr.xit.foundation.Access;
|
|
|
|
|
* 사용자가 애플리케이션의 기능을 실행할 수 있는지 판단한다.
|
|
|
|
|
* @author mjkhan
|
|
|
|
|
*/
|
|
|
|
|
public class ApplicationAccess extends AbstractComponent implements AccessDecisionVoter<Object> {
|
|
|
|
|
private boolean controlAccess;
|
|
|
|
|
@Component("applicationAccess")
|
|
|
|
|
public class ApplicationAccess
|
|
|
|
|
extends AbstractComponent
|
|
|
|
|
implements AccessDecisionVoter<Object>, AuthorizationManager<RequestAuthorizationContext> {
|
|
|
|
|
/** 권한별 가용 기능(URL) */
|
|
|
|
|
@Resource(name="accessContext")
|
|
|
|
|
protected AccessContext accessContext;
|
|
|
|
|
|
|
|
|
|
/**접근 제어를 사용할지 설정한다.
|
|
|
|
|
* @param controlAccess 접근 제어 사용 여부
|
|
|
|
|
* <ul><li>접근 제어를 사용하면 true</li>
|
|
|
|
|
* <li>그렇지 않으면 false</li>
|
|
|
|
|
* </ul>
|
|
|
|
|
*/
|
|
|
|
|
public void setControlAccess(boolean controlAccess) {
|
|
|
|
|
this.controlAccess = controlAccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean supports(ConfigAttribute attribute) {
|
|
|
|
|
return true;
|
|
|
|
@ -45,9 +42,10 @@ public class ApplicationAccess extends AbstractComponent implements AccessDecisi
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int vote(Authentication authentication, Object obj, Collection<ConfigAttribute> attributes) {
|
|
|
|
|
if (!controlAccess) return ACCESS_GRANTED;
|
|
|
|
|
return vote(Access.current().getAction());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String action = Access.current().getAction();
|
|
|
|
|
public int vote(String action) {
|
|
|
|
|
if (isEmpty(action))
|
|
|
|
|
return ACCESS_GRANTED;
|
|
|
|
|
|
|
|
|
@ -61,4 +59,17 @@ public class ApplicationAccess extends AbstractComponent implements AccessDecisi
|
|
|
|
|
*/
|
|
|
|
|
return ACCESS_DENIED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final AuthorizationDecision
|
|
|
|
|
granted = new AuthorizationDecision(true),
|
|
|
|
|
denied = new AuthorizationDecision(false);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public AuthorizationDecision check(Supplier<Authentication> authentication, RequestAuthorizationContext hreqCtx) {
|
|
|
|
|
switch (vote(authentication.get(), null, null)) {
|
|
|
|
|
case ACCESS_GRANTED: return granted;
|
|
|
|
|
case ACCESS_DENIED: return denied;
|
|
|
|
|
default: return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|