use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.
the class UpgradeUtils method removeAttributesFromSchema.
protected static void removeAttributesFromSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
if (!(schemaMods.getAttributes().isEmpty())) {
for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
removeAttributeSchema(serviceName, null, schemaType, attrs.getName(), adminToken);
}
}
if (schemaMods.hasSubSchema()) {
for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
if (!(schema.getValue().getAttributes().isEmpty())) {
for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
ServiceSchema subSchema = null;
try {
subSchema = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to remove attributes from schema", smse);
throw new UpgradeException(smse);
}
removeAttributeSchema(subSchema, attrs.getName());
}
}
if (schema.getValue().hasSubSchema()) {
ServiceSchema ss = null;
try {
ss = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to remove attributes from schema", smse);
throw new UpgradeException(smse);
}
removeAttributesFromSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
}
}
}
}
use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.
the class UpgradeUtils method modifyAttributesInExistingSchema.
protected static void modifyAttributesInExistingSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
modifyAttributeInExistingSchema(serviceName, null, schemaType, attrs.getName(), attrs.getAttributeSchemaNode(), adminToken);
}
if (schemaMods.hasSubSchema()) {
for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
ServiceSchema subSchema = null;
try {
subSchema = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to modify attributes in schema", smse);
throw new UpgradeException(smse);
}
modifyAttributeInExistingSchema(subSchema, attrs.getName(), attrs.getAttributeSchemaNode());
}
if (schema.getValue().hasSubSchema()) {
ServiceSchema ss = null;
try {
ss = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to modify attributes in schema", smse);
throw new UpgradeException(smse);
}
modifyAttributesInExistingSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
}
}
}
}
use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.
the class UpgradeUtils method addAttributesToSchema.
protected static void addAttributesToSchema(String serviceName, String schemaType, ServiceSchemaModificationWrapper schemaMods, ServiceSchema serviceSchema, SSOToken adminToken) throws UpgradeException {
if (!(schemaMods.getAttributes().isEmpty())) {
for (AttributeSchemaImpl attrs : schemaMods.getAttributes()) {
addAttributeToSchema(serviceName, null, schemaType, attrs.getAttributeSchemaNode(), adminToken);
}
}
if (schemaMods.hasSubSchema()) {
for (Map.Entry<String, ServiceSchemaModificationWrapper> schema : schemaMods.getSubSchemas().entrySet()) {
if (!(schema.getValue().getAttributes().isEmpty())) {
for (AttributeSchemaImpl attrs : schema.getValue().getAttributes()) {
ServiceSchema subSchema = null;
try {
subSchema = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to add attributes to schema", smse);
throw new UpgradeException(smse);
}
addAttributeToSchema(subSchema, attrs.getAttributeSchemaNode());
}
}
if (schema.getValue().hasSubSchema()) {
ServiceSchema ss = null;
try {
ss = serviceSchema.getSubSchema(schema.getKey());
} catch (SMSException smse) {
debug.error("Unable to add attributes to schema", smse);
throw new UpgradeException(smse);
}
addAttributesToSchema(serviceName, schemaType, schema.getValue(), ss, adminToken);
}
}
}
}
use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.
the class UpgradeUtils method addNewSchema.
/**
* Adds a new Schema to an already existing service.
*
* @param serviceName The name of the service that needs to be extended.
* @param schemaChanges A "container" object holding the details of the new schema.
* @param adminToken An admin token.
* @throws UpgradeException If there was an error while trying to add the new schema to the service.
*/
public static void addNewSchema(String serviceName, SchemaUpgradeWrapper schemaChanges, SSOToken adminToken) throws UpgradeException {
try {
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminToken);
InputStream schemaStream = ssm.getSchema();
Document dom = XMLUtils.toDOMDocument(schemaStream, debug);
NodeList schemaElements = dom.getElementsByTagName("Schema");
String schemaName = schemaChanges.getNewSchema().getSchemaName();
debug.message("Adding new " + schemaName + " schema to " + serviceName);
if (schemaElements.getLength() == 1) {
Node schemaElement = schemaElements.item(0);
NodeList schemas = schemaElement.getChildNodes();
Node newNextSibling = null;
int idx = SCHEMA_ORDER.indexOf(schemaName);
for (int i = 0; i < schemas.getLength(); i++) {
Node node = schemas.item(i);
int currentIdx = SCHEMA_ORDER.indexOf(node.getNodeName());
if (currentIdx > idx) {
newNextSibling = node;
break;
}
}
String xml = "<" + schemaName + "></" + schemaName + ">";
Document doc = XMLUtils.toDOMDocument(xml, debug);
for (AttributeSchemaImpl attr : schemaChanges.getNewSchema().getAttributes()) {
Node imported = doc.importNode(attr.getAttributeSchemaNode(), true);
doc.getDocumentElement().appendChild(imported);
}
Node schemaNode = dom.importNode(doc.getDocumentElement(), true);
schemaElement.insertBefore(schemaNode, newNextSibling);
InputStream is = new ByteArrayInputStream(XMLUtils.print(dom.getDocumentElement()).getBytes());
ssm.replaceSchema(is);
} else {
debug.error("Unexpected number of Schema element in service XML for " + serviceName + "\n" + XMLUtils.print(dom));
throw new UpgradeException("Unexpected number of Schema element in service XML for " + serviceName);
}
} catch (Exception ex) {
UpgradeProgress.reportEnd("upgrade.failed");
debug.error("An error occurred while trying to add new schema to service: " + serviceName, ex);
throw new UpgradeException(ex);
}
}
use of com.sun.identity.sm.AttributeSchemaImpl in project OpenAM by OpenRock.
the class SessionServiceHelper method addNewAttribute.
@Override
public AttributeSchemaImpl addNewAttribute(Set<AttributeSchemaImpl> existingAttrs, AttributeSchemaImpl newAttr) throws UpgradeException {
if (newAttr.getName().equals(SESSION_CONSTRAINT_HANDLER_ATTR)) {
for (AttributeSchemaImpl attr : existingAttrs) {
if (attr.getName().equals(SESSION_CONSTRAINT_HANDLER_OLD_ATTR)) {
Set<String> defaultValues = attr.getDefaultValues();
Set<String> newDefaultValues = new HashSet<String>();
if (destroyAllSessionsSet() && defaultValues.contains(DESTROY_OLD_SESSION)) {
newDefaultValues.add(DESTROY_ALL_SESSIONS_CLASS);
newAttr = updateDefaultValues(newAttr, newDefaultValues);
} else if (defaultValues.contains(DENY_ACCESS)) {
newDefaultValues.add(NEW_DENY_ACCESS);
newAttr = updateDefaultValues(newAttr, newDefaultValues);
} else if (destroyOldestSessionSet()) {
newDefaultValues.add(DESTROY_OLDEST_SESSION_CLASS);
newAttr = updateDefaultValues(newAttr, newDefaultValues);
}
break;
}
}
} else if (REDUCED_CROSSTALK_ENABLED.equals(newAttr.getName())) {
updateDefaultValues(newAttr, asSet("false"));
}
return newAttr;
}
Aggregations