Package com.adito.properties.attributes

Examples of com.adito.properties.attributes.AttributeDefinition


     * (non-Javadoc)
     *
     * @see com.adito.properties.PropertyType#retrieve(com.adito.properties.PropertyKey)
     */
    public String retrievePropertyImpl(AbstractPropertyKey key) throws IllegalArgumentException {
        AttributeDefinition def = (AttributeDefinition)getDefinition(key.getName());
        UserAttributeKey userAttrKey = (UserAttributeKey) key;
        try {
            String val = ProfilesFactory.getInstance().retrieveAttributeValue(userAttrKey);
            if (val != null) {
                if (def.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
                    /*
                     * We can only get confidential attributes after the users
                     * private key has been verified. This may not have happened
                     * when a users attributes are first loaded so we must skip
                     * such attributes.
                     */
                    if (PublicKeyStore.getInstance().hasLoadedKey(userAttrKey.getUser().getPrincipalName())) {
                        try {
                            val = PublicKeyStore.getInstance().decryptText(val, userAttrKey.getUser().getPrincipalName());
                        } catch (Throwable t) {
                            log.warn("Failed to decrypt confidential user attribute, probably corrupt. Returning default value", t);
                            return null;
                        }
                    }
                }
            }

            // Decrypt obfuscated password if of password type
            if (def.getType() == PropertyDefinition.TYPE_PASSWORD && val != null) {
                try {
                    val = ContextHolder.getContext().deobfuscatePassword(val);
                } catch (Throwable t) {
                    log.warn("Password property " + def.getName() + " could not be decoded. It has been result to the default.", t);
                }
            }
           
            //
            return val == null ? def.getDefaultValue() : val;
        } catch (Exception e) {
            log.error("Failed to retrieve property.", e);
        }
        return null;
    }
