@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; }
@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; }
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; } }
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; } }
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; } }
@Override protected void doPopulateProperties(Map<String, Serializable> properties) throws Exception { for (Attribute attribute: new ArrayList<Attribute>(getEntry())) { properties.put(attribute.getName(), attribute.getValue()); } } }
@Override protected void doPopulateProperties(Map<String, Serializable> properties) throws Exception { for (Attribute attribute: new ArrayList<Attribute>(getEntry())) { properties.put(attribute.getName(), attribute.getValue()); } } }
@Override public void setAttribute(IdentityContext context, AttributedType attributedType, Attribute<? extends Serializable> attribute) { doSetAttribute(context, attributedType, attribute); attributedType.setAttribute(attribute); if (isTraceEnabled()) { IDENTITY_STORE_LOGGER.tracef("Ad-hoc attribute [%s] stored for type [%s] with identifier [%s] and value [%s]", attribute.getName(), attributedType.getClass(), attributedType.getId(), attribute.getValue()); } }
@Override public void setAttribute(IdentityContext context, AttributedType attributedType, Attribute<? extends Serializable> attribute) { doSetAttribute(context, attributedType, attribute); attributedType.setAttribute(attribute); if (isTraceEnabled()) { IDENTITY_STORE_LOGGER.tracef("Ad-hoc attribute [%s] stored for type [%s] with identifier [%s] and value [%s]", attribute.getName(), attributedType.getClass(), attributedType.getId(), attribute.getValue()); } }
@Override public void loadAttributes(IdentityContext identityContext, AttributedType attributedType) { Collection<Attribute<? extends Serializable>> attributes = getAttributes(identityContext, attributedType); for (Attribute attribute : attributes) { attributedType.setAttribute(attribute); if (isTraceEnabled()) { IDENTITY_STORE_LOGGER.tracef("Ad-hoc attribute [%s] loaded into type [%s] with identifier [%s] and value [%s]", attribute.getName(), attributedType.getClass(), attributedType.getId(), attribute.getValue()); } } loadManagedAttributes(attributedType); }
@Override public void loadAttributes(IdentityContext identityContext, AttributedType attributedType) { Collection<Attribute<? extends Serializable>> attributes = getAttributes(identityContext, attributedType); for (Attribute attribute : attributes) { attributedType.setAttribute(attribute); if (isTraceEnabled()) { IDENTITY_STORE_LOGGER.tracef("Ad-hoc attribute [%s] loaded into type [%s] with identifier [%s] and value [%s]", attribute.getName(), attributedType.getClass(), attributedType.getId(), attribute.getValue()); } } loadManagedAttributes(attributedType); }
private void loadManagedAttributes(AttributedType attributedType) { for (Attribute attribute : attributedType.getAttributes()) { List<Property<Object>> properties = PropertyQueries.createQuery(attributedType.getClass()) .addCriteria(new AnnotatedPropertyCriteria(AttributeProperty.class)) .getResultList(); for (Property property : properties) { AttributeProperty attributeProperty = property.getAnnotatedElement().getAnnotation(AttributeProperty.class); if (property.getName().equals(attribute.getName()) && attributeProperty.managed()) { Object value = null; if (attribute != null) { value = attribute.getValue(); } property.setValue(attributedType, value); if (isTraceEnabled()) { IDENTITY_STORE_LOGGER.tracef("Managed attribute [%s] loaded into type [%s] with identifier [%s] and value [%s]", attribute.getName(), attributedType.getClass(), attributedType.getId(), attribute.getValue()); } } } } }
private void loadManagedAttributes(AttributedType attributedType) { for (Attribute attribute : attributedType.getAttributes()) { List<Property<Object>> properties = PropertyQueries.createQuery(attributedType.getClass()) .addCriteria(new AnnotatedPropertyCriteria(AttributeProperty.class)) .getResultList(); for (Property property : properties) { AttributeProperty attributeProperty = property.getAnnotatedElement().getAnnotation(AttributeProperty.class); if (property.getName().equals(attribute.getName()) && attributeProperty.managed()) { Object value = null; if (attribute != null) { value = attribute.getValue(); } property.setValue(attributedType, value); if (isTraceEnabled()) { IDENTITY_STORE_LOGGER.tracef("Managed attribute [%s] loaded into type [%s] with identifier [%s] and value [%s]", attribute.getName(), attributedType.getClass(), attributedType.getId(), attribute.getValue()); } } } } }
/** * 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(); }
@Override public void setAttribute(org.picketlink.idm.model.Attribute<? extends Serializable> attribute) { Serializable value = attribute.getValue(); getLDAPAttributes().put(attribute.getName(), value); getCustomAttributes().addAttribute(attribute.getName(), value); }
@Override protected boolean validateCredential(IdentityContext context, CredentialStorage credentialStorage, UsernamePasswordCredentials credentials, LDAPIdentityStore ldapIdentityStore) { Account account = getAccount(context, credentials.getUsername()); char[] password = credentials.getPassword().getValue(); String userDN = (String) account.getAttribute(LDAPIdentityStore.ENTRY_DN_ATTRIBUTE_NAME).getValue(); if (CREDENTIAL_LOGGER.isDebugEnabled()) { CREDENTIAL_LOGGER.debugf("Using DN [%s] for authentication of user [%s]", userDN, credentials.getUsername()); } if (ldapIdentityStore.getOperationManager().authenticate(userDN, new String(password))) { return true; } return false; } }
/** * <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> * Sets a multi-valued attribute. * </p> * * @throws Exception */ @Test public void testSetMultiValuedAttribute() 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); assertNotNull(multiValuedAttribute.getValue()); assertEquals(3, multiValuedAttribute.getValue().length); }
/** * <p> * Sets an one-valued attribute. * </p> * * @throws Exception */ @Test public void testSetOneValuedAttribute() throws Exception { T storedIdentityTypeInstance = getIdentityType(true); storedIdentityTypeInstance.setAttribute(new Attribute<String>("one-valued", "1")); updateIdentityType(storedIdentityTypeInstance); T updatedIdentityTypeInstance = getIdentityType(false); Attribute<String> oneValuedAttribute = updatedIdentityTypeInstance.getAttribute("one-valued"); assertNotNull(oneValuedAttribute); assertEquals("1", oneValuedAttribute.getValue()); }
/** * <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()); }