I want to integrate Pentaho with Silverlight platform.For the Authentication, there is log in page for user console. I do not want use above login page to login, I want to login in code behind.
I tried basic authentication, but in new version it won't work.
string[] parts = System.Text.RegularExpressions.Regex.Split(ae.Result, "/");
String data = "userid=" + App.UserName + "&password=" + App.Password;
WebClient webClient = new System.Net.WebClient();
Uri uri = new Uri("http://localhost:8080/pentaho/Home?" + data);
webClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
webClient.Encoding = Encoding.UTF8;
App.WindowManager.ConsoleWrite(uri.ToString());
webClient.UploadStringAsync(uri, "POST", "");
But its worked with previous version of Pentaho. I know there are few other methods available in Pentaho. But it should able to do in Silverlight application.
do you know any other solution for do it in Silverlight Application ?
Thanks you very much in advance!!!
In previous version we could pass userid=admin&password=password as part of URL while calling prpt, xaction or Analyzer.
In 5.0 we can authenticate via URL only to Home page.
Try the following to enable it.
i) Stop your Bi server.
ii) Open applicationContext-spring-security.xml and look for filterChainProxy bean.
iii) Comment the existing value section in the bean and add the new value section provided below.
<value>
<![CDATA[CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/api/repos/dashboards/print=securityContextHolderAwareRequestFilter,httpSessionPentahoSessionContextIntegrationFilter,httpSessionContextIntegrationFilter,preAuthenticatedSecurityFilter,httpSessionReuseDetectionFilter,logoutFilter,authenticationProcessingFilter,basicProcessingFilter,requestParameterProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
/webservices/**=securityContextHolderAwareRequestFilterForWS,httpSessionPentahoSessionContextIntegrationFilter,httpSessionContextIntegrationFilter,basicProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilterForWS,filterInvocationInterceptorForWS
/api/**=securityContextHolderAwareRequestFilterForWS,httpSessionPentahoSessionContextIntegrationFilter,httpSessionContextIntegrationFilter,requestParameterProcessingFilter,basicProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilterForWS,filterInvocationInterceptorForWS
/plugin/**=securityContextHolderAwareRequestFilterForWS,httpSessionPentahoSessionContextIntegrationFilter,httpSessionContextIntegrationFilter,requestParameterProcessingFilter,basicProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilterForWS,filterInvocationInterceptorForWS
/**=securityContextHolderAwareRequestFilter,httpSessionPentahoSessionContextIntegrationFilter,httpSessionContextIntegrationFilter,httpSessionReuseDetectionFilter,logoutFilter,authenticationProcessingFilter,basicProcessingFilter,requestParameterProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor]]>
</value>
iv) Restart your server, you should be able to call a report or xaction with user credientials in the url.
v) Use this test URL http://localhost:8080/pentaho/api/repos/:public:Steel%20Wheels:Buyer%20Report%20%28sparkline%20report%29.prpt/viewer?userid=admin&password=password
Authenticate with query string method is unsecured one, so I found a solution with Basic Authentication method.
WebClient webClient = new System.Net.WebClient();
Uri uri = new Uri("http://serverDomain:8080/pentaho/Home");
//Give user name and password here
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("username:password");
var encodedString = System.Convert.ToBase64String(plainTextBytes);
webClient.Headers["Authorization"] = "Basic " + encodedString;
webClient.Encoding = Encoding.UTF8;
App.WindowManager.ConsoleWrite(uri.ToString());
webClient.UploadStringAsync(uri, "POST", "");
Related
First of all I am new to C#. I am writing a WPF program in Visual Studio 2019.
In my project I have multiple web requests and whilst testing how they work the functionality was minimal: only the web requests were made and they were working fine until now. The login authorization request still works.
This is my webrequest.
using (var client = new WebClientEx())
{
client.BaseAddress = serverurl.serviceurl;
client.UseDefaultCredentials = true;
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(excelvertibas.username + ":" + excelvertibas.password));
client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
client.Timeout = 90000;
byte[] postArray = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(domObjectVariables));
client.Headers.Add("Content-Type", "application/json");//----------------
client.Encoding = Encoding.UTF8;
byte[] responseArray = client.UploadData(serverurl.serviceurl + "StartAddDigitalObject", "post", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(domObjectVariables))); //----------------------------
domMetadataAddResponse = JsonConvert.DeserializeObject<StartAddDigitalObjectResponse>(Encoding.UTF8.GetString(responseArray));
}
The base address works, I tested it manually through Postman.
Username and password are also correct which I have tested.
Post array is also passing information which is needed, and I have checked it whilst adding breakpoints.
My question is why could this be not working anymore and what should I look for?
fyi this is the line of code where is should be getting information back into the response array but for some reason it stays null.
byte[] responseArray = client.UploadData(serverurl.serviceurl + "StartAddDigitalObject", "post", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(domObjectVariables)));
After this the program breaks because the response array contains nothing when I try to pass it further.
Ok i understood what was the problem , when i got the response from the server , it was me who didnt provide the necessary field for the server to respond with anything.So everything was fine with the code.
myAPI is the name of a web service reference I added to my project and I am trying to send Basic Authorization into the header of the SOAP request using C# but it’s not happening no matter what method I try.
I read a lot online and ended up with the following ways but none seem to work with mine.
What I've tried:
Method 1: no error but does nothing
NetworkCredential netCredential = new NetworkCredential("un", "pw");
Uri uri = new Uri(resol.Url);
ICredentials credentials = netCredential.GetCredential(uri, "Basic");
myAPI.Credentials = credentials;
myAPI.PreAuthenticate = true;
Method 2: (FYI ResolvingBinding (below) basically consists of all my method which comes from the service reference myAPI) but the problem is : "client" does not have any definition for InnerChannel and ClientCredential so this method fails too
myAPI.ResolvingBinding client = new myAPI.ResolvingBinding();
using (OperationContextScope scope = new OperationContextScope(client.InnerChannel))
{
var httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " +
Convert.ToBase64String(Encoding.ASCII.GetBytes(client.ClientCredentials.UserName.UserName + ":" +
client.ClientCredentials.UserName.Password));
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
client.DoSomething();
}
My ultimate end goal is to encode username:password into base 64 which I tried in the second example.
How do I go about resolving this? Please feel free to add a comment/leave a suggestion or point out mistakes I might've overlooked.
This code should add your basic authentication to your header
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(<userId> + ":" +<pw>);
string val = System.Convert.ToBase64String(plainTextBytes);
string textValue = "Basic " + val;
httpRequestProperty.Headers.Add("Authorization", textValue);
So basically I'm working on integrating a web API into my project from an externally hosted source.. But the xml is stored behind basic authentication. So I've been advised that I need to parse some authentication into the header of my HTTP request when contacting the location of the XML.
Here's what I'm working with at the moment:
I've created a controller, my code is as follows:
namespace com.tortoise.Controllers
{
public class VebraController : ApiController
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");
string username = "user";
string password = "password";
string usernamePassword = ("username + : + password");
CredentialCache cache = new CredentialCache();
new cache.add Uri(url), "Basic", new class NetworkCredential(username, password));
request.Credentials = cache;
request.Headers.Add("Authorization", "Basic " // <- space here.
+ Convert.ToBase64String()(new Int64 ASCIIEncoding().GetBytes (usernamePassword));
// Get the token from the response:
string token = response.GetResponseHeader("Token");
}
Any help is great. I'm receiving errors in CredentialCache, ASCIIEncoding, ToBase64String(), GetBytes() and GetResponseHeader().
Alright, I have fixed your code a bit. It should compile now, assuming you have actually declared the variables you are using. I can't do that for you. Please read the comments. You seem to need a lot of practice with C# syntax and the language in general, you had a lot of invalid C# in there. Hope this helps.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
string username = "user";
string password = "password";
//here I am declaring the NetworkCredentials. You do not need to put 'new class'
NetworkCredential myCredentials = new System.Net.NetworkCredential(username,password);
string usernamePassword = (username + password); //I assume you meant to concatenate them
CredentialCache cache = new CredentialCache();
cache.Add((Uri)url, "Basic", myCredentials); //you must declare url, not sure what you want it to be
request.Credentials = cache;
request.Headers.Add("Authorization", "Basic " // <- space here.
+ Convert.ToBase64String(Encoding.ASCII.GetBytes(usernamePassword)); //fixed this
// Get the token from the response:
string token = response.GetResponseHeader("Token"); //you need to declare response somewhere
When I am using HttpWebRequest I use the following code to set the Credentials
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlToCall);
request.Method = "GET";
request.Credentials = new NetworkCredential(username, pass);
How do I do the same when I am using BackgroundTransferService in Windows Phone 8.
For reference I am using the following.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202955%28v=vs.105%29.aspx
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202959%28v=vs.105%29.aspx
*Edit:
The authentication method is Digest
This is what I get in the Authorization Header when I use my browser to download the file.
Digest username="adf", realm="bcd", nonce="XXXXXXXXX", uri="/ans/1268e52399.txt", algorithm=MD5, response="XXXXXXXXXXXXXXX", qop=auth, nc=00000001, cnonce="XXXXXXXXXXXX"
Unfortunately this isn't supported on the BackgroundTranserService. One possible solution might be to manually create a header for your request like below:
var credentials = new UTF8Encoding().GetBytes(username + ":" +password);
var transferRequest = new BackgroundTransferRequest(transferUri);
transferRequest.Headers["Authorization"] ="Basic " + convert.ToBase64String(credentials);
Unfortunately I'm unable to test this at the minute, give it a try and let me know how you get on.
I'm trying to get list of torrents from uTorrent using Web API. Getting required token goes O.K.:
WebClient client = new WebClient() { Credentials = new NetworkCredential(UserName, pass) };
StreamReader Reader = new StreamReader(client.OpenRead("http://localhost:" + port + "/gui/token.html"));
string token = Reader.ReadToEnd();
token = token.Split('>')[2].Split('<')[0];
// token is now something like 3LemfrO_-A-SNBXlnQ2QcQWTYydx7qOqKb1W1S54JJW74Ly3EYGgu0xQSU4AAAAA
But when I try to use it to get list of torrents:
Reader = new StreamReader(client.OpenRead("http://localhost:" + port + "/gui/?list=1&token=" + token));
all I get is "Error 400 Bad request".
I've tried to get token manually. In browser page "http://localhost:30303/gui/?list=1&token=3LemfrO_-A-SNBXlnQ2QcQWTYydx7qOqKb1W1S54JJW74Ly3EYGgu0xQSU4AAAAA" opens as it should, but in C# with the same link without any variables I still get error 400.
The interesting part is that if switch off token authentication WebClient load page perfectly with and without
"&token=3LemfrO_-A-SNBXlnQ2QcQWTYydx7qOqKb1W1S54JJW74Ly3EYGgu0xQSU4AAAAA"
but token auth enabled by default, so my and any app should use it.
And yes, WebRequest/HttpWebRequest didn't help also.
P.S. sorry for my English, I was never able to make it work right
you have to save the cookie from the request
Classes.CookieAwareWebClient client = new Classes.CookieAwareWebClient() { Credentials = new NetworkCredential("shehab", "shehab") };
StreamReader Reader = new StreamReader(client.OpenRead("http://localhost:" + "8080" + "/gui/token.html"));
string token = HtmlRemoval.StripTagsRegexCompiled(Reader.ReadToEnd());
MessageBox.Show(token);
Reader = new StreamReader(client.OpenRead("http://localhost:" + "8080" + "/gui/?list=1&token=" + token));
MessageBox.Show(Reader.ReadToEnd());
and for the cookie aware class go to the following link(Using CookieContainer with WebClient class) as web client doesn't support cookies.
You should save cookies from request
WebRequest request = WebRequest.Create("http://localhost:" + port + "/gui/token.html");
CookieContainer cookies = new CookieContainer();
(request as HttpWebRequest).CookieContainer = cookies;
And then use it in every other request to uTorrent when using the same token:
request = WebRequest.Create("http://localhost:" + port + "/gui/?list=1&token=" + token);
(request as HttpWebRequest).CookieContainer = cookies;
I have a simple 3-step suggestion:
When you use your browser with the token, use Fiddler2 to analyze the HTTP traffic between the server and browser.
Open up your C# app and use Fiddler2 to analyze the HTTP traffic between the server and your app.
Compare the HTTP requests and responses for the browser with the requests and responses for the C# app. If you see a significant difference, there is a good chance that could be the problem.