/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: ServiceSchema.java,v 1.12 2008/08/30 16:46:47 goodearth Exp $
*
* Portions Copyrighted 2011-2016 ForgeRock AS.
*/
/**
* The class <code>ServiceSchema</code> provides interfaces to manage the
* schema information of a service. The schema for a service can be one of the
* following types: GLOBAL, ORGANIZATION, DYNAMIC, USER, and POLICY.
*
* @supported.all.api
*/
public class ServiceSchema {
// Pointer to service's schema manager & type
boolean orgAttrSchema;
/**
* Default constructor (private).
*/
private ServiceSchema() {
// do nothing
}
}
{
this.componentName = compName;
this.orgAttrSchema = isOrgAttrSchema;
}
/**
* Returns the name of the service.
*
* @return the name of the schema
*/
}
/**
* Returns the version of the service.
*
* @return version of the service schema
*/
return (ssm.getVersion());
}
/**
* Returns the name of the schema.
*
* @return the name of the schema
*/
}
/**
* Returns the schema type.
*
* @return the schema type.
*/
return (type);
}
/**
* Returns the I18N key that points to the description of the service.
*
* @return the I18N key that points to the description of the service
*/
return (ss.getI18NKey());
}
/**
* Returns <code>true</code> if service schema supports multiple
* configurations; <code>false</code> otherwise
*
* @return <code>true</code> if service schema supports multiple
* configurations; <code>false</code> otherwise
*/
public boolean supportsMultipleConfigurations() {
return (ss.supportsMultipleConfigurations());
}
/**
* Sets the value of the I18N key in the service schema.
*
* @param key
* Value to be set for the I18N key of the service schema.
* @throws SMSException
* if there is a problem setting the value in the data store.
* @throws SSOException
* If the user has an invalid SSO token.
*/
.getDocument());
}
/**
* Set the value of inheritance attribute in service schema.
*
* @param value
* New value of inheritance attribute.
* @throws SMSException
* if there is a problem setting the value in the data store.
* @throws SSOException
* if the user has an invalid single sign on token.
*/
"sms-invalid-inheritance-value", arg);
}
.getDocument());
}
/**
* Returns the view bean URL for this service
*
* @return file name that contains I18N messages
*/
return (ssm.getPropertiesViewBeanURL());
}
/**
* Returns the name of the status attribute, as defined in the Service
* schema
*
* @return String name of status attribute
*/
return (ss.getStatusAttribute());
}
/**
* Returns <code>true</code> if the service configuration created can be
* exported to other organizations.
*
* @return <code>true</code> if service configurations for this schema can
* be exported to other organizations; <code>false</code>
* otherwise.
*/
public boolean isExportable() {
return (false);
}
/**
* Sets the exportable nature of the service configurations created for this
* schema. Setting it to <code>true</code> allows the configurations to be
* exported to other organizations and a value of <code>false</code>
* disables exporting of configuration data.
*
* @param exportable
* <code>true</code> if service configurations for this schema
* can be exported to other organizations; <code>false</code>
* otherwise.
*/
}
/**
* Returns the I18N properties file name for the service schema.
*
* @return the I18N properties file name for the service schema
*/
}
/**
* Sets the I18N properties file name for the service schema
*
* @param url
* properties file name
* @throws SMSException
* if an error occurred while trying to perform the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
}
/**
* Returns the name for the service schema when used in a CREST representation.
*/
return name;
}
}
return getServiceName();
}
/**
* Should this service schema be hidden in the Configuration UI.
* @return True if it should be hidden.
*/
public boolean isHiddenInConfigUI() {
return ss.isHiddenInConfigUI();
}
/**
* During the creation of a new organisation/realm the services assigned to the parent realm are copied to the
* child realm. This will include the sub configs for that service, which in some cases are realm specific and will
* fail validation if copied. The schemas of these sub configs should set {@code realmCloneable} to {@code no} to
* avoid being copied.
*
* @return {@code true} if the config is cloneable between realms.
*/
public boolean isRealmCloneable() {
return ss.isRealmCloneable();
}
/**
* Sets the CREST resource name for the service schema.
*
* @param name
* resource name.
* @throws SMSException
* if an error occurred while trying to perform the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
ssm.replaceSchema((ServiceSchemaManagerImpl.getInstance(ssm.getSSOToken(), ssm.getName(), ssm.getVersion()))
.getDocument());
}
/**
* Returns the names of the schema attributes defined for the service. It
* does not return the schema attributes defined for the sub-schema.
*
* @return the names of schema attributes defined for the service
*/
return (ss.getAttributeSchemaNames());
}
/**
* Returns the names of the schema attributes defined for the service which
* are searchable. It does not return the schema attributes defined for the
* sub-schema.
*
* @return the names of schema attributes defined for the service which are
* searchable attributes.
*/
return (ss.getSearchableAttributeNames());
}
/**
* Returns the schema for an attribute given the name of the attribute,
* defined for this service. It returns only the attribute schema defined at
* the top level for the service and not from the sub-schema.
*
* @param attributeName
* the name of the schema attribute
* @return the schema for the attribute
*/
}
/**
* Returns the attribute schemas defined for the service. It does not return
* the schema attributes defined for the sub-schema.
*
* @return attribute schemas defined for the service
*/
.hasNext();) {
}
return (answer);
}
/**
* Returns the attribute schemas defined for the service that is not a
* status attribute and is not a service attribute. It does not return the
* schema attributes defined for the sub-schema.
*
* @return attribute schemas defined for the service
*/
return (ss.getServiceAttributeNames());
}
/**
* Validates the <code>attrMap</code> against the attributes defined in
* this schema of the service. It will throw an exception if the map
* contains any attribute not listed in the schema. It will also pick up
* default values for any attributes not in the map but which are listed in
* the schema, if the boolean <Code>inherit</Code> is set to true.
*
* @param attrMap
* map of attributes
* @param inherit
* if true, then inherit the default values
* @return Map of validated attributes with default values
* @throws SMSException
* if invalid attribute names are present in the
* <code>attrMap</code>.
*/
throws SMSException {
}
/**
* Validates the <code>attrMap</code> against the attributes defined in
* this schema of the service for the given organization. It will throw an
* exception if the map contains any attribute not listed in the schema. It
* will also pick up default values for any attributes not in the map but
* which are listed in the schema, if the boolean <Code>inherit</Code> is
* set to true.
*
* @param attrMap
* map of attributes
* @param inherit
* if true, then inherit the default values
* @return Map of validated attributes with default values
* @throws SMSException
* if invalid attribute names are present in the
* <code>attrMap</code>.
*/
boolean inherit) throws SMSException {
}
// This attribute is not listed in the service.
+ " is not listed in the service " + getServiceName());
throw new InvalidAttributeNameException(
"services_validator_invalid_attr_name", null);
}
}
// If orgName is not null, populate the envMap
}
// Inherit default values of this attribute, if
// required
// A required attribute is being deleted
// throw an exception.
+ attr + " is a required attribute and cannot"
+ " be deleted");
"sms-required-attribute-delete", args);
}
} else if (inherit) {
}
// validate the attribute against Schema
: null;
}
}
if (debug.messageEnabled()) {
}
return attrMap;
}
/**
* Adds the attribute schema to this service. The schema is defined in XML
* input stream that follows the SMS DTD.
*
* @param xmlAttrSchema
* the XML format of the attribute schema
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
throws SSOException, SMSException {
// Check if attribute exists
"sms-attributeschema-already-exists", args));
}
}
}
/**
* Removes the attribute schema from this service.
*
* @param attrName
* the name of the attribute schema
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
}
/**
* Returns a map of all the attribute and their default values in this
* schema.
*
* @return Map of Attribute Names and Sets of their default values as
* defined in the Schema
*/
return (ss.getAttributeDefaults());
}
/**
* Returns a map of all the attribute and their example values in this
* schema.
*
* @return Map of Attribute Names and Sets of their example values as
* defined in the Schema
*/
return (ss.getAttributeExamples());
}
/**
* Returns an unmodifiable map of all the attribute and their default values
* in this schema.
*
* @return Map of Attribute Names and Sets of their default values as
* defined in the Schema
*/
return (ss.getReadOnlyAttributeDefaults());
}
/**
* Method to change the default values of attributes in the schema.
*
* @param attrs
* A map of the names of <code>AttributeSchema</code> to
* modify, and a Set of Values which should replace the default
* values of the current schema.
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
// Get a copy of the XML document
"sms-invalid-attr-name", args));
}
}
// Save the document
}
/**
* Method to change default value for a specific attribute.
*
* @param attrName
* Name of the attribute for which defaults values need to be
* replaced.
* @param values
* Set of new values to replace the old ones.
* @throws SchemaException
* if an error occurred while parsing the XML
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
"sms-invalid-attr-name", args));
}
}
/**
* Removes the default values of attributes in the schema.
*
* @param attrs
* A set of the names of <code>AttributeSchema</code>.
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
throw (new InvalidAttributeNameException(
null));
}
}
}
/**
* Returns the names of sub-schemas for the service.
*
* @return the names of service's sub-schemas
*/
return ss.getSubSchemaNames();
}
/**
* Returns <code>ServiceSchema</code> object given the name of the
* service's sub-schema.
*
* @param subSchemaName
* the name of the service's sub-schema
* @return <code>ServiceSchema</code> object
* @throws SMSException
* if an error occurred while performing the operation
*
*/
{
}
return (answer);
}
/**
* Adds the service's sub-schema given the XML input stream that follows the
* SMS DTD.
*
* @param xmlSubSchema
* the XML format of the sub-schema
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
// Check if attribute exists
"sms-subschema-already-exists", args));
}
}
}
/**
* Removes the service's sub-schema from the service.
*
* @param subSchemaName
* the name of the service's sub-schema
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
}
/**
* Determines whether each attribute in the attribute set is valid. Iterates
* though the set checking each element to see if there is a validator that
* needs to execute.
*
* @param attributeSet
* the <code>Map</code> where key is the attribute name and
* value is the <code>Set</code> of attribute values
* @return true if all attributes are valid
* @throws SMSException
* if an error occurred while performing the operation
*/
null));
}
/**
* Determines whether each attribute in the attribute set is valid for the
* given organization. Iterates though the set checking each element to see
* if there is a validator that needs to execute.
*
* @param attributeSet
* the <code>Map</code> where key is the attribute name and
* value is the <code>Set</code> of attribute values
* @param orgName
* organization name
* @return true if all attributes are valid
* @throws SMSException
* if an error occurred while performing the operation
*/
throws SMSException {
orgName));
}
/**
* Returns string representation of the schema.
*
* @return string representation of the schema.
*/
}
/**
* Returns the Node of this schema element. Used by Policy component's
* <code>ServiceType</code> to get <code>ActionSchema</code>.
*
* @return the Node of this schema element. Used by Policy component's
* <code>ServiceType</code> to get <code>ActionSchema</code>.
*/
try {
} catch (SMSException ssme) {
}
return (node);
}
/**
* Removes the attribute schema from this service.
*
* @param attrName
* the name of the attribute schema
* @throws SMSException
* if an error occurred while performing the operation
* @throws SSOException
* if the single sign on token is invalid or expired
*/
}
}
try {
nextSibling = child;
break;
}
}
}
} catch (Exception e) {
}
}
}
try {
//In this case we've found an entry that is not an AttributeSchema, so this is definitely an
//element before which we can place a SubSchema. (i.e. the found element was a SubSchema or
//an OrganizationAttributeSchema). Note that this will change the order of the SubSchema
//elements in the service description, however the order should not matter for SMS.
nextSibling = child;
break;
}
}
}
}
// -----------------------------------------------------------
// Protected methods
// -----------------------------------------------------------
if (debug.messageEnabled()) {
+ componentName);
}
if (schemaNode != null) {
}
}
}
void replaceChildNode(String nodeType, String nodeName, Node attributeSchemaNode) throws SSOException,
if (debug.messageEnabled()) {
+ componentName);
}
if (schemaNode != null) {
}
} else {
if (debug.messageEnabled()) {
+ componentName);
}
}
}
// -----------------------------------------------------------
// Method to obtain schema node
// -----------------------------------------------------------
}
// Get the schema type node
}
}
// Walk the component name
return (stNode);
} else if (orgAttrSchema) {
// OrganizationAttributeSchema
return (XMLUtils
}
while (st.hasMoreTokens()) {
continue;
}
}
}
return (stNode);
}
// -----------------------------------------------------------
// Method to obtain organizationattributeschema node
// -----------------------------------------------------------
// Throw an exception
"sms-invalid-orgattr-schema-document", null));
}
}
return (rNode);
}
}
}