View Full Code Here


        }
        return null;
    }

    public String storePropertyImpl(AbstractPropertyKey key, String value) throws IllegalArgumentException {
        AttributeDefinition def = (AttributeDefinition)getDefinition(key.getName());
        UserAttributeKey userAttrKey = (UserAttributeKey) key;
       
        /* A null old value would indicate that the key could be not retrieved for
         * some reason. So, we write anyway
         */
        String oldValue = retrieveProperty(key);
       
        /* If the new value is the same as the default value, we remove the persisted item from the database */
       
        if (def.getDefaultValue().equals(value)) {
            value = null;
        }
       
        /* Store the attribute always if this is a confidential attribute, the old value could not be retrieved or the value has changed */
        if (def.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE || oldValue == null || !oldValue.equals(value) ) {

            // Obfuscate the password for storing in the database

            if (def.getType() == PropertyDefinition.TYPE_PASSWORD) {
                try {
                    value = ContextHolder.getContext().obfuscatePassword(value);
                } catch (Throwable t) {
                  if(log.isDebugEnabled())
                    log.warn("Password property " + def.getName() + " could not be encoded.", t);
                }
            }
           
            if (value != null) {
                if (def.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
                    /*
                     * We can only get confidential attributes after the users
                     * private key has been verified. This may not have happened
                     * when a users attributes are first loaded so we must skip
                     * such attributes.
View Full Code Here

      String typeMeta, int category, String categoryLabel,
      String defaultValue, int visibility, int sortOrder,
      String messageResourcesKey, boolean hidden, String label,
      String description, boolean system, boolean replaceable,
      String validationString) {
    AttributeDefinition def = new DefaultAttributeDefinition(type, name, typeMeta, category,
        categoryLabel, defaultValue, visibility, sortOrder,
        messageResourcesKey, hidden, label, description, system,
        replaceable, validationString);
    def.init(this);
    return def;
  }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void createUserAttributesDefinition() throws Exception {
        UserAttributes attribute = new UserAttributes();
        AttributeDefinition attributeDefinition = attribute.createAttributeDefinition(AttributeDefinition.TYPE_UNDEFINED, "AttributName", "typeMeta", -1, "categorylabel", "default value", AttributeDefinition.TYPE_UNDEFINED, 0, "", false, "Label", "Description", false, true, "");
        createAttributeDefinition(attribute, attributeDefinition);
        Assert.assertTrue("Should exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
        deletAttributeDefinitionName(attribute, attributeDefinition.getName());
        Assert.assertFalse("Should not exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void createPolicyAttributesDefinition() throws Exception {
        UserAttributes attribute = new UserAttributes();
        AttributeDefinition attributeDefinition = attribute.createAttributeDefinition(AttributeDefinition.TYPE_UNDEFINED, "AttributName", "typeMeta", -1, "categorylabel", "default value", AttributeDefinition.TYPE_UNDEFINED, 0, "", false, "Label", "Description", false, true, "");
        createAttributeDefinition(attribute, attributeDefinition);
        Assert.assertTrue("Should exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
        deletAttributeDefinitionName(attribute, attributeDefinition.getName());
        Assert.assertFalse("Should not exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
    }
View Full Code Here

    Properties confidentialAttributes = new Properties();
    UserAttributes userAttributes = (UserAttributes) PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME);
    if ("automatic".equals(Property.getProperty(new SystemConfigKey("security.privateKeyMode")))
            && PublicKeyStore.getInstance().hasLoadedKey(user.getPrincipalName())) {
      for (PropertyDefinition def : userAttributes.getDefinitions()) {
        AttributeDefinition attrDef = (AttributeDefinition) def;
        if (attrDef.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
          String val = attrDef.getPropertyClass()
          .retrieveProperty(new UserAttributeKey(user, def.getName()));
          if(val == null) {
            val = def.getDefaultValue();
          }
          confidentialAttributes.setProperty(def.getName(), val);
        }
      }
    }

    try {

      char[] creds = LogonControllerFactory.getInstance()
              .getPasswordFromCredentials((AuthenticationScheme) request.getSession()
                      .getAttribute(Constants.AUTH_SESSION));

      if (creds == null) {
                HttpSession httpSession = getSessionInfo(request).getHttpSession();
                httpSession.setAttribute("newUser", user);
                // as the form will be reset, we need to store the current values to be used later
                httpSession.setAttribute(SetPasswordForm.SAVED_PASSWORD, setPasswordForm.getConfirmPassword());
                httpSession.setAttribute(SetPasswordForm.SAVED_FORCE_PASSWORD_CHANGE, setPasswordForm.getForceChangePasswordAtLogon());
                String forwardTo = Util.urlEncode(CoreUtil.addParameterToPath(request.getServletPath(), "action", "commit"));
                return new ActionForward("/promptForSessionPassword.do?forwardTo=" + forwardTo, false);
      }

      udb.setPassword(user.getPrincipalName(),
        setPasswordForm.getNewPassword(),
        setPasswordForm.getForceChangePasswordAtLogon(),
        LogonControllerFactory.getInstance().getUser(request),
        new String(creds));

      /* Only attempt to re-encrypt user attributes if users key is loaded */
      if ("automatic".equals(Property.getProperty(new SystemConfigKey("security.privateKeyMode")))) {
        if(PublicKeyStore.getInstance().hasLoadedKey(user.getPrincipalName())) {
          PublicKeyStore.getInstance().removeKeys(user.getPrincipalName());
          PublicKeyStore.getInstance().verifyPrivateKey(user.getPrincipalName(), setPasswordForm.getNewPassword().toCharArray());
          for(Iterator i = confidentialAttributes.keySet().iterator(); i.hasNext(); ) {
            String n = (String)i.next();
            AttributeDefinition attrDef = (AttributeDefinition) userAttributes.getDefinition(n);
            if (attrDef.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
              Property.setProperty(new UserAttributeKey(user, n),
                confidentialAttributes.getProperty(n),
                info);
            }
          }
View Full Code Here

                for (PropertyClass propertyClass : PropertyClassManager.getInstance().getPropertyClasses()) {
                    if (propertyClass instanceof AttributesPropertyClass
                                    && !propertyClass.getName().equals(ResourceAttributes.NAME)) {
                        l = propertyClass.getDefinitions();
                        for (PropertyDefinition d : l) {
                            AttributeDefinition def = (AttributeDefinition) d;
                            if (def.isReplaceable()) {
                                addVariable(def.getPropertyClass().getName() + ":" + def.getName(), def.getDescription(), buf,
                                                pageContext, bundle, locale, inputId);
                            }
                        }
                    }
                }
View Full Code Here

        User user = (User) request.getSession().getAttribute(Constants.EDITING_ITEM);
        PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
        PropertyClass propertyClass = PropertyClassManager.getInstance().getPropertyClass(UserAttributes.NAME);
        /* We must delete all confidential attribute values */
        for (PropertyDefinition propertyDefinition : propertyClass.getDefinitions()) {
            AttributeDefinition attributeDefinition = (AttributeDefinition) propertyDefinition;
            if (attributeDefinition.getVisibility() == AttributeDefinition.USER_CONFIDENTIAL_ATTRIBUTE) {
                Property.setProperty(new UserAttributeKey(user, attributeDefinition.getName()), (String) null, getSessionInfo(request));
            }
        }
        PublicKeyStore.getInstance().removeKeys(user.getPrincipalName());
        return list(mapping, form, request, response);
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void updateUserAttributeDefinitionName() throws Exception {
        UserAttributes attribute = new UserAttributes();
        AttributeDefinition attributeDefinition = attribute.createAttributeDefinition(AttributeDefinition.TYPE_UNDEFINED, "NewAttributName", "typeMeta", -1, "categorylabel", "default value", AttributeDefinition.TYPE_UNDEFINED, 0, "", false, "Label", "Description", false, true, "");
        createAttributeDefinition(attribute, attributeDefinition);
        Assert.assertTrue("Should exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
        updateAttributeDefinition(attribute, attributeDefinition);
        deletAttributeDefinitionName(attribute, attributeDefinition.getName());
        Assert.assertFalse("Should not exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void updatePolicyAttributeDefinitionName() throws Exception {
        PolicyAttributes attribute = new PolicyAttributes();
        AttributeDefinition attributeDefinition = attribute.createAttributeDefinition(AttributeDefinition.TYPE_UNDEFINED, "NewAttributName", "typeMeta", -1, "categorylabel", "default value", AttributeDefinition.TYPE_UNDEFINED, 0, "", false, "Label", "Description", false, true, "");
        createAttributeDefinition(attribute, attributeDefinition);
        Assert.assertTrue("Should exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
        updateAttributeDefinition(attribute, attributeDefinition);
        deletAttributeDefinitionName(attribute, attributeDefinition.getName());
        Assert.assertFalse("Should not exist.", attribute.isDefinitionExists(attributeDefinition.getName()));
    }
View Full Code Here

TOP

Related Classes of com.adito.properties.attributes.AttributeDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.