/** * <p>Return a formatted string representing the reference to the given {@link org.picketlink.idm.model.IdentityType}.</p> * * @param identityType * * @return */ public static String formatId(final IdentityType identityType) { return identityType.getClass().getName() + ID_SEPARATOR + identityType.getPartition().getId() + ID_SEPARATOR + identityType.getId(); }
/** * <p> * Updated the common properties for a specific {@link IdentityType} instance from another instance. * </p> * * @param fromIdentityType * @param toIdentityType */ private void updateCommonProperties(IdentityType fromIdentityType, IdentityType toIdentityType) { toIdentityType.setEnabled(fromIdentityType.isEnabled()); toIdentityType.setCreatedDate(fromIdentityType.getCreatedDate()); toIdentityType.setExpirationDate(fromIdentityType.getExpirationDate()); for (Object object : toIdentityType.getAttributes().toArray()) { Attribute<? extends Serializable> attribute = (Attribute<? extends Serializable>) object; toIdentityType.removeAttribute(attribute.getName()); } for (Attribute<? extends Serializable> attrib : fromIdentityType.getAttributes()) { toIdentityType.setAttribute(attrib); } }
@Override protected IdentityType doPopulateEntry(Map<String, Serializable> properties) throws Exception { IdentityType identityType = super.doPopulateEntry(properties); String partitionType = properties.get("partitionType").toString(); String partitionId = properties.get("partitionId").toString(); Partition partition = (Partition) Class.forName(partitionType).getConstructor(new Class[]{String.class}).newInstance(""); partition.setId(partitionId); identityType.setPartition(partition); identityType.setCreatedDate((Date) properties.get("createdDate")); identityType.setExpirationDate((Date) properties.get("expirationDate")); identityType.setEnabled((Boolean) properties.get("enabled")); return identityType; }
IdentityType identityType = (IdentityType) attributedType; identityType.setPartition(context.getPartition()); clonedIdentityType.setPartition(identityType.getPartition()); clonedIdentityType.setExpirationDate(identityType.getExpirationDate()); clonedIdentityType.setCreatedDate(identityType.getCreatedDate()); clonedIdentityType.setEnabled(identityType.isEnabled()); } else if (Relationship.class.isInstance(attributedType)) { Relationship relationship = (Relationship) attributedType;
protected FilePermission(IdentityType identityType, Permission permission) { super(VERSION, permission); this.identityTypeId = identityType.getId(); }
return o1.getId().compareTo(o2.getId()); } else if (queryParameter.equals(IdentityType.ENABLED)) { return Boolean.valueOf(o1.isEnabled()).compareTo(o2.isEnabled()); } else if (queryParameter.equals(IdentityType.CREATED_DATE)) { return o1.getCreatedDate().compareTo(o2.getCreatedDate()); } else if (queryParameter.equals(IdentityType.EXPIRY_DATE)) { return o1.getExpirationDate().compareTo(o2.getExpirationDate());
@Override protected void doPopulateProperties(Map<String, Serializable> properties) throws Exception { super.doPopulateProperties(properties); IdentityType identityType = getEntry(); if (identityType.getPartition() == null) { throw new IllegalStateException("Partition Null"); } if (identityType.getPartition().getId() == null) { throw new IllegalStateException("Partition ID Null"); } properties.put("partitionId", identityType.getPartition().getId()); properties.put("partitionType", identityType.getPartition().getClass().getName()); properties.put("createdDate", identityType.getCreatedDate()); if (identityType.getExpirationDate() != null) { properties.put("expirationDate", identityType.getExpirationDate()); } properties.put("enabled", identityType.isEnabled()); } }
/** * <p> * Populates the given {@link Object} argument representing a Identity Class (from the config) with the information from the * specified {@link IdentityType}. * </p> * * @param toIdentity * @param fromIdentityType */ protected void populateIdentityInstance(Realm realm, Object toIdentity, T fromIdentityType, JPAIdentityStore store) { // populate the common properties from IdentityType String identityDiscriminator = store.getConfig().getIdentityDiscriminator(fromIdentityType.getClass()); store.setModelProperty(toIdentity, PROPERTY_IDENTITY_DISCRIMINATOR, identityDiscriminator, true); store.setModelProperty(toIdentity, PROPERTY_IDENTITY_KEY, fromIdentityType.getKey(), true); store.setModelProperty(toIdentity, PROPERTY_IDENTITY_ENABLED, fromIdentityType.isEnabled(), true); store.setModelProperty(toIdentity, PROPERTY_IDENTITY_CREATED, fromIdentityType.getCreatedDate(), true); store.setModelProperty(toIdentity, PROPERTY_IDENTITY_EXPIRES, fromIdentityType.getExpirationDate()); if (realm != null) { store.setModelProperty(toIdentity, PROPERTY_IDENTITY_PARTITION, store.lookupPartitionObject(realm)); } doPopulateIdentityInstance(toIdentity, fromIdentityType, store); }
/** * <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()); }
/** * <p> * Creates a {@link IdentityType} instance using the information from the given Identity Class instance. This method already * provides the mapping for the common properties for all {@link IdentityType} types. * </p> * * @param realm * @param identity * @return */ public T createIdentityType(Realm realm, Object identity, JPAIdentityStore store) { T identityType = doCreateIdentityType(identity, store); identityType.setEnabled(store.getModelProperty(Boolean.class, identity, PROPERTY_IDENTITY_ENABLED)); identityType.setExpirationDate(store.getModelProperty(Date.class, identity, JPAIdentityStoreConfiguration.PROPERTY_IDENTITY_EXPIRES)); identityType.setCreatedDate(store.getModelProperty(Date.class, identity, JPAIdentityStoreConfiguration.PROPERTY_IDENTITY_CREATED)); return identityType; }
public Set<Partition> getRelationshipPartitions(Relationship relationship) { Set<Partition> partitions = new HashSet<Partition>(); for (Property<? extends IdentityType> prop : getRelationshipIdentityProperties(relationship.getClass())) { IdentityType identity = prop.getValue(relationship); if (!partitions.contains(identity.getPartition())) { partitions.add(identity.getPartition()); } } return partitions; }
if (identityType.getPartition() == null) { Partition partition = context.getPartition(); identityType.setPartition(partition);
private void configurePartition(Partition partition, Object identity, IdentityType identityType) { if (getConfig().isModelPropertySet(PROPERTY_IDENTITY_PARTITION)) { // TODO implement cache support for partitions Object partitionInstance = getModelProperty(Object.class, identity, PROPERTY_IDENTITY_PARTITION); identityType.setPartition(convertPartitionEntityToPartition(partitionInstance)); } else { identityType.setPartition(partition); } }
/** * <p> * Removes an attribute. * </p> * * @throws Exception */ @Test public void testRemoveAttribute() 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); updatedIdentityTypeInstance.removeAttribute("multi-valued"); updateIdentityType(updatedIdentityTypeInstance); updatedIdentityTypeInstance = getIdentityType(false); multiValuedAttribute = updatedIdentityTypeInstance.getAttribute("multi-valued"); assertNull(multiValuedAttribute); }
/** * <p> * Expires an user. * </p> * * @throws Exception */ @Test public void testExpiration() throws Exception { T validIdentityTypeInstance = getIdentityType(true); Date expirationDate = new Date(); validIdentityTypeInstance.setExpirationDate(expirationDate); updateIdentityType(validIdentityTypeInstance); T expiredIdentityTypeInstance = getIdentityType(false); Thread.sleep(500); assertNotNull(expiredIdentityTypeInstance.getExpirationDate()); assertTrue(new Date().after(expiredIdentityTypeInstance.getExpirationDate())); assertTrue(expirationDate.compareTo(expiredIdentityTypeInstance.getExpirationDate()) == 0); }
/** * <p> * Disables an user. * </p> * * @throws Exception */ @Test public void testDisable() throws Exception { T enabledIdentityTypeInstance = getIdentityType(true); assertTrue(enabledIdentityTypeInstance.isEnabled()); enabledIdentityTypeInstance.setEnabled(false); updateIdentityType(enabledIdentityTypeInstance); T disabledIdentityTypeInstance = getIdentityType(false); assertFalse(disabledIdentityTypeInstance.isEnabled()); disabledIdentityTypeInstance.setEnabled(true); updateIdentityType(disabledIdentityTypeInstance); enabledIdentityTypeInstance = getIdentityType(false); assertTrue(enabledIdentityTypeInstance.isEnabled()); }
Attribute<Serializable> userAttribute = fileUser.getAttribute(customParameter.getName()); boolean match = false;
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")); Collection<Attribute<? extends Serializable>> allAttributes = updatedIdentityTypeInstance.getAttributes();
private void updateAttributes(IdentityType identityType, Object identity) { EntityManager em = getEntityManager(); if (identityType.getAttributes() != null && !identityType.getAttributes().isEmpty()) { List<String> attributesToRetain = new ArrayList<String>(); for (Attribute<? extends Serializable> userAttribute : identityType.getAttributes()) { attributesToRetain.add(userAttribute.getName());
IdentityType identityType = (IdentityType) attributedType; identityType.setPartition(context.getPartition()); clonedIdentityType.setPartition(identityType.getPartition()); clonedIdentityType.setExpirationDate(identityType.getExpirationDate()); clonedIdentityType.setCreatedDate(identityType.getCreatedDate()); clonedIdentityType.setEnabled(identityType.isEnabled()); } else if (Relationship.class.isInstance(attributedType)) { Relationship relationship = (Relationship) attributedType;