@Override public <T extends CredentialStorage> T retrieveCurrentCredential(Agent agent, Class<T> storageClass) { T storage = null; List<Property<Object>> annotatedTypes = PropertyQueries.createQuery(storageClass) .addCriteria(new AnnotatedPropertyCriteria(Stored.class)).getResultList(); if (annotatedTypes.isEmpty()) { throw new IdentityManagementException("Could not find any @Stored annotated method for CredentialStorage type [" + storageClass.getName() + "]."); } else { Property<Object> storedProperty = annotatedTypes.get(0); org.picketlink.idm.model.Attribute<Serializable> credentialAttribute = agent.getAttribute(storageClass.getName()); if (credentialAttribute != null) { try { storage = storageClass.newInstance(); } catch (Exception e) { throw new IdentityManagementException("Error while creating a " + storageClass.getName() + " storage instance.", e); } storedProperty.setValue(storage, credentialAttribute.getValue()); } else { throw new IdentityManagementException( "Methods annotated with @Stored should aways return a serializable object."); } } return storage; }
/** * <p> * Updates the stored agent information. * </p> * * @throws Exception */ @Test public void testUpdate() throws Exception { Agent storedAgent = getIdentityType(true); assertNotNull(storedAgent); assertEquals("someAgent", storedAgent.getId()); IdentityManager identityManager = getIdentityManager(); storedAgent.setAttribute(new Attribute<String>("someAttribute", "1")); identityManager.update(storedAgent); // let's load again the user from the store and check for the updated information Agent updatedUser = identityManager.getAgent(storedAgent.getId()); assertNotNull(updatedUser.getAttribute("someAttribute")); assertEquals("1", updatedUser.getAttribute("someAttribute").getValue()); }