Search in sources :

Example 11 with Attribute

use of com.sun.identity.xacml.context.Attribute in project OpenAM by OpenRock.

the class XACMLClientSample method createSampleXacmlRequest.

private Request createSampleXacmlRequest(String subjectId, String subjectIdType, String subjectCategory, String resourceId, String resourceIdType, String serviceName, String serviceNameType, String actionId, String actionIdType) throws XACMLException, URISyntaxException {
    Request request = ContextFactory.getInstance().createRequest();
    //Subject
    Subject subject = ContextFactory.getInstance().createSubject();
    subject.setSubjectCategory(new URI(subjectCategory));
    //set subject id
    Attribute attribute = ContextFactory.getInstance().createAttribute();
    attribute.setAttributeId(new URI(XACMLConstants.SUBJECT_ID));
    attribute.setDataType(new URI(subjectIdType));
    List valueList = new ArrayList();
    valueList.add(subjectId);
    attribute.setAttributeStringValues(valueList);
    List attributeList = new ArrayList();
    attributeList.add(attribute);
    subject.setAttributes(attributeList);
    //set Subject in Request
    List subjectList = new ArrayList();
    subjectList.add(subject);
    request.setSubjects(subjectList);
    //Resource
    Resource resource = ContextFactory.getInstance().createResource();
    //set resource id
    attribute = ContextFactory.getInstance().createAttribute();
    attribute.setAttributeId(new URI(XACMLConstants.RESOURCE_ID));
    attribute.setDataType(new URI(resourceIdType));
    valueList = new ArrayList();
    valueList.add(resourceId);
    attribute.setAttributeStringValues(valueList);
    attributeList = new ArrayList();
    attributeList.add(attribute);
    //set serviceName
    attribute = ContextFactory.getInstance().createAttribute();
    attribute.setAttributeId(new URI(XACMLConstants.TARGET_SERVICE));
    attribute.setDataType(new URI(serviceNameType));
    valueList = new ArrayList();
    valueList.add(serviceName);
    attribute.setAttributeStringValues(valueList);
    attributeList.add(attribute);
    resource.setAttributes(attributeList);
    //set Resource in Request
    List resourceList = new ArrayList();
    resourceList.add(resource);
    request.setResources(resourceList);
    //Action
    Action action = ContextFactory.getInstance().createAction();
    attribute = ContextFactory.getInstance().createAttribute();
    attribute.setAttributeId(new URI(XACMLConstants.ACTION_ID));
    attribute.setDataType(new URI(actionIdType));
    //set actionId
    valueList = new ArrayList();
    valueList.add(actionId);
    attribute.setAttributeStringValues(valueList);
    attributeList = new ArrayList();
    attributeList.add(attribute);
    action.setAttributes(attributeList);
    //set Action in Request
    request.setAction(action);
    //Enviornment, our PDP does not use environment now
    Environment environment = ContextFactory.getInstance().createEnvironment();
    request.setEnvironment(environment);
    return request;
}
Also used : Action(com.sun.identity.xacml.context.Action) Attribute(com.sun.identity.xacml.context.Attribute) Request(com.sun.identity.xacml.context.Request) ArrayList(java.util.ArrayList) Resource(com.sun.identity.xacml.context.Resource) Environment(com.sun.identity.xacml.context.Environment) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) Subject(com.sun.identity.xacml.context.Subject)

Example 12 with Attribute

use of com.sun.identity.xacml.context.Attribute in project OpenAM by OpenRock.

the class FMSubjectMapperTest method testMapToNativeSubject.

@Test(groups = { "xacml" })
public void testMapToNativeSubject() throws XACMLException, URISyntaxException {
    FMSubjectMapper subjectMapper = new FMSubjectMapper();
    Subject subject1 = ContextFactory.getInstance().createSubject();
    //supported category for id
    //urn:oasis:names:tc:xacml:1.0:subject-category:access-subject
    subject1.setSubjectCategory(new URI("urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"));
    Attribute attribute = ContextFactory.getInstance().createAttribute();
    attribute.setIssuer("sampleIssuer1");
    //key attribute id
    //urn:oasis:names:tc:xacml:1.0:subject:subject-id
    attribute.setAttributeId(new URI("urn:oasis:names:tc:xacml:1.0:subject:subject-id"));
    //supported data type for id
    //urn:oasis:names:tc:xacml:1.0:data-type:x500Name
    //urn:sun:names:xacml:2.0:data-type:opensso-session-id
    //urn:sun:names:xacml:2.0:data-type:openfm-sp-nameid
    attribute.setDataType(new URI("urn:sun:names:xacml:2.0:data-type:opensso-session-id"));
    List<String> valueList = new ArrayList<String>();
    AuthContext lc = null;
    String[] callbacks = { "amadmin", "admin123" };
    SSOToken ssot = null;
    try {
        lc = new AuthContext("/");
        AuthContext.IndexType indexType = AuthContext.IndexType.MODULE_INSTANCE;
        String indexName = "DataStore";
        log(Level.INFO, "testMapToNativeSubject():\n", " LDAPLogin: Obtained login context");
        lc.login(indexType, indexName, callbacks);
        if (lc.getStatus() == AuthContext.Status.SUCCESS) {
            log(Level.INFO, "testMapToNativeSubject():\n", " Login success!!");
        }
        ssot = lc.getSSOToken();
    } catch (Exception le) {
        le.printStackTrace();
        log(Level.INFO, "testMapToNativeSubject():\n", " Login failed!!");
    }
    String sid = ssot.getTokenID().toString();
    log(Level.INFO, "testMapToNativeSubject():\n", " sid = " + sid);
    valueList.add(sid);
    attribute.setAttributeStringValues(valueList);
    List<Attribute> attributeList = new ArrayList<Attribute>();
    attributeList.add(attribute);
    subject1.setAttributes(attributeList);
    Subject[] subjects = { subject1 };
    List<Subject> subjectsList = new ArrayList<Subject>();
    subjectsList.add(subject1);
    SSOToken retSSOToken = (SSOToken) subjectMapper.mapToNativeSubject(subjectsList);
    String retSid = retSSOToken.getTokenID().toString();
    log(Level.INFO, "testMapToNativeSubject():\n", " return sid = " + retSid);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Attribute(com.sun.identity.xacml.context.Attribute) ArrayList(java.util.ArrayList) AuthContext(com.sun.identity.authentication.AuthContext) URI(java.net.URI) Subject(com.sun.identity.xacml.context.Subject) URISyntaxException(java.net.URISyntaxException) XACMLException(com.sun.identity.xacml.common.XACMLException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) Test(org.testng.annotations.Test)

Example 13 with Attribute

use of com.sun.identity.xacml.context.Attribute in project OpenAM by OpenRock.

the class ResourceImpl method processElement.

private void processElement(Element element) throws XACMLException {
    if (element == null) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid root element");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
    }
    String elemName = element.getLocalName();
    if (elemName == null) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): local name missing");
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_local_name"));
    }
    if (!elemName.equals(XACMLConstants.RESOURCE)) {
        XACMLSDKUtils.debug.error("ResourceImpl.processElement(): invalid local name " + elemName);
        throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_local_name"));
    }
    // starts processing subelements
    NodeList nodes = element.getChildNodes();
    int numOfNodes = nodes.getLength();
    if (numOfNodes > 0) {
        ContextFactory factory = ContextFactory.getInstance();
        for (int i = 0; i < numOfNodes; i++) {
            Node child = (Node) nodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                String childName = child.getLocalName();
                // <ResourceContent>
                if (childName.equals(XACMLConstants.ATTRIBUTE)) {
                    if (attributes == null) {
                        attributes = new ArrayList();
                    }
                    Attribute attribute = factory.getInstance().createAttribute((Element) child);
                    attributes.add(attribute);
                } else if (childName.equals(XACMLConstants.RESOURCE_CONTENT)) {
                    resourceContent = (Element) child;
                }
            }
        }
    } else {
    /* not a schema violation
             XACMLSDKUtils.debug.error(
                "ResourceImpl.processElement(): no attributes or resource "
                +"content");
            throw new XACMLException( 
                XACMLSDKUtils.xacmlResourceBundle.getString(
                "missing_subelements"));
            */
    }
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) XACMLException(com.sun.identity.xacml.common.XACMLException)

Example 14 with Attribute

use of com.sun.identity.xacml.context.Attribute in project OpenAM by OpenRock.

the class ResourceImpl method toXMLString.

/**
    * Returns a <code>String</code> representation of this object
    * @param includeNSPrefix Determines whether or not the namespace qualifier
    *        is prepended to the Element when converted
    * @param declareNS Determines whether or not the namespace is declared
    *        within the Element.
    * @return a string representation of this object
    * @exception XACMLException if conversion fails for any reason
     */
public String toXMLString(boolean includeNSPrefix, boolean declareNS) throws XACMLException {
    StringBuffer sb = new StringBuffer(2000);
    StringBuffer NS = new StringBuffer(100);
    String appendNS = "";
    if (declareNS) {
        NS.append(XACMLConstants.CONTEXT_NS_DECLARATION).append(XACMLConstants.SPACE);
        NS.append(XACMLConstants.XSI_NS_URI).append(XACMLConstants.SPACE).append(XACMLConstants.CONTEXT_SCHEMA_LOCATION);
    }
    if (includeNSPrefix) {
        appendNS = XACMLConstants.CONTEXT_NS_PREFIX + ":";
    }
    sb.append("<").append(appendNS).append(XACMLConstants.RESOURCE).append(NS);
    sb.append(">");
    int length = 0;
    if (attributes != null) {
        sb.append("\n");
        length = attributes.size();
        for (int i = 0; i < length; i++) {
            Attribute attr = (Attribute) attributes.get(i);
            sb.append(attr.toXMLString(includeNSPrefix, false));
        }
    }
    if (resourceContent != null) {
        sb.append("\n");
        // ignore trailing ":"
        if (includeNSPrefix && (resourceContent.getPrefix() == null)) {
            resourceContent.setPrefix(appendNS.substring(0, appendNS.length() - 1));
        }
        if (declareNS) {
            int index = NS.indexOf("=");
            String namespaceName = NS.substring(0, index);
            String namespaceURI = NS.substring(index + 1);
            if (resourceContent.getNamespaceURI() == null) {
                resourceContent.setAttribute(namespaceName, namespaceURI);
            // does not seem to work to append namespace TODO
            }
        }
        sb.append(XMLUtils.print(resourceContent));
    }
    sb.append("</").append(appendNS).append(XACMLConstants.RESOURCE);
    sb.append(">\n");
    return sb.toString();
}
Also used : Attribute(com.sun.identity.xacml.context.Attribute)

Example 15 with Attribute

use of com.sun.identity.xacml.context.Attribute in project OpenAM by OpenRock.

the class XACMLSDKUtils method createAttribute.

public static Attribute createAttribute(List values, URI attributeId, URI dataType, String issuer) throws XACMLException {
    ContextFactory factory = ContextFactory.getInstance();
    Attribute attr = null;
    attr = factory.getInstance().createAttribute();
    attr.setAttributeId(attributeId);
    attr.setDataType(dataType);
    attr.setAttributeValues(values);
    ;
    attr.setIssuer(issuer);
    return attr;
}
Also used : ContextFactory(com.sun.identity.xacml.context.ContextFactory) Attribute(com.sun.identity.xacml.context.Attribute)

Aggregations

Attribute (com.sun.identity.xacml.context.Attribute)17 URI (java.net.URI)9 ArrayList (java.util.ArrayList)9 XACMLException (com.sun.identity.xacml.common.XACMLException)7 List (java.util.List)6 ContextFactory (com.sun.identity.xacml.context.ContextFactory)5 Subject (com.sun.identity.xacml.context.Subject)5 Element (org.w3c.dom.Element)5 Request (com.sun.identity.xacml.context.Request)4 Resource (com.sun.identity.xacml.context.Resource)4 Node (org.w3c.dom.Node)4 NodeList (org.w3c.dom.NodeList)4 SSOException (com.iplanet.sso.SSOException)3 SSOToken (com.iplanet.sso.SSOToken)3 Action (com.sun.identity.xacml.context.Action)3 Environment (com.sun.identity.xacml.context.Environment)3 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2 Decision (com.sun.identity.xacml.context.Decision)2 Response (com.sun.identity.xacml.context.Response)2 Result (com.sun.identity.xacml.context.Result)2