[java-identity-provider COMMIT] in /trunk/idp-attribute-resolver-impl/src: main/java/net/shibboleth/idp/attribute/res...
noreply at shibboleth.net
noreply at shibboleth.net
Thu Mar 28 08:22:24 EDT 2013
Author: rdw
Date: Thu Mar 28 08:22:24 2013
New Revision: 4366
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=4366&view=rev
Log:
IDP-206 Recast the environment that the scripted Attribute resolver lives in to provide visibility to things which look like real attributes. Also the start of support for V2 scripting. Test coverage and documentation to follow.
Added:
trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttribute.java (with props)
trunk/idp-attribute-resolver-impl/src/test/resources/data/net/shibboleth/idp/attribute/resolver/impl/ad/simple2.script
Modified:
trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeDefinition.java
trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/JscriptAttribute.java
trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeTest.java
trunk/idp-attribute-resolver-impl/src/test/java/net/shibboleth/idp/attribute/resolver/impl/ad/TestContextContainer.java
trunk/idp-attribute-resolver-impl/src/test/resources/data/net/shibboleth/idp/attribute/resolver/impl/ad/attributes.script
trunk/idp-attribute-resolver-impl/src/test/resources/data/net/shibboleth/idp/attribute/resolver/impl/ad/context.script
trunk/idp-attribute-resolver-impl/src/test/resources/data/net/shibboleth/idp/attribute/resolver/impl/ad/simple.script
trunk/idp-attribute-resolver-impl/src/test/resources/data/net/shibboleth/idp/attribute/resolver/impl/ad/simpleWithPredef.script
Modified: trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeDefinition.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeDefinition.java?rev=4366&r1=4365&r2=4366&view=diff
==============================================================================
--- trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeDefinition.java (original)
+++ trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/ad/ScriptedAttributeDefinition.java Thu Mar 28 08:22:24 2013
@@ -104,11 +104,26 @@
try {
script.eval(context);
} catch (ScriptException e) {
- throw new ResolutionException("ScriptletAttributeDefinition " + getId()
- + " unable to execute script", e);
+ throw new ResolutionException("AttributeDefinition '" + getId() + "' unable to execute script", e);
+ }
+ Object result = context.getAttribute(getId());
+
+ if (null == result) {
+ log.info("AttributeDefinition '{}' No value returned", getId());
+ return Optional.absent();
}
- return Optional.fromNullable((Attribute) context.getAttribute(getId()));
+ if (result instanceof ScriptedAttribute) {
+
+ ScriptedAttribute scriptedAttribute = (ScriptedAttribute) result;
+ return Optional.of(scriptedAttribute.getResultingAttribute());
+
+ } else {
+
+ throw new ResolutionException("AttributeDefinition '" + getId() + "'returned variable was of wrong type ("
+ + result.getClass().toString() + ")");
+ }
+
}
/** {@inheritDoc} */
@@ -128,28 +143,35 @@
*
* @return constructed script context
*
- * @throws ResolutionException thrown if dependent data connectors or attribute definitions can not be
- * resolved
+ * @throws ResolutionException thrown if dependent data connectors or attribute definitions can not be resolved
*/
@Nonnull private ScriptContext getScriptContext(@Nonnull final AttributeResolutionContext resolutionContext)
throws ResolutionException {
Constraint.isNotNull(resolutionContext, "Attribute resolution context can not be null");
final SimpleScriptContext scriptContext = new SimpleScriptContext();
+ final Map<String, Set<AttributeValue>> dependencyAttributes =
+ PluginDependencySupport.getAllAttributeValues(resolutionContext, getDependencies());
- log.debug("Attribute definition '{}': adding to-be-populated attribute to script context", getId());
- scriptContext.setAttribute(getId(), new Attribute(getId()), ScriptContext.ENGINE_SCOPE);
+ if (dependencyAttributes.containsKey(getId())) {
+ log.debug("Attribute definition '{}': to-be-populated attribute is a dependency. Not created");
+ } else {
+ log.debug("Attribute definition '{}': adding to-be-populated attribute to script context", getId());
+ final Attribute newAttribute = new Attribute(getId());
+ scriptContext.setAttribute(getId(), new ScriptedAttribute(newAttribute), ScriptContext.ENGINE_SCOPE);
[... 182 lines stripped ...]
More information about the commits
mailing list