public virtual void PrepareFieldForPersist(Net.Vpc.Upa.Field field, object @value, Net.Vpc.Upa.Record userRecord, Net.Vpc.Upa.Record persistentRecord, Net.Vpc.Upa.Persistence.EntityExecutionContext executionContext, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> insertNonNullable, System.Collections.Generic.ISet <Net.Vpc.Upa.Field> insertWithDefaultValue) /* throws Net.Vpc.Upa.Exceptions.UPAException */
        {
            object userValue      = null;
            bool   userValueFound = false;

            if (!(@value is Net.Vpc.Upa.Expressions.Expression))
            {
                userValueFound = true;
                userValue      = @value;
            }
            else if (@value is Net.Vpc.Upa.Expressions.Param)
            {
                object o = ((Net.Vpc.Upa.Expressions.Param)@value).GetValue();
                //            if (o instanceof String) {
                userValue      = o;
                userValueFound = true;
            }
            else if (@value is Net.Vpc.Upa.Expressions.Literal)
            {
                object o = ((Net.Vpc.Upa.Expressions.Literal)@value).GetValue();
                //            if (o instanceof String) {
                userValue      = o;
                userValueFound = true;
            }
            //            }
            if (userValueFound)
            {
                Net.Vpc.Upa.Types.DataTypeTransform typeTransform      = Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(field);
                Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform t = Net.Vpc.Upa.Impl.Util.UPAUtils.FindPasswordTransform(typeTransform);
                object v = ConvertCypherValue(t.GetCipherValue(), field.GetDataType());
                if (Net.Vpc.Upa.Impl.Util.UPAUtils.Equals(userValue, v))
                {
                    return;
                }
                //ignore insert
                userRecord.SetObject(field.GetName(), v);
            }
            else
            {
                log.TraceEvent(System.Diagnostics.TraceEventType.Error, 100, Net.Vpc.Upa.Impl.FwkConvertUtils.LogMessageExceptionFormatter("Inserting non user value to password, hashing will be ignored", null));
            }
            Net.Vpc.Upa.Expressions.Expression valueExpression = (@value is Net.Vpc.Upa.Expressions.Expression) ? ((Net.Vpc.Upa.Expressions.Expression)((Net.Vpc.Upa.Expressions.Expression)@value)) : new Net.Vpc.Upa.Expressions.Param(field.GetName(), @value);
            persistentRecord.SetObject(field.GetName(), valueExpression);
        }
Beispiel #2
0
 public static Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform FindPasswordTransform(Net.Vpc.Upa.Types.DataTypeTransform t)
 {
     if (t is Net.Vpc.Upa.Impl.Transform.IdentityDataTypeTransform)
     {
         return(null);
     }
     if (t is Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform)
     {
         return((Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform)t);
     }
     if (t is Net.Vpc.Upa.Impl.Transform.DataTypeTransformList)
     {
         foreach (Net.Vpc.Upa.Types.DataTypeTransform x in ((Net.Vpc.Upa.Impl.Transform.DataTypeTransformList)t))
         {
             Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform v = FindPasswordTransform(x);
             if (v != null)
             {
                 return(v);
             }
         }
     }
     return(null);
 }
Beispiel #3
0
        public virtual Net.Vpc.Upa.Types.DataTypeTransform CreatePasswordTransform(Net.Vpc.Upa.PersistenceUnit pu, Net.Vpc.Upa.Types.DataType source, Net.Vpc.Upa.PasswordTransformConfig p)
        {
            if (p == null)
            {
                p = new Net.Vpc.Upa.PasswordTransformConfig();
            }
            object s = p.GetCipherStrategy();

            if (s == null)
            {
                s = Net.Vpc.Upa.PasswordStrategyType.DEFAULT;
            }
            if (s is Net.Vpc.Upa.PasswordStrategyType)
            {
                switch (((Net.Vpc.Upa.PasswordStrategyType)s))
                {
                case Net.Vpc.Upa.PasswordStrategyType.SHA1:
                {
                    s = Net.Vpc.Upa.Impl.Transform.DefaultPasswordStrategy.SHA1;
                    break;
                }

                case Net.Vpc.Upa.PasswordStrategyType.SHA256:
                {
                    s = Net.Vpc.Upa.Impl.Transform.DefaultPasswordStrategy.SHA256;
                    break;
                }

                case Net.Vpc.Upa.PasswordStrategyType.MD5:
                {
                    s = Net.Vpc.Upa.Impl.Transform.DefaultPasswordStrategy.MD5;
                    break;
                }

                case Net.Vpc.Upa.PasswordStrategyType.DEFAULT:
                {
                    s = Net.Vpc.Upa.Impl.Transform.DefaultPasswordStrategy.MD5;
                    break;
                }

                default:
                {
                    throw new System.ArgumentException("Unsupported CipherStrategy " + s);
                }
                }
            }
            else if (s is string)
            {
                if (!Net.Vpc.Upa.Impl.Util.StringUtils.IsNullOrEmpty((string)s))
                {
                    s = (Net.Vpc.Upa.PasswordStrategy)pu.GetFactory().CreateObject <T>((string)s);
                }
                else
                {
                    s = Net.Vpc.Upa.Impl.Transform.DefaultPasswordStrategy.MD5;
                }
            }
            else if (s is System.Type)
            {
                s = (Net.Vpc.Upa.PasswordStrategy)pu.GetFactory().CreateObject <object>((System.Type)s);
            }
            else if (s is Net.Vpc.Upa.PasswordStrategy)
            {
                s = (Net.Vpc.Upa.PasswordStrategy)s;
            }
            else
            {
                throw new System.ArgumentException("Unsupported CipherStrategy " + s);
            }
            p.SetCipherStrategy((Net.Vpc.Upa.PasswordStrategy)s);
            Net.Vpc.Upa.Types.DataTypeTransform t = null;
            object cipherValue = p.GetCipherValue();

            if (!(source is Net.Vpc.Upa.Types.StringType))
            {
                t = CreateStringEncoderTransform(pu, source, null);
                Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform t2 = new Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform((Net.Vpc.Upa.PasswordStrategy)p.GetCipherStrategy(), cipherValue, t.GetTargetType());
                return(t.Chain(t2));
            }
            return(new Net.Vpc.Upa.Impl.Transform.PasswordDataTypeTransform((Net.Vpc.Upa.PasswordStrategy)p.GetCipherStrategy(), cipherValue, source));
        }