Package com.sun.xacml.cond

Examples of com.sun.xacml.cond.EvaluationResult


        // Get the list of attribute finders who are registered with this particular attribute.
        List<PIPAttributeFinder> finders = attrFinders.get(attributeId.toString());

        if (finders == null || finders.size() == 0) {
            log.info("No attribute designators defined for the attribute " + attributeId.toString());
            return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
        }

        List<AttributeValue> attrBag = new ArrayList<AttributeValue>();
        EvaluationResult subject = null;
        String subjectId = null;
        EvaluationResult resource = null;
        String resourceId = null;

        try {
            subject = context.getSubjectAttribute(new URI(StringAttribute.identifier), new URI(
                    "urn:oasis:names:tc:xacml:1.0:subject:subject-id"), subjectCategory);
            if (subject.getAttributeValue().isBag()) {
                BagAttribute attr = (BagAttribute) subject.getAttributeValue();
                for (Iterator iterator = attr.iterator(); iterator.hasNext();) {
                    AttributeValue val = (AttributeValue) iterator.next();
                    subjectId = val.encode();
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Finding attributes for the subject %1$s",
                                subjectId));
                    }
                    break;
                }

            }

            resource = context.getResourceAttribute(new URI(StringAttribute.identifier), new URI(
                    "urn:oasis:names:tc:xacml:1.0:resource:resource-id"), null);
            if (resource.getAttributeValue().isBag()) {
                BagAttribute attr = (BagAttribute) resource.getAttributeValue();
                for (Iterator iterator = attr.iterator(); iterator.hasNext();) {
                    AttributeValue val = (AttributeValue) iterator.next();
                    resourceId = val.encode();
                    if (log.isDebugEnabled()) {
                        log.debug(String.format("Finding attributes for the resource %1$s",
                                resourceId));
                    }
                    break;
                }

            }

            for (Iterator iterator = finders.iterator(); iterator.hasNext();) {
                PIPAttributeFinder pipAttributeFinder = (PIPAttributeFinder) iterator.next();
                if (log.isDebugEnabled()) {
                    log.debug(String.format(
                            "Finding attributes with the PIP attribute handler %1$s",
                            pipAttributeFinder.getClass()));
                }
                Set<String> attrs = pipAttributeFinder.getAttributeValues(subjectId, resourceId,
                        attributeId.toString());
                if (attrs != null) {
                    for (Iterator iterAttr = attrs.iterator(); iterAttr.hasNext();) {
                        final String attr = (String) iterAttr.next();
                        AttributeValue attribute = getAttribute(attr, attributeType.toString());
                        attrBag.add(attribute);
                    }
                }
            }

        } catch (Exception e) {
            log.error("Error occured while finding attributes via PIP", e);
            return new EvaluationResult(BagAttribute.createEmptyBag(attributeType));
        }

        return new EvaluationResult(new BagAttribute(attributeType, attrBag));
    }
View Full Code Here


    if(!XACMLConstants.ACCESS_SUBJECT.equals(subjectCategory))
      {return errorResult("UserAttributeModule can only handle subject category '" + XACMLConstants.ACCESS_SUBJECT + "'");}
    if(!XACMLConstants.STRING_TYPE.equals(attributeType))
      {return errorResult("UserAttributeModule can only handle data type '" + XACMLConstants.STRING_TYPE + "'");}
   
    final EvaluationResult subjectID = context.getSubjectAttribute(attributeType, XACMLConstants.SUBJECT_ID_ATTRIBUTE, issuer, subjectCategory);
    if(subjectID.indeterminate())
      {return subjectID;}
   
    AttributeValue value = subjectID.getAttributeValue();
    if(value == null)
      {return errorResult("Could not find user for context: null subject-id");}
    if(value.isBag())
    {
      final BagAttribute bag = (BagAttribute)value;
      if(bag.isEmpty())
        {return errorResult("Could not find user for context: no subject-id found");}
      if(bag.size() > 1)
        {return errorResult("Error finding attribute: Subject-id attribute is not unique.");}
     
      value = (AttributeValue)bag.iterator().next();
    }
    if(!(value instanceof StringAttribute))
      {return errorResult("Error finding attribute: Subject-id attribute must be a string.");}
   
    final String uid = ((StringAttribute)value).getValue();
    final Account user = pdp.getBrokerPool().getSecurityManager().getAccount(uid);
    if(user == null)
      {return errorResult("No user exists for UID '" + uid + "'");}
   
    if(XACMLConstants.GROUP_ATTRIBUTE.equals(attributeId))
      {return getGroups(user);}
    else if(XACMLConstants.USER_NAME_ATTRIBUTE.equals(attributeId))
      {return new EvaluationResult(new StringAttribute(user.getName()));}
    else
      {return errorResult("UserAttributeModule cannot handle attribute '" + attributeId + "'");}
  }
View Full Code Here

    final int size = (groupArray == null) ? 0 : groupArray.length;
    final Set<StringAttribute> groupAttributes = new HashSet<StringAttribute>(size);
    for(int i = 0; i < size; ++i)
      groupAttributes.add(new StringAttribute(groupArray[i]));
    final AttributeValue value = new BagAttribute(XACMLConstants.STRING_TYPE, groupAttributes);
    return new EvaluationResult(value);
   
  }
View Full Code Here

  //logs the specified message and exception
  //then, returns a result with status Indeterminate and the given message
  private static EvaluationResult errorResult(String message)
  {
    LOG.warn(message);
    return new EvaluationResult(new Status(Collections.singletonList(Status.STATUS_PROCESSING_ERROR), message));
  }
View Full Code Here

                    + "couldn't make URI for contextId itself");
        }
        logger.debug("ContextAttributeFinder:findAttribute"
                + " about to call getAttributeFromEvaluationCtx");

        EvaluationResult attribute =
                context.getActionAttribute(contextIdType, contextIdId, null);
        Object element = getAttributeFromEvaluationResult(attribute);
        if (element == null) {
            logger.debug("ContextAttributeFinder:getContextId" + " exit on "
                    + "can't get contextId on request callback");
View Full Code Here

        try {
            datastreamIdUri = new URI(Constants.DATASTREAM.ID.uri);
        } catch (URISyntaxException e) {
        }

        EvaluationResult attribute =
                context.getResourceAttribute(STRING_ATTRIBUTE_URI,
                                             datastreamIdUri,
                                             null);

        Object element = getAttributeFromEvaluationResult(attribute);
View Full Code Here

            resourceIdType = new URI(StringAttribute.identifier);
            resourceIdId = new URI(Constants.OBJECT.PID.uri);
        } catch (URISyntaxException e) {
            throw new FaultException("Bad URI syntax", e);
        }
        EvaluationResult attribute
                = context.getResourceAttribute(resourceIdType,
                                               resourceIdId,
                                               null);
        Object element = getAttributeFromEvaluationResult(attribute);
        if (element == null) {
View Full Code Here

                    attributeType = new URI(StringAttribute.identifier);
                } catch (URISyntaxException e) {
                    //we tried
                }
            }
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        if (!willService(attributeId)) {
            logger.debug("AttributeFinder:willService() {} returns false", iAm());
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        if (category != null) {
            logger.debug("++++++++++ AttributeFinder:findAttribute {} category={}", iAm(), category.toString());
        }
        logger.debug("++++++++++ AttributeFinder:findAttribute {} designatorType={}", iAm(), designatorType);

        logger.debug("about to get temp {}", iAm());
        Object temp =
                getAttributeLocally(designatorType,
                                    attributeId.toASCIIString(),
                                    category,
                                    context);
        logger.debug("{} got temp={}", iAm(), temp);

        if (temp == null) {
            logger.debug("AttributeFinder:findAttribute" + " exit on "
                    + "attribute value not found" + iAm());
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        Set<AttributeValue> set = new HashSet<AttributeValue>();
        if (temp instanceof String) {
            logger.debug("AttributeFinder:findAttribute will return a String {}", iAm());
            if (attributeType.toString().equals(StringAttribute.identifier)) {
                set.add(new StringAttribute((String) temp));
            } else if (attributeType.toString()
                    .equals(DateTimeAttribute.identifier)) {
                DateTimeAttribute tempDateTimeAttribute;
                try {
                    tempDateTimeAttribute =
                            DateTimeAttribute.getInstance((String) temp);
                    set.add(tempDateTimeAttribute);
                } catch (Throwable t) {
                }
            } else if (attributeType.toString()
                    .equals(DateAttribute.identifier)) {
                DateAttribute tempDateAttribute;
                try {
                    tempDateAttribute =
                            DateAttribute.getInstance((String) temp);
                    set.add(tempDateAttribute);
                } catch (Throwable t) {
                }
            } else if (attributeType.toString()
                    .equals(TimeAttribute.identifier)) {
                TimeAttribute tempTimeAttribute;
                try {
                    tempTimeAttribute =
                            TimeAttribute.getInstance((String) temp);
                    set.add(tempTimeAttribute);
                } catch (Throwable t) {
                }
            } else if (attributeType.toString()
                    .equals(IntegerAttribute.identifier)) {
                IntegerAttribute tempIntegerAttribute;
                try {
                    tempIntegerAttribute =
                            IntegerAttribute.getInstance((String) temp);
                    set.add(tempIntegerAttribute);
                } catch (Throwable t) {
                }
            } //xacml fixup
            //was set.add(new StringAttribute((String)temp));
        } else if (temp instanceof String[]) {
            logger.debug("AttributeFinder:findAttribute will return a String[] ", iAm());
            for (int i = 0; i < ((String[]) temp).length; i++) {
                if (((String[]) temp)[i] == null) {
                    continue;
                }
                if (attributeType.toString().equals(StringAttribute.identifier)) {
                    set.add(new StringAttribute(((String[]) temp)[i]));
                } else if (attributeType.toString()
                        .equals(DateTimeAttribute.identifier)) {
                    logger.debug("USING AS DATETIME:{}", ((String[]) temp)[i]);
                    DateTimeAttribute tempDateTimeAttribute;
                    try {
                        tempDateTimeAttribute =
                                DateTimeAttribute
                                        .getInstance(((String[]) temp)[i]);
                        set.add(tempDateTimeAttribute);
                    } catch (Throwable t) {
                    }
                } else if (attributeType.toString()
                        .equals(DateAttribute.identifier)) {
                    logger.debug("USING AS DATE:{}", ((String[]) temp)[i]);
                    DateAttribute tempDateAttribute;
                    try {
                        tempDateAttribute =
                                DateAttribute.getInstance(((String[]) temp)[i]);
                        set.add(tempDateAttribute);
                    } catch (Throwable t) {
                    }
                } else if (attributeType.toString()
                        .equals(TimeAttribute.identifier)) {
                    logger.debug("USING AS TIME:{}", ((String[]) temp)[i]);
                    TimeAttribute tempTimeAttribute;
                    try {
                        tempTimeAttribute =
                                TimeAttribute.getInstance(((String[]) temp)[i]);
                        set.add(tempTimeAttribute);
                    } catch (Throwable t) {
                    }
                } else if (attributeType.toString()
                        .equals(IntegerAttribute.identifier)) {
                    logger.debug("USING AS INTEGER: {}", ((String[]) temp)[i]);
                    IntegerAttribute tempIntegerAttribute;
                    try {
                        tempIntegerAttribute =
                                IntegerAttribute
                                        .getInstance(((String[]) temp)[i]);
                        set.add(tempIntegerAttribute);
                    } catch (Throwable t) {
                    }
                }
            }
        }
        return new EvaluationResult(new BagAttribute(attributeType, set));
    }
View Full Code Here

                                          int designatorType) {
        String user = null;
        URI userId = Constants.SUBJECT.LOGIN_ID.getURI();
        URI category = XACML1SubjectCategoryNamespace.getInstance().ACCESS_SUBJECT.getURI();

        EvaluationResult userER =
                context.getSubjectAttribute(STRING_DATATYPE, userId, category);
        if (userER == null) {
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        AttributeValue userAV = userER.getAttributeValue();
        if (userAV == null) {
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        user = userAV.encode();
        if (logger.isDebugEnabled()) {
            logger.debug("LDAPAttributeFinder: Getting info for " + user);
        }

        // figure out which attribute we're looking for
        String attrName = attributeId.toString();

        // we only know about registered attributes from config file
        if (m_attributes.get(designatorType) == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Does not know about designatorType: "
                        + designatorType);
            }
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        Set<String> allowedAttributes =
                m_attributes.get(designatorType).keySet();
        if (!allowedAttributes.contains(attrName)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Does not know about attribute: " + attrName);
            }
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        EvaluationResult result = null;
        try {
            result = getEvaluationResult(user, attrName, attributeType);
        } catch (Exception e) {
            logger.error("Error finding attribute: " + e.getMessage(), e);
            return new EvaluationResult(BagAttribute
                    .createEmptyBag(attributeType));
        }

        return result;
    }
View Full Code Here

                    }
                }
            }
        } catch (Exception e) {
            logger.error("Error getting evaluation result", e);
            return new EvaluationResult(BagAttribute.createEmptyBag(type));
        }

        BagAttribute bag = new BagAttribute(type, bagValues);

        return new EvaluationResult(bag);
    }
View Full Code Here

TOP

Related Classes of com.sun.xacml.cond.EvaluationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.