Authority, AccessContext, SecuredUserInfo -> ActionGroup관련 메소드 추가

master
mjkhan21 1 year ago
parent 807e1adafe
commit 83da0967a6

@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import cokr.xit.base.security.access.dao.AuthorityMapper;
import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.data.DataObject;
/** (URL)
* .<br />
@ -48,7 +49,24 @@ public class AccessContext extends AbstractComponent implements ApplicationConte
.filter(authority -> Authority.Type.IMPLICIT.equals(authority.type()))
.collect(Collectors.toList());
authorityMapper.getActionList().stream()
List<DataObject> authorityActions = authorityMapper.getActionList();
authorityActions.stream() // 권한별 기능그룹 설정
.map(row -> Map.of("AUTH_ID", row.get("AUTH_ID"), "GRP_ID", row.get("GRP_ID")))
.collect(Collectors.groupingBy(
row -> row.get("AUTH_ID"),
Collectors.toSet()
))
.forEach((authID, byAuth) -> {
List<String> groupIDs = byAuth.stream()
.map(row -> (String)row.get("GRP_ID"))
.collect(Collectors.toList());
Authority authority = authorityIndex.get(authID);
if (authority != null)
authority.setActionGroups(groupIDs);
});
authorityActions.stream() // 권한별 기능(URL) 설정
.collect(Collectors.groupingBy(row -> row.string("AUTH_ID")))
.forEach((authID, actions) -> {
List<String> actionList = actions.stream()

@ -52,7 +52,9 @@ public class Authority extends AbstractEntity implements GrantedAuthority {
description,
infoScope,
userInfoScope;
private List<String> actions;
private List<String>
actionGroups,
actions;
/**{@link Type } .
* @return
@ -82,6 +84,7 @@ public class Authority extends AbstractEntity implements GrantedAuthority {
/** id .
* @param id id
* @return Authority
*/
public Authority setId(String id) {
this.id = id;
@ -97,6 +100,7 @@ public class Authority extends AbstractEntity implements GrantedAuthority {
/** .
* @param name
* @return Authority
*/
public Authority setName(String name) {
this.name = name;
@ -132,6 +136,7 @@ public class Authority extends AbstractEntity implements GrantedAuthority {
* <ul><li>ALL - </li>
* <li>SELF - </li>
* </ul>
* @return Authority
*/
public Authority setInfoScope(String infoScope) {
this.infoScope = infoScope;
@ -153,17 +158,58 @@ public class Authority extends AbstractEntity implements GrantedAuthority {
* <ul><li>ALL - </li>
* <li>SELF - </li>
* </ul>
* @return Authority
*/
public Authority setUserInfoScope(String userInfoScope) {
this.userInfoScope = userInfoScope;
return this;
}
/** .
* @return
*/
public List<String> getActionGroups() {
return Assert.ifEmpty(actionGroups, Collections::emptyList);
}
/** .
* @param actionGroups
* @return
* <ul><li> true</li>
* <li> false</li>
* </ul>
*/
public boolean isActionGroupGranted(String actionGroup) {
return Type.SUPER.equals(type())
|| getActionGroups().contains(actionGroup);
}
/** .
* @param actionGroups
* @return Authority
*/
public Authority setActionGroups(List<String> actionGroups) {
this.actionGroups = actionGroups;
return this;
}
/**action .
* @param action (URL)
* @return
* <ul><li> true</li>
* <li> false</li>
* </ul>
*/
public boolean isActionGranted(String action) {
return Type.SUPER.equals(type())
|| getActions().contains(action);
}
/**(URL) .
* @return (URL)
*/
public List<String> getActions() {
return actions != null ? actions : Collections.emptyList();
return Assert.ifEmpty(actions, Collections::emptyList);
}
/**(URL) .
@ -205,19 +251,6 @@ public class Authority extends AbstractEntity implements GrantedAuthority {
return Assert.ifEmpty(infoScopes != null ? infoScopes.get(infoType) : null, () -> "none");
}
/**action .
* @param action (URL)
* @return
* <ul><li> true</li>
* <li> false</li>
* </ul>
*/
public boolean isGranted(String action) {
if (Type.SUPER.equals(type())) return true;
return getActions().contains(action);
}
@Override
public String toString() {
return String.format("%s{id:'%s', name:'%s'}", getClass().getSimpleName(), getId(), getName());

@ -79,10 +79,27 @@ public class SecuredUserInfo extends UserInfo implements UserDetails {
* <li> false</li>
* </ul>
*/
public boolean isGranted(String action) {
public boolean isActionGranted(String action) {
if (authorities != null && !authorities.isEmpty()) {
for (Authority authority: authorities) {
if (authority.isGranted(action))
if (authority.isActionGranted(action))
return true;
}
}
return false;
}
/** .
* @param actionGroup
* @return
* <ul><li> true</li>
* <li> false</li>
* </ul>
*/
public boolean isActionGroupGranted(String actionGroup) {
if (authorities != null && !authorities.isEmpty()) {
for (Authority authority: authorities) {
if (authority.isActionGroupGranted(actionGroup))
return true;
}
}

@ -50,11 +50,11 @@ public class ApplicationAccess
return ACCESS_GRANTED;
SecuredUserInfo userInfo = currentUser();
if (userInfo.isGranted(action))
if (userInfo.isActionGranted(action))
return ACCESS_GRANTED;
/*
for (Authority authority: accessContext.getImplicits())
if (authority.isGranted(action))
if (authority.isActionGranted(action))
return ACCESS_GRANTED;
*/
return ACCESS_DENIED;

Loading…
Cancel
Save