Beispiel #1
0
        /// <summary>
        /// Gets all of the external service names / identifiers from the specified access control.
        /// </summary>
        /// <param name="accessControl">The access control to inspect.</param>
        /// <returns>The collection of external names.</returns>
        internal static IEnumerable <string> GetExternalNames(this DeviceAccessControl accessControl)
        {
            Type type = typeof(DeviceAccessControl);

            var values = Enum.GetValues(type);

            foreach (int value in values)
            {
                if (((int)accessControl & value) == value)
                {
                    string valueName = Enum.GetName(type, value);

                    // Get the metadata
                    FieldInfo field = accessControl.GetType().GetField(valueName);
                    if (field != null)
                    {
                        var attributes = (RicohDeviceAccessControlMetaDataAttribute[])field.GetCustomAttributes(typeof(RicohDeviceAccessControlMetaDataAttribute), true);
                        foreach (RicohDeviceAccessControlMetaDataAttribute attribute in attributes)
                        {
                            foreach (string name in attribute.Names)
                            {
                                yield return(name);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get's the access control capabilities / restrictions for the specified device.
        /// </summary>
        /// <param name="deviceId">The internal id of the device.</param>
        public DeviceAccessControl GetDeviceAccessControlCapabilities(uint deviceId = 0)
        {
            // Make sure we haven't already processed the restrictions.
            if (_accessControl != null)
            {
                return(_accessControl.GetValueOrDefault(DeviceAccessControl.None));
            }

            return(Connect(() => {
                _accessControl = DeviceAccessControl.None;

                string[] objectIds = Client.getObjects(SessionId, deviceId, USAGE_CONTROL_DEVICE);
                if ((objectIds != null) && (objectIds.Length > 0))
                {
                    Trace.TraceInformation("Retrieved the following objectIds for {0}", USAGE_CONTROL_DEVICE);

                    // For each of the object ids (corresponding to copy, fax, printer, scanner, etc.),
                    // get the capabilities for each.
                    objectIds.AsParallel().ForAll((objectId) => {
                        objectCapability capability = GetObjectCapability(deviceId, objectId);
                        if (capability != null)
                        {
                            DeviceAccessControl deviceAccessControl = capability.ToDeviceAccessControl();
                            Trace.TraceInformation("Device supports {0} restrictions (ACLs).", deviceAccessControl);

                            _accessControl |= deviceAccessControl;
                        }
                    });
                }
                return (_accessControl.GetValueOrDefault(DeviceAccessControl.None));
            }));
        }
Beispiel #3
0
 /// <summary>
 /// Checks to see if the field is one of the specified names.
 /// </summary>
 /// <param name="field">The field to check.</param>
 /// <param name="accessControl">The access control type to check for.</param>
 /// <returns>True if the field is one of the specified value, false if otherwise.</returns>
 public static bool Is(this field field, DeviceAccessControl accessControl)
 {
     return(Is(field, accessControl.GetExternalNames()));
 }
Beispiel #4
0
 /// <summary>
 /// Indidates if the <see cref="DeviceAccessControl"/> has no access control support.
 /// </summary>
 /// <param name="accessControl">The access control to inspect.</param>
 /// <returns>True if supported; false if otherwise.</returns>
 public static bool HasNoAccessControl(this DeviceAccessControl accessControl)
 {
     return(accessControl == DeviceAccessControl.None);
 }
Beispiel #5
0
 /// <summary>
 /// Indidates if the <see cref="DeviceAccessControl"/> has document server access control support.
 /// </summary>
 /// <param name="accessControl">The access control to inspect.</param>
 /// <returns>True if supported; false if otherwise.</returns>
 public static bool HasDocumentServerAccessControl(this DeviceAccessControl accessControl)
 {
     return(accessControl.HasFlag(DeviceAccessControl.DocumentServer));
 }
Beispiel #6
0
 /// <summary>
 /// Indidates if the <see cref="DeviceAccessControl"/> has scanner access control support.
 /// </summary>
 /// <param name="accessControl">The access control to inspect.</param>
 /// <returns>True if supported; false if otherwise.</returns>
 public static bool HasScannerAccessControl(this DeviceAccessControl accessControl)
 {
     return(accessControl.HasFlag(DeviceAccessControl.Scanner));
 }
Beispiel #7
0
 /// <summary>
 /// Indidates if the <see cref="DeviceAccessControl"/> has printer access control support.
 /// </summary>
 /// <param name="accessControl">The access control to inspect.</param>
 /// <returns>True if supported; false if otherwise.</returns>
 public static bool HasPrinterAccessControl(this DeviceAccessControl accessControl)
 {
     return(accessControl.HasFlag(DeviceAccessControl.Printer));
 }
Beispiel #8
0
 /// <summary>
 /// Indidates if the <see cref="DeviceAccessControl"/> has fax access control support.
 /// </summary>
 /// <param name="accessControl">The access control to inspect.</param>
 /// <returns>True if supported; false if otherwise.</returns>
 public static bool HasFaxAccessControl(this DeviceAccessControl accessControl)
 {
     return(accessControl.HasFlag(DeviceAccessControl.Fax));
 }
Beispiel #9
0
 /// <summary>
 /// Allows access to the specified device functions for the device.
 /// </summary>
 /// <param name="currentAccessControl">The existing <see cref="UserAccessControl"/> settings.</param>
 /// <param name="accessControl">The device controls to modify.</param>
 /// <param name="deviceId">The internal id of the device.</param>
 /// <returns>True if the call was successful, false if otherwise.</returns>
 public bool AllowAccess(UserAccessControl currentAccessControl, DeviceAccessControl accessControl, uint deviceId = 0)
 {
     return(SetAccessControl(deviceId, currentAccessControl, accessControl, true));
 }
Beispiel #10
0
 /// <summary>
 /// Restricts access to the specified device functions for the device.
 /// </summary>
 /// <param name="currentAccessControl">The existing <see cref="UserAccessControl"/> settings.</param>
 /// <param name="accessControl">The device controls to modify.</param>
 /// <param name="deviceId">The internal id of the device.</param>
 /// <returns>True if the call was successful, false if otherwise.</returns>
 public bool RestrictAccess(UserAccessControl currentAccessControl, DeviceAccessControl accessControl, uint deviceId = 0)
 {
     return(SetAccessControl(deviceId, currentAccessControl, accessControl, false));
 }
Beispiel #11
0
        /// <summary>
        /// Restricts access to the fax functionality for the device.
        /// </summary>
        /// <param name="deviceId">The internal id of the device. If null, then ignore or don't modify attribute.</param>
        /// <param name="currentAccessControl">The existing <see cref="UserAccessControl"/> settings.</param>
        /// <param name="accessControl">The device controls to modify.</param>
        /// <param name="allow">Enable or disable access. If null, then ignore or don't modify attribute.</param>
        /// <returns>True if the call was successful, false if otherwise.</returns>
        protected bool SetAccessControl(uint deviceId, UserAccessControl currentAccessControl, DeviceAccessControl accessControl, bool allow = false)
        {
            return(Connect(() => {
                try {
                    IEnumerable <field> fields = currentAccessControl.Fields.GetUpdatableFields(f => f.Type == typeof(bool));
                    if ((fields == null) || (!fields.Any()))
                    {
                        return (false);
                    }

                    IEnumerable <string> names = accessControl.GetExternalNames(); // Get all of the external names that match the requested accessControl type.

                    // Update the requested changes.
                    fields.AsParallel().ForAll(f => {
                        if (names.Any(n => String.Equals(n, f.name, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            // The external service views the ON / OFF from a RESTRICTION point of view instead of ALLOW
                            bool toogle = !allow;// f.IsFax() ? ! allow :allow;

                            Trace.TraceWarning("Changing accessControl '{1}' from '{2}' to '{3}' for {0}.", currentAccessControl.Id, f.name, f.value, toogle.ToOnOff());
                            f.value = toogle.ToOnOff();
                        }
                    });

                    return (Update(deviceId,
                                   Convert.ToString(currentAccessControl.Index), currentAccessControl.Id,
                                   fields.ToArray(), USAGE_CONTROL_USER, false));
                } catch (Exception e) {
                    Trace.TraceError(e.Message);
                    Trace.TraceError(e.StackTrace);

                    throw (new RicohOperationFailedException(this, "Restrict", e));
                }
            }));
        }