I want to set the user account for Windows Service even before installing.
I am doing it by adding code in project installer.
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
this.serviceProcessInstaller1.Password = ConfigurationSettings.AppSettings["password"];
this.serviceProcessInstaller1.Username = ConfigurationSettings.AppSettings["username"];
Still its prompting for Username and password. Looks like the configuration file is not getting ready by the time the installation is done.
How I can i pull the username and password from configuration file instead of hardcoding it?
Well, I'm at a loss to say why the AppSettings values are not readable in the traditional manner while the installer is running. I tried it myself and ran into the same problem you are having. However, I was able to get around the problem by loading the configuration file as a regular XML file and reading it that way. Try this:
XmlDocument doc = new XmlDocument();
doc.Load(Assembly.GetExecutingAssembly().Location + ".config");
XmlElement appSettings = (XmlElement)doc.DocumentElement.GetElementsByTagName("appSettings")[0];
string username = null;
string password = null;
foreach (XmlElement setting in appSettings.GetElementsByTagName("add"))
{
string key = setting.GetAttribute("key");
if (key == "username") username = setting.GetAttribute("value");
if (key == "password") password = setting.GetAttribute("value");
}
serviceProcessInstaller1.Account = ServiceAccount.User;
serviceProcessInstaller1.Username = username;
serviceProcessInstaller1.Password = password;
Related
i am trying to validate the credentials of a user against a active directory with a principalcontext but always get an error.
I try to connect via ssl, because it is sensitive data, but it always give me the error in the headline.
try
{
PrincipalContext pc = new PrincipalContext(ContextType.Domain, "myAwesomeDomain.com", null, ContextOptions.SecureSocketLayer, adUser, adPassword);
using (pc)
{
retVal = pc.ValidateCredentials(userID, password, ContextOptions.SecureSocketLayer);
}
}
I also tried to set DC="myAwesomeDomain,DC=COM" for the container instead of null.
The Credentials to log into the AD are correct, they are working fine with DirectoryEntry.
I have no clue how to go on.
Any idea?
Mh, it is some time since now, i found a solution back then:
try
{
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "myAwesomeDomain.com", null, ContextOptions.SecureSocketLayer, adUser, adPassword);
{
retVal = pc.ValidateCredentials(userID, password, ContextOptions.SecureSocketLayer);
}
}
it really worked this way, i can not explain why
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.
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;
I have a grails application that reads from a property file. I created an administration page, that allows the user to view the settings in this file. I want to allow the user to update the various properties and save them back to the property file using Grails.
My problem is I cant seem to figure out how to save the changes back to the property file.
Here is my code that reads from the file and makes changes to the properties:
def env = params.getAt("environment");
if (env != null){
//Read from Property file based on user selection
def props = new Properties()
def cl = Thread.currentThread().contextClassLoader
def filepath = env+'.properties'
props.load servletContext.getResourceAsStream("/WEB-INF/"+ filepath)
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
def input = params.getAt(key)
if (input != null){
props.setProperty(key,input)
}
}
//props.store(propFile.newWriter(), null)
}
Any Ideas on how to save/overwrite the example.properties file in /WEB-INF/example.properties?
I think that you might be looking for the getRealPath method in ServletContext
http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
Simple example that shows you how to use it
http://82.157.70.109/mirrorbooks/javaservletjspcookbook/0596005725_jsvltjspckbk-chp-14-sect-7.html
I would like to use .Net's SqlMembershipProvider and SqlRoleProvider for user management in my application. My issue is that when the application starts, it does not know any db connection information. For security purposes, it needs to get this information from a WCF service that is running on the datbase server. Therefore I need to build my membership/role providers after-the-fact.
I think I've been able to work out creating and adding the membership provider:
// register membership provider
var membership = new SqlMembershipProvider();
var providerValues = new NameValueCollection();
providerValues.Add("name", "sqlMembershipProvider");
providerValues.Add("applicationName", "/");
providerValues.Add("connectionStringName", "connectionStrDynamAddedToConfig");
providerValues.Add("maxInvalidPasswordAttempts", "10");
membership.Initialize("sqlMembershipProvider", providerValues);
I have, so far, been unable to work out something similar to create the RoleProvider. I can create the provider, but cannot add it to the Roles Manager. Do I need to create a custom provider that can take a connectionString after it is already initialized?
I ran across this page, which recommends "downloading the ProviderToolkitSamples and modifying the SQLConnectionHelper Class. Specifically, the GetConnectionString function which looks something like this"
internal static string GetConnectionString(string specifiedConnectionString, bool lookupConnectionString, bool appLevel)
{
if (specifiedConnectionString == null || specifiedConnectionString.Length < 1)
return null;
string connectionString = null;
/////////////////////////////////////////
// Step 1: Check <connectionStrings> config section for this connection string
if (lookupConnectionString)
{
ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[specifiedConnectionString];
if (connObj != null)
connectionString = connObj.ConnectionString;
if (connectionString == null)
return null;
}
else
{
connectionString = specifiedConnectionString;
}
return connectionString;
}
}
Text lifted from williablog.net, since as that page says, "links have a way of breaking over time"