本文整理汇总了Java中org.wso2.balana.ctx.AbstractResult.DECISION_PERMIT属性的典型用法代码示例。如果您正苦于以下问题:Java AbstractResult.DECISION_PERMIT属性的具体用法?Java AbstractResult.DECISION_PERMIT怎么用?Java AbstractResult.DECISION_PERMIT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.wso2.balana.ctx.AbstractResult
的用法示例。
在下文中一共展示了AbstractResult.DECISION_PERMIT属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResponse
/**
* Helper method to get XACML decision
*
* @param requestAttributes XACML request attributes
* @return whether permit or deny
*/
private boolean getResponse(List<AttributeDTO> requestAttributes) {
ResponseCtx responseCtx;
AbstractRequestCtx requestCtx = EntitlementUtil.createRequestContext(requestAttributes);
responseCtx = EntitlementEngine.getInstance().evaluateByContext(requestCtx);
if (responseCtx != null) {
Set<AbstractResult> results = responseCtx.getResults();
for (AbstractResult result : results) {
if (result.getDecision() == AbstractResult.DECISION_PERMIT) {
return true;
}
}
}
return false;
}
示例2: combine
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what else
// we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT) {
return result;
} else if(value == AbstractResult.DECISION_DENY){
denyObligations.addAll(result.getObligations());
denyAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of PERMIT. The return DENY
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
示例3: combine
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {
List<ObligationResult> permitObligations = new ArrayList<ObligationResult>();
List<Advice> permitAdvices= new ArrayList<Advice>();
for (Object ruleElement : ruleElements) {
Rule rule = ((RuleCombinerElement) (ruleElement)).getRule();
AbstractResult result = rule.evaluate(context);
int value = result.getDecision();
// if there was a value of DENY, then regardless of what else
// we've seen, we always return DENY
if (value == AbstractResult.DECISION_DENY) {
return result;
} else if(value == AbstractResult.DECISION_PERMIT){
permitObligations.addAll(result.getObligations());
permitAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of DENY. The return PERMIT
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_PERMIT,
permitObligations, permitAdvices, context);
}
示例4: combine
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> permitObligations = new ArrayList<ObligationResult>();
List<Advice> permitAdvices= new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of DENY, then regardless of what else
// we've seen, we always return DENY
if (value == AbstractResult.DECISION_DENY) {
return result;
} else if(value == AbstractResult.DECISION_PERMIT){
permitObligations.addAll(result.getObligations());
permitAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of DENY. The return PERMIT
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_PERMIT,
permitObligations, permitAdvices, context);
}
示例5: combine
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
for (Object ruleElement : ruleElements) {
Rule rule = ((RuleCombinerElement) (ruleElement)).getRule();
AbstractResult result = rule.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what else
// we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT) {
return result;
} else if(value == AbstractResult.DECISION_DENY){
denyObligations.addAll(result.getObligations());
denyAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of PERMIT. The return DENY
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
示例6: checkAccessByRequest
public static boolean checkAccessByRequest(String request){
boolean access = false;
PDP pdp = PDPHelper.getPDPNewInstance();
String response = pdp.evaluate(request);
if (debug) {
System.out
.println("XACML Response:");
System.out.println(response);
}
try {
ResponseCtx responseCtx = ResponseCtx
.getInstance(XACMLHelper.getXacmlResponse(response));
AbstractResult result = responseCtx.getResults().iterator().next();
if (AbstractResult.DECISION_PERMIT == result.getDecision()) {
access = true;
}
} catch (ParsingException e) {
e.printStackTrace();
}
return access;
}
示例7: main
public static void main(String[] args){
Console console;
String userName = "none";
String content = "foo";
initBalana();
if ((console = System.console()) != null){
userName = console.readLine("Enter User name [bob, peter, alice] : ");
if(userName == null || userName.trim().length() < 1 ){
System.err.println("\nUser name can not be empty\n");
return;
}
}
String request = createXACMLRequest(userName, content);
PDP pdp = getPDPNewInstance();
System.out.println("\n======================== XACML Request ====================");
System.out.println(request);
System.out.println("===========================================================");
String response = pdp.evaluate(request);
System.out.println("\n======================== XACML Response ===================");
System.out.println(response);
System.out.println("===========================================================");
try {
ResponseCtx responseCtx = ResponseCtx.getInstance(getXacmlResponse(response));
AbstractResult result = responseCtx.getResults().iterator().next();
if(AbstractResult.DECISION_PERMIT == result.getDecision()){
System.out.println("\n" + userName + " is authorized to perform this access\n\n");
} else {
System.out.println("\n" + userName + " is NOT authorized to perform this access\n");
}
} catch (ParsingException e) {
e.printStackTrace();
}
}
示例8: combine
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
MatchResult match = policy.match(context);
if (match.getResult() == MatchResult.MATCH) {
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what else
// we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT) {
return result;
} else if(value == AbstractResult.DECISION_DENY){
denyObligations.addAll(result.getObligations());
denyAdvices.addAll(result.getAdvices());
}
}
}
// if there is not any value of PERMIT. The return DENY
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
示例9: combine
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> permitObligations = new ArrayList<ObligationResult>();
List<Advice> permitAdvices= new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
MatchResult match = policy.match(context);
if (match.getResult() == MatchResult.MATCH) {
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of DENY, then regardless of what else
// we've seen, we always return DENY
if (value == AbstractResult.DECISION_DENY) {
return result;
} else if (value == AbstractResult.DECISION_PERMIT) {
permitObligations.addAll(result.getObligations());
permitAdvices.addAll(result.getAdvices());
}
}
}
// if there is not any value of DENY. The return PERMIT
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_PERMIT,
permitObligations, permitAdvices, context);
}
示例10: combine
/**
* Applies the combining rule to the set of rules based on the evaluation context.
*
* @param context the context from the request
* @param parameters a (possibly empty) non-null <code>List</code> of
* <code>CombinerParameter<code>s
* @param ruleElements the rules to combine
*
* @return the result of running the combining algorithm
*/
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {
boolean atLeastOneError = false;
boolean potentialPermit = false;
boolean atLeastOneDeny = false;
AbstractResult firstIndeterminateResult = null;
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
Iterator it = ruleElements.iterator();
while (it.hasNext()) {
Rule rule = ((RuleCombinerElement) (it.next())).getRule();
AbstractResult result = rule.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what
// else we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT){
return result;
}
// if it was INDETERMINATE, then we couldn't figure something
// out, so we keep track of these cases...
if (value == AbstractResult.DECISION_INDETERMINATE ||
value == AbstractResult.DECISION_INDETERMINATE_DENY ||
value == AbstractResult.DECISION_INDETERMINATE_PERMIT ||
value == AbstractResult.DECISION_INDETERMINATE_DENY_OR_PERMIT) {
atLeastOneError = true;
// there are no rules about what to do if multiple cases
// cause errors, so we'll just return the first one
if (firstIndeterminateResult == null){
firstIndeterminateResult = result;
}
// if the Rule's effect is PERMIT, then we can't let this
// alg return DENY, since this Rule might have permitted
// if it could do its stuff
if (rule.getEffect() == AbstractResult.DECISION_PERMIT){
potentialPermit = true;
}
} else {
// keep track of whether we had at least one rule that
// actually pertained to the request
if (value == AbstractResult.DECISION_DENY)
atLeastOneDeny = true;
denyAdvices.addAll(result.getAdvices());
denyObligations.addAll(result.getObligations());
}
}
// we didn't explicitly PERMIT, but we might have had some Rule
// been evaluated, so we have to return INDETERMINATE
if (potentialPermit){
return firstIndeterminateResult;
}
// some Rule said DENY, so since nothing could have permitted,
// we return DENY
if (atLeastOneDeny){
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
// we didn't find anything that said DENY, but if we had a
// problem with one of the Rules, then we're INDETERMINATE
if (atLeastOneError){
return firstIndeterminateResult;
}
// if we hit this point, then none of the rules actually applied
// to us, so we return NOT_APPLICABLE
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_NOT_APPLICABLE, context);
}
示例11: checkAccess
public static boolean checkAccess(String userName, String object, String action) {
boolean access = false;
String request = createXACMLRequest(userName, object, action);
PDP pdp = getPDPNewInstance();
String response = pdp.evaluate(request);
if (debug) {
System.out
.println("\n======================== XACML Request ====================");
System.out.println(request);
System.out
.println("===========================================================");
System.out
.println("\n======================== XACML Response ===================");
System.out.println(response);
System.out
.println("===========================================================");
}
try {
ResponseCtx responseCtx = ResponseCtx
.getInstance(getXacmlResponse(response));
AbstractResult result = responseCtx.getResults().iterator().next();
if (AbstractResult.DECISION_PERMIT == result.getDecision()) {
access = true;
if (debug) {
System.out.println("\n" + userName
+ " is authorized to perform this action\n\n");
}
} else {
if (debug) {
System.out.println("\n" + userName
+ " is NOT authorized to perform this action\n");
List<Advice> advices = result.getAdvices();
for (Advice advice : advices) {
List<AttributeAssignment> assignments = advice
.getAssignments();
for (AttributeAssignment assignment : assignments) {
System.out.println("Advice : "
+ assignment.getContent() + "\n\n");
}
}
}
}
} catch (ParsingException e) {
e.printStackTrace();
}
return access;
}