private Map<String, Serializable> getAttributes(AttributedType attributedType) { HashMap<String, Serializable> attributes = new HashMap<String, Serializable>(); for (Attribute attribute : attributedType.getAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } return attributes; } }
/** * Represents the generated TOTP secret for the current User logged in. */ @Produces @Secret public String getSecret() { User user = (User) identity.getAccount(); Attribute<String> secret = user.getAttribute(IDM_SECRET_ATTRIBUTE); if (secret == null) { secret = new Attribute<String>(IDM_SECRET_ATTRIBUTE, Base32.random()); user.setAttribute(secret); this.identityManager.update(user); } return secret.getValue(); }
attribute = new Attribute<Serializable>(storedName, storedValue); } else { Serializable[] values = null; if (attribute.getValue().getClass().isArray()) { values = (Serializable[]) attribute.getValue(); } else { values = (Serializable[]) Array.newInstance(attribute.getValue().getClass(), 1); values[0] = attribute.getValue(); attribute.setValue(newValues); attributes.put(attribute.getName(), attribute);
@Override protected Collection<Attribute<? extends Serializable>> doPopulateEntry(Map<String, Serializable> properties) throws Exception { List<Attribute<? extends Serializable>> attributes = new ArrayList<Attribute<?extends Serializable>>(); for (String name: properties.keySet()) { attributes.add(new Attribute(name, properties.get(name))); } return attributes; }
@Override public String getValue(Object instance) { if (!(instance instanceof AttributedType)) { throw new IllegalStateException("Instance [ " + instance + " ] not an instance of AttributedType"); } AttributedType attributedType = (AttributedType) instance; Attribute<String> attr = attributedType.getAttribute(bindingPropertyName); return attr!=null ? attr.getValue() : null; }
identityType.setAttribute(new Attribute<Serializable>(mappedName, (Serializable) value)); identityTypeAttribute = new Attribute<Serializable>(attribName, attribValue); identityType.setAttribute(identityTypeAttribute); } else { if (identityTypeAttribute.getValue() != null) { String[] values = null; if (identityTypeAttribute.getValue().getClass().isArray()) { values = (String[]) identityTypeAttribute.getValue(); } else { values = new String[1]; values[0] = identityTypeAttribute.getValue().toString(); identityTypeAttribute.setValue(newValues);
private Map<String, Attribute> getAttributes(IdentityContext identityContext, AttributedType identityType) { Map<String, Attribute> attributes = new HashMap<String, Attribute>(); for (Attribute attribute : identityType.getAttributes()) { attributes.put(attribute.getName(), attribute); } List<Property<Object>> properties = PropertyQueries.createQuery(identityType.getClass()) .addCriteria(new AnnotatedPropertyCriteria(AttributeProperty.class)) .getResultList(); for (Property property : properties) { AttributeProperty attributeProperty = property.getAnnotatedElement().getAnnotation(AttributeProperty.class); if (attributeProperty.managed()) { String attributeName = property.getName(); Object attributeValue = property.getValue(identityType); if (attributeValue != null) { attributes.put(attributeName, new Attribute(attributeName, (Serializable) attributeValue)); } else { attributes.remove(attributeName); } } } return attributes; }
public void setAttribute(Attribute<? extends Serializable> attribute) { attributes.put(attribute.getName(), attribute); }
serialArray[i++] = str.toString(); attribute.setValue(serialArray); } else if (Integer.class.getName().equals(attributeType)) { Integer[] serialArray = new Integer[valueList.size()]; serialArray[i++] = (Integer) str; attribute.setValue(serialArray); } else if (Long.class.getName().equals(attributeType)) { Long[] serialArray = new Long[valueList.size()]; serialArray[i++] = (Long) str; attribute.setValue(serialArray); } else if (Double.class.getName().equals(attributeType)) { Double[] serialArray = new Double[valueList.size()]; attribute.setValue(serialArray); } else if (Float.class.getName().equals(attributeType)) { Float[] serialArray = new Float[valueList.size()]; attribute.setValue(serialArray); } else if (Short.class.getName().equals(attributeType)) { Short[] serialArray = new Short[valueList.size()]; attribute.setValue(serialArray);
@Override protected Collection<Attribute<? extends Serializable>> doPopulateEntry(Map<String, Serializable> properties) throws Exception { List<Attribute<? extends Serializable>> attributes = new ArrayList<Attribute<?extends Serializable>>(); for (String name: properties.keySet()) { attributes.add(new Attribute(name, properties.get(name))); } return attributes; }
@Override public String getValue(Object instance) { if (!(instance instanceof AttributedType)) { throw new IllegalStateException("Instance [ " + instance + " ] not an instance of AttributedType"); } AttributedType attributedType = (AttributedType) instance; Attribute<String> attr = attributedType.getAttribute(bindingPropertyName); return attr!=null ? attr.getValue() : null; }
/** * <p> * Updates an attribute. * </p> * * @throws Exception */ @Test public void testUpdateAttribute() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String[]>("multi-valued", new String[] { "1", "2", "3" })); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); Attribute<String[]> multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNotNull(multiValuedAttribute); multiValuedAttribute.setValue(new String[] { "3", "4", "5" }); updatedIdentityTypeInstance.setAttribute(multiValuedAttribute); updateIdentityType(updatedIdentityTypeInstance); updatedIdentityTypeInstance = getIdentityType(false); multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNotNull(multiValuedAttribute); assertEquals(3, multiValuedAttribute.getValue().length); String[] values = multiValuedAttribute.getValue(); Arrays.sort(values); assertTrue(Arrays.equals(values, new String[] { "3", "4", "5" })); }
private Map<String, Attribute> getAttributes(IdentityContext identityContext, AttributedType identityType) { Map<String, Attribute> attributes = new HashMap<String, Attribute>(); for (Attribute attribute : identityType.getAttributes()) { attributes.put(attribute.getName(), attribute); } List<Property<Object>> properties = PropertyQueries.createQuery(identityType.getClass()) .addCriteria(new AnnotatedPropertyCriteria(AttributeProperty.class)) .getResultList(); for (Property property : properties) { AttributeProperty attributeProperty = property.getAnnotatedElement().getAnnotation(AttributeProperty.class); if (attributeProperty.managed()) { String attributeName = property.getName(); Object attributeValue = property.getValue(identityType); if (attributeValue != null) { attributes.put(attributeName, new Attribute(attributeName, (Serializable) attributeValue)); } else { attributes.remove(attributeName); } } } return attributes; }
public void setAttribute(Attribute<? extends Serializable> attribute) { attributes.put(attribute.getName(), attribute); }
serialArray[i++] = str.toString(); attribute.setValue(serialArray); } else if (Integer.class.getName().equals(attributeType)) { Integer[] serialArray = new Integer[valueList.size()]; serialArray[i++] = (Integer) str; attribute.setValue(serialArray); } else if (Long.class.getName().equals(attributeType)) { Long[] serialArray = new Long[valueList.size()]; serialArray[i++] = (Long) str; attribute.setValue(serialArray); } else if (Double.class.getName().equals(attributeType)) { Double[] serialArray = new Double[valueList.size()]; attribute.setValue(serialArray); } else if (Float.class.getName().equals(attributeType)) { Float[] serialArray = new Float[valueList.size()]; attribute.setValue(serialArray); } else if (Short.class.getName().equals(attributeType)) { Short[] serialArray = new Short[valueList.size()]; attribute.setValue(serialArray);
private Map<String, Serializable> getAttributes(AttributedType attributedType) { HashMap<String, Serializable> attributes = new HashMap<String, Serializable>(); for (Attribute attribute : attributedType.getAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } return attributes; } }
/** * <p> * Sets multiple attributes and check if they are properly stored. * </p> * * @throws Exception */ @Test public void testSetMultipleAttributes() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String>("QuestionTotal", "2")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question1", "What is favorite toy?")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question1Answer", "Gum")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question2", "What is favorite word?")); storedIdentityTypeInstance.setAttribute(new Attribute<String>("Question2Answer", "Hi")); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); assertEquals("2", updatedIdentityTypeInstance.<String> getAttribute("QuestionTotal").getValue()); assertEquals("What is favorite toy?", updatedIdentityTypeInstance.<String> getAttribute("Question1").getValue()); assertEquals("Gum", updatedIdentityTypeInstance.<String> getAttribute("Question1Answer").getValue()); assertEquals("What is favorite word?", updatedIdentityTypeInstance.<String[]> getAttribute("Question2").getValue()); assertEquals("Hi", updatedIdentityTypeInstance.<String> getAttribute("Question2Answer").getValue()); }
@Override public void setValue(Object instance, String value) { if (!(instance instanceof AttributedType)) { throw new IllegalStateException("Instance [ " + instance + " ] not an instance of AttributedType"); } AttributedType attributedType = (AttributedType) instance; attributedType.setAttribute(new Attribute(bindingPropertyName, value)); }