using System.Diagnostics;\r
using SharpCifs.Smb;\r
using Commons;\r
+using System.Runtime.InteropServices;\r
+using Microsoft.Win32.SafeHandles;\r
+using System.Runtime.ConstrainedExecution;\r
+using System.Security;\r
+using System.Security.Permissions;\r
+using System.Security.Principal;\r
\r
namespace IntegrationTests {\r
+ public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid {\r
+ private SafeTokenHandle()\r
+ : base(true) {\r
+ }\r
+\r
+ [DllImport("kernel32.dll")]\r
+ [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]\r
+ [SuppressUnmanagedCodeSecurity]\r
+ [return: MarshalAs(UnmanagedType.Bool)]\r
+ private static extern bool CloseHandle(IntPtr handle);\r
+\r
+ protected override bool ReleaseHandle() {\r
+ return CloseHandle(handle);\r
+ }\r
+ }\r
+\r
+\r
+\r
[TestClass]\r
public class MaestroTests {\r
\r
result = result.Substring(0, result.LastIndexOf("."));\r
Debug.WriteLine(result);\r
}\r
+\r
+ [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]\r
+ public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,\r
+ int dwLogonType, int dwLogonProvider, out SafeTokenHandle phToken);\r
+\r
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto)]\r
+ public extern static bool CloseHandle(IntPtr handle);\r
+\r
+\r
+\r
+ [PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]\r
+ [TestMethod]\r
+ public void TestImpersonate() {\r
+ SafeTokenHandle safeTokenHandle;\r
+ try {\r
+ string userName, domainName, password;\r
+ // Get the user token for the specified user, domain, and password using the\r
+ // unmanaged LogonUser method.\r
+ // The local machine name can be used for the domain name to impersonate a user on this machine.\r
+ domainName = ".";\r
+ userName = "mediacube";\r
+ password = "Broadca5T";\r
+ const int LOGON32_PROVIDER_DEFAULT = 0;\r
+ //This parameter causes LogonUser to create a primary token.\r
+ const int LOGON32_LOGON_INTERACTIVE = 2;\r
+\r
+ // Call LogonUser to obtain a handle to an access token.\r
+ bool returnValue = LogonUser(userName, domainName, password,\r
+ LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,\r
+ out safeTokenHandle);\r
+\r
+ Console.WriteLine("LogonUser called.");\r
+\r
+ if (false == returnValue) {\r
+ int ret = Marshal.GetLastWin32Error();\r
+ Console.WriteLine("LogonUser failed with error code : {0}", ret);\r
+ throw new System.ComponentModel.Win32Exception(ret);\r
+ }\r
+ using (safeTokenHandle) {\r
+ Console.WriteLine("Did LogonUser Succeed? " + (returnValue ? "Yes" : "No"));\r
+ Console.WriteLine("Value of Windows NT token: " + safeTokenHandle);\r
+\r
+ // Check the identity.\r
+ Console.WriteLine("Before impersonation: "\r
+ + WindowsIdentity.GetCurrent().Name);\r
+ // Use the token handle returned by LogonUser.\r
+ using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle())) {\r
+ using (WindowsImpersonationContext impersonatedUser = newId.Impersonate()) {\r
+\r
+ // Check the identity.\r
+ Console.WriteLine("After impersonation: "\r
+ + WindowsIdentity.GetCurrent().Name);\r
+ }\r
+ }\r
+ // Releasing the context object stops the impersonation\r
+ // Check the identity.\r
+ Console.WriteLine("After closing the context: " + WindowsIdentity.GetCurrent().Name);\r
+ }\r
+ }\r
+ catch (Exception ex) {\r
+ Console.WriteLine("Exception occurred. " + ex.Message);\r
+ }\r
+\r
+ }\r
+\r
+\r
}\r
}
\ No newline at end of file
static private final byte[] GET_SPECIAL_ID_ATTRIBUTES_REQ = { (byte) 0xC8, (byte) 0x84 };\r
static private final char[] hexArray = "0123456789ABCDEF".toCharArray();\r
\r
+ public static String bytesToBin(byte[] bytes) {\r
+ StringBuilder result = new StringBuilder();\r
+ for (byte b : bytes) {\r
+ String str = byteToStr(b);\r
+ result.append(str);\r
+ if (result.length() % 4 == 0)\r
+ result.append(" ");\r
+ }\r
+ return result.toString();\r
+ }\r
+\r
public static String bytesToHex(byte[] bytes) {\r
char[] hexChars = new char[bytes.length * 2];\r
for (int j = 0; j < bytes.length; j++) {\r
return new String(hexChars);\r
}\r
\r
+ public static String byteToStr(byte b) {\r
+ String binaryString = Integer.toBinaryString(b & 0xFF);\r
+ String str = String.format("%8s", binaryString).replace(' ', '0');\r
+ return str;\r
+ }\r
+\r
+ public static String longToStr(long b) {\r
+ String binaryString = Long.toBinaryString(b & 0xFFFF);\r
+ String str = String.format("%16s", binaryString).replace(' ', '0');\r
+ return str;\r
+ }\r
+\r
private EventListenerList progressListenerList;\r
private ProgressEvent progressEvent = new ProgressEvent(this, 0);\r
private INexioChangeListener nexioChangeListener;\r
}\r
\r
try {\r
- if ("2931346-3".equals(jsClip.getString(LONGNAMEID)))\r
- jsClip.put(KILLDATE, clip.getKillDate());\r
+ jsClip.put(KILLDATE, clip.getKillDate());\r
} catch (Exception e) {\r
// System.out.println(e);\r
}\r
import java.io.IOException;
import java.util.Calendar;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
import user.commons.nexio.server.protocol.Id;
import user.commons.nexio.server.protocol.NexioServerProtocol;
import user.commons.nexio.server.protocol.ProtocolException;
import user.commons.nexio.server.protocol.Xid;
class ClipImpl implements Clip {
-
+ private static final Logger logger = LogManager.getLogger();
private static final String PROTOCOL = "protocol";
private static final String ID = "id";
private static final String XID = "xid";
metadata = protocol.executeGetIDMetadata(id);
checkClipExists(metadata);
}
- byte[] filetime = { metadata[42], metadata[43] };
-
Calendar result = Calendar.getInstance();
-
- return null;
+ byte[] dtArray = { metadata[43], metadata[42] };
+
+ long data = dtArray[0] & 0xFF;
+ data <<= 8;
+ data |= (dtArray[1] & 0xFF);
+
+ //logger.info("--- {} .. {}", NexioClipEventDispatcher.bytesToBin(dtArray), NexioClipEventDispatcher.longToStr(data));
+
+ int day = (int) (data >> 11);
+ int month = (int) ((data & 0x7FF) >> 7);
+ int year = 1900 + (int) (data & 0x7F);
+ //System.out.println(String.format("day %s month %s year %s", day, month, year));
+ result.set(Calendar.YEAR, year);
+ result.set(Calendar.MONTH, month - 1);
+ result.set(Calendar.DAY_OF_MONTH, day);
+ result.set(Calendar.HOUR_OF_DAY, 0);
+ result.set(Calendar.MINUTE, 0);
+ result.set(Calendar.SECOND, 0);
+ result.set(Calendar.MILLISECOND, 0);
+ return result;
}
@Override
import user.commons.nexio.api.Controller;\r
\r
public class NexioDataMinerTest {\r
+ public static String bytesToBin(byte[] bytes) {\r
+ StringBuilder result = new StringBuilder();\r
+ for (byte b : bytes) {\r
+ String str = byteToStr(b);\r
+ result.append(str);\r
+ if (result.length() % 4 == 0)\r
+ result.append(" ");\r
+ }\r
+ return result.toString();\r
+ }\r
+\r
+ public static long bytesToLong(byte[] b) {\r
+ long result = 0;\r
+ for (int i = 0; i < 2; i++) {\r
+ result <<= 8;\r
+ result |= (b[i] & 0xFF);\r
+ }\r
+ return result;\r
+ }\r
+\r
+ public static String byteToStr(byte b) {\r
+ String binaryString = Integer.toBinaryString(b & 0xFF);\r
+ String str = String.format("%8s", binaryString).replace(' ', '0');\r
+ return str;\r
+ }\r
+\r
@BeforeClass\r
public static void initialize() throws Exception {\r
//Naplozas\r
System.getProperties().putAll(properties);\r
}\r
\r
+ public static String longToStr(long b) {\r
+ String binaryString = Long.toBinaryString(b & 0xFFFF);\r
+ String str = String.format("%16s", binaryString).replace(' ', '0');\r
+ return str;\r
+ }\r
+\r
private NexioDataMiner sut;\r
\r
@Test\r
c.connect();\r
c.getMediabase().getProtocol().setDescription("%0000205", "VALAMI");\r
}\r
+\r
+ @Test\r
+ public void testKillDateConverter() throws Exception {\r
+ byte[] data = { 8, -58 };\r
+ long num = bytesToLong(data);\r
+ System.out.println(String.format("%s .. %s", bytesToBin(data), longToStr(num)));\r
+ int day = (int) (num >> 11);\r
+ int month = (int) ((num & 0x7FF) >> 7);\r
+ int year = (int) (num & 0x7F);\r
+ System.out.println(String.format("day %s month %s year %s", day, month, year));\r
+\r
+ }\r
+\r
}\r