@Test public void testWrongType() throws Exception { final int[] intArray = {1, 2, 3, 4}; final Collection<? extends IdPAttributeValue<?>> values = Arrays.asList( new IdPAttributeValue<Object>() { public Object getValue() { return intArray; } public String getDisplayValue() { return intArray.toString(); } }, saml2NameIdFor(OTHERID)); final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME); inputAttribute.setValues(values); prc.getSubcontext(RelyingPartyContext.class) .getSubcontext(AttributeContext.class, true) .setIdPAttributes(Collections.singleton(inputAttribute)); generator.setAttributeSourceIds(Collections.singletonList(ATTR_NAME)); generator.initialize(); Assert.assertNull(generator.generate(prc, generator.getFormat())); }
@Test public void testWrongFormat() throws Exception { final Collection<? extends IdPAttributeValue<?>> values = Collections.singletonList(saml1NameIdFor(NAME_1)); final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME); inputAttribute.setValues(values); prc.getSubcontext(RelyingPartyContext.class) .getSubcontext(AttributeContext.class, true) .setIdPAttributes(Collections.singleton(inputAttribute)); generator.setFormat(NameIdentifier.EMAIL); generator.setAttributeSourceIds(Collections.singletonList(ATTR_NAME)); generator.initialize(); Assert.assertNull(generator.generate(prc, generator.getFormat())); }
/** {@inheritDoc} */ @Override @Nullable protected IdPAttribute doAttributeDefinitionResolve( @Nonnull final AttributeResolutionContext resolutionContext, @Nonnull final AttributeResolverWorkContext workContext) throws ResolutionException { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ComponentSupport.ifDestroyedThrowDestroyedComponentException(this); List<? extends IdPAttributeValue<?>> inputValues; List<? extends IdPAttributeValue<?>> outputValues = null; final IdPAttribute result = new IdPAttribute(getId()); inputValues = PluginDependencySupport.getMergedAttributeValues(workContext, getDependencies(), getId()); if (null != inputValues && !inputValues.isEmpty()) { if (1 == inputValues.size()) { final IdPAttributeValue<?> val = encodeOneValue(inputValues.iterator().next(), resolutionContext); if (null != val) { outputValues = Collections.singletonList(val); } } else { // TODO(rdw) Fix typing // Intermediate to solve typing issues. final List<XMLObjectAttributeValue> xmlVals = new ArrayList<>(inputValues.size()); for (final IdPAttributeValue<?> theValue : inputValues) { final XMLObjectAttributeValue val = encodeOneValue(theValue, resolutionContext); if (null != val) { xmlVals.add(val); } } if (0 == xmlVals.size()) { log.warn("{} No appropriate values", getLogPrefix()); return null; } outputValues = xmlVals; } } result.setValues(outputValues); return result; }
@Test public void testNameIdentifierValued() throws Exception { final Collection<? extends IdPAttributeValue<?>> values = Collections.singletonList(saml1NameIdFor(NAME_1)); final IdPAttribute inputAttribute = new IdPAttribute(ATTR_NAME); inputAttribute.setValues(values); prc.getSubcontext(RelyingPartyContext.class) .getSubcontext(AttributeContext.class, true) .setIdPAttributes(Collections.singleton(inputAttribute)); generator.setAttributeSourceIds(Collections.singletonList(ATTR_NAME)); generator.initialize(); final NameIdentifier outputNameId = generator.generate(prc, generator.getFormat()); Assert.assertNotNull(outputNameId); Assert.assertEquals(outputNameId.getValue(), NAME_1); Assert.assertEquals(outputNameId.getFormat(), NameIdentifier.X509_SUBJECT); Assert.assertEquals(outputNameId.getNameQualifier(), QUALIFIER); }