Windows Authentication With WMI - windows

I want to use Windows current credential when using WMI to query data on a remote machine, but in many examples I found that I have to use Connection object which needs you to provide a username, password and authority for validating username and password as shown below:
Dim connection As New ConnectionOptions
connection.Username = userNameBox.Text
connection.Password = passwordBox.Text
connection.Authority = "ntlmdomain:MyDomain"
Dim scope As New ManagementScope( _
"\\RemoteMachine\root\CIMV2", connection)
scope.Connect()
I want to bypass these inputs and use current Windows logon credentials instead, is there any way for this?

Here' the C# example with connnection options using Windows credentials.
ConnectionOptions connectionOptions = new ConnectionOptions
{
Authentication = AuthenticationLevel.PacketPrivacy,
Impersonation = ImpersonationLevel.Impersonate
};

Related

Firefox Extension Set Proxy Auth

I am trying to develop and Firefox Extension, which sets a proxy and does some other things after doing that. So i know how to set proxy http and port.
var prefManager = Cc["#mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefManager.setIntPref("network.proxy.type", 1);
prefManager.setCharPref("network.proxy.http",aProxy[0]);
prefManager.setIntPref("network.proxy.http_port",aProxy[1]);
But i was not able to find the properties for username and password. Seems it will need to be set differently.
Someone can help?
Have you tried saving the passwords using nsILoginManager? In Firefox, password for proxies are handled like any other password.
let LoginInfo = new Components.Constructor("#mozilla.org/login-manager/loginInfo;1", Components.interfaces.nsILoginInfo, "init");
let loginInfo = new LoginInfo(
hostname,
null,
realm,
user,
password,
'',
''
);
let loginManager = Components.classes["#mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager);
loginManager.addLogin(loginInfo);
Proxies don't have a scheme, so I've seen code in Firefox do something like this (code from https://hg.mozilla.org/mozilla-central/file/69d61e42d5df/toolkit/components/passwordmgr/nsLoginManagerPrompter.js#l1400):
// Proxies don't have a scheme, but we'll use "moz-proxy://"
// so that it's more obvious what the login is for.
var idnService = Cc["#mozilla.org/network/idn-service;1"].
getService(Ci.nsIIDNService);
hostname = "moz-proxy://" +
idnService.convertUTF8toACE(info.host) +
":" + info.port;
realm = aAuthInfo.realm;
if (!realm)
realm = hostname;
I think it's just for readability (when the user opens the password manager), but it shouldn't be required.
P.S.: There's also a preference, signon.autologin.proxy, that makes Firefox not prompt for authentication if a password is saved.

Google Apps Jdbc - Connection Issue

I am trying to connect to a MySQL server using Jdbc for Google Apps and getting an error as follows:
Failed to establish a database connection. Check connection string,
username and password. (line 10, file "dbadmin")
The following is a snipet of the code I am using:
var address = 'w.x.y.z';
var user = 'user';
var userPwd = 'password';
var db = 'dbname';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
var conn = Jdbc.getConnection(dbUrl, user, userPwd);
I have successfully connected to the Database from my own computer using both the IP and Hostname. I have confirmed the server should be accepted connections from ALL IPs for that account, and confirmed the ruleset is working by removing the whitelisting and adding it back again.
I am basically out of troubleshooting ideas of what is going on. What am I doing wrong, or what is wrong with Google?
A typical way to establish JDBC connection is as follows:
String url = "jdbc:mysql://hostname:3306/mydb";
String username = "username";
String password = "password"
Connection conn = DriverManager.getConnection(url, username, password);
You can refer to this for more detailed information.

ServiceStack Accessing Session Directly

I'm having trouble getting direct manipulation of sessions working properly.
Using some code from the source and a tip from Demis, I've put together something in our unit test client to auth the user and then recover the session.
The AuthResponse I'm getting from the service has a SessionId of 533, which results in a constructed urn of "urn:iauthsession:533", whereas the urn in the Redis cache is "urn:iauthsession:sbQBLwb1WpRj8DqQ7EdL", so obviously, the thing being passed to the urn builder in the running code is not simply the session id (or the overload being used is not what I think it is).
Here's the code we're using in our test base class to try to recover the session from the auth call:
var client = new JsonServiceClient(ServiceTestAppHost.BaseUrl)
{
UserName = userName,
Password = password,
AlwaysSendBasicAuthHeader = true
};
var response = client.Post<AuthResponse>("/auth/basic", new Auth() { UserName = userName, Password = password, RememberMe = true });
var sessionKey = IdUtils.CreateUrn<IAuthSession>(response.SessionId);
var session = _appHost.TryResolve<ICacheClient>().Get<SsoUserSession>(sessionKey);
Any idea why the constructed urn is not matching?
This should now be fixed with this commit which is available in v4.0.22 that's now available on MyGet.

(401) Unauthorized Error When Calling Web API from a Console Application

When I call my WEB API from my Console Application, I encounter:
The remote server returned an error: (401) Unauthorized.
This application runs in Interanet (Windows Authentication)
Uri uri = new Uri("http://myServer/api/main/foo");
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
using (Stream data = client.OpenRead(uri))
{
using (StreamReader sr = new StreamReader(data))
{
string result = sr.ReadToEnd();
Console.WriteLine(result);
}
}
Updated
If I replace
client.Credentials = CredentialCache.DefaultCredentials;
with this line
client.Credentials = new NetworkCredential( username, password);
it works fine but I need the current credential to be set automatically.
Any idea?
Thanks in advance ;)
You use the default windows credentials here
client.Credentials = CredentialCache.DefaultCredentials;
Specify the credential that you want to authenticate using the following code:
var credential = new NetworkCredential(, , );
serverReport.ReportServerCredentials.NetworkCredentials = credential;
following line is the cause of this behaviour :
client.Credentials = CredentialCache.DefaultCredentials;
Actually this line assigns the credentials of the logged in user or the user being impersonated ( which is only possible in web applications ) , so what I believe is that you have to provide credentials explicitly (http://msdn.microsoft.com/en-us/library/system.net.credentialcache(v=vs.110).aspx) , thanks.

Get User Profile Picture Without Credentials, Possible?

Working on an email client.
Does anyone know if it is possible to get the profile pic of a user from the email and server URL without their password?
I'm working with Exchange 2013. I tried the HTTP POST option provided. It works like a charm but requires a log in.
Have a look at Exchange Impersonation.
You can have a specific user account impersonate another user account and access their details without the need for their username and password.
string impName = #"impy";
string impPassword = #"password";
string impDomain = #"domain";
string impEmail = #"impy#domain.com";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new NetworkCredential(impName, impPassword, impDomain);
service.AutodiscoverUrl(impEmail);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, #"user#domain.com");
More references:
http://msdn.microsoft.com/en-us/library/dd633680(v=exchg.80).aspx
you can use like this..
var userpicUrl = "/_layouts/15/userphoto.aspx?accountname=" + user.UserName + "&size=M&url=" + user.ProfilePictureURl;

Resources