com.kero.security.lang.parsers.PropertyParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kero-security Show documentation
Show all versions of kero-security Show documentation
Kero-Security is a library for statically controlling access to properties of objects / classes.
package com.kero.security.lang.parsers;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.kero.security.lang.collections.TokenSequence;
import com.kero.security.lang.nodes.DefaultAccessNode;
import com.kero.security.lang.nodes.PropertyNode;
import com.kero.security.lang.nodes.metaline.PropertyMetalineBase;
import com.kero.security.lang.parsers.metaline.HasMetalines;
import com.kero.security.lang.parsers.metaline.MetalineParser;
import com.kero.security.lang.parsers.metaline.PropagationParser;
import com.kero.security.lang.tokens.DefaultAccessToken;
import com.kero.security.lang.tokens.NameToken;
import com.kero.security.lang.tokens.RoleToken;
public class PropertyParser extends KsdlNodeParserBase implements HasBlock, HasMetalines {
private List> metalineParsers = new ArrayList<>();
public PropertyParser() {
metalineParsers.add(new PropagationParser());
}
public PropertyNode parse(TokenSequence tokens) {
NameToken nameToken = (NameToken) tokens.poll();
DefaultAccessToken defaultRuleToken = tokens.tryGetOrDefault(DefaultAccessToken.EMPTY);
Set grantRoles = new HashSet<>();
Set denyRoles = new HashSet<>();
List roles = this.parseBlock(tokens);
for(RoleToken role : roles) {
if(role.getAccessible()) {
grantRoles.add(role.getRoleName());
}
else {
denyRoles.add(role.getRoleName());
}
}
List metalines = this.parseMetalines(tokens);
String name = nameToken.getRaw();
DefaultAccessNode defaultRule = defaultRuleToken.toNode();
return new PropertyNode(name, defaultRule, grantRoles, denyRoles, metalines);
}
@Override
public List> getMetalineParsers() {
return metalineParsers;
}
@Override
public RoleToken parseBlockUnit(TokenSequence tokens) {
return (RoleToken) tokens.poll();
}
}