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;
}
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);
}
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"));
*/
}
}
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();
}
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;
}
Aggregations