Sunday, July 3, 2011

Office 365 SSO - Using smart links or IdP initiated authentication with Office 365

There is a good wiki page explaining how to set smart links. I followed the same, and was still getting error after redirecting to Office 365. After debugging, I figured out what was going wrong.

As per the wiki page, we need to remove QS parameter “bk”. However, I had to remove one more QS parameter “ct” similar to “bk”. I tried to access the service through the normal way at two different times and traced the requests and figured out what was different at both times. Both times, I found values for “bk” and “ct” to be different. So this means that we need to remove these from the smart link.

If you are programmatically trying to generate the URL, then you should be able to even set the value of the QS parameters dynamically. I think the value is total seconds since 1/1/1970. I haven’t tried out this myself yet. So please use this with caution. C# code snippet which could help in this situation is given below.


TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
int timestamp = (int) t.TotalSeconds;
Console.WriteLine(timestamp);

Office 365 SSO Error - Your organization could not sign you into the service

While configuring SSO for Office 365, I ran into this issue of “Your organization could not sign you into the service”. I looked at the documentation provided here, however there were issues in those commands. However, the help provided there and some other blogs/forums helped me to resolve the problem.

Run the following command to see if the configuration matches between ‘ADFS Server’ and ‘Microsoft Office 365’.

> Get-MsolFederationProperty –DomainName YourDomain.com

Initially, I thought everything matches. However, with close inspection, I figured out some minor mismatches (even things like one string doesn’t end with a ‘/’). We need to get everything to match exactly the same to avoid the issue. As per the suggestion, I tried to run the following command to get this fixed.

> Update-MsolFederatedDomain -DomainName YourDomain.com –SupportMultipleDomain

Still, I found the ‘FederationServiceIdentifier’ to be different between ADFS Server and O365.

Then I updated the service identifier on ADFS Server, by going to through ‘AD FS 2.0 Management’ in administrative tools.

  • Open ‘AD FS 2.0 Management’
  • Right click and select ‘Edit Federation Service Properties’ from ‘Service’ node under ‘AD FS 2.0’
  • Change the required properties to match what you need. :)

ADFS_FederationServiceProperties

Tuesday, September 21, 2010

Customized Contrib SSL Jar file

You can find a custom version of the Contrib SSL jar file here.

Sunday, March 28, 2010

Consuming Exchange Web Service from Java – Proxy Generation

Download the WSDL and supporting files from your exchange server. Replace https://www.outlook.com/ with your exchange server details.

Add service definition to Services.wsdl file

<wsdl:service name="ExchangeServices">
    <wsdl:port name="ExchangeServicePort" binding="tns:ExchangeServiceBinding">
      <soap:address location="https://www.outlook.com/EWS/Exchange.asmx"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

Modify the import statement in types.xsd file as follows.

<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2009/01/xml.xsd" />

Now we are good to build the proxy files. Issue the following command to generate the ANT build file and java source files. Once you make further changes to the schema files and do not want to overwrite the build.xml file, you can use ‘--noBuildXML’ option for wsdl2java.

wsdl2java -u -uri Services.wsdl

When you build the files using, ANT, it gives compilation errors. I am not sure, why Axis fail to generate the files correctly. What I have done is to define the member variable for ‘localPathTracker’ in each of those files.

Consuming Exchange Web Service from Java – Setup Environment

  • Install following
    • JDK (1.5 or above)
    • Apache Axis2 (I used Axis 1.4.1)
    • Apache Ant
  • Configure following environment variables
    • JAVA_HOME
    • AXIS2_HOME
    • ANT_HOME
  • Append following to PATH
    • %JAVA_HOME%\bin;%AXIS2_HOME%\bin;%ANT_HOME%\bin
  • Ensure that you can run the following commands from command line
    • java
    • wsdl2java
    • ant

Thursday, March 25, 2010

Consuming Exchange Web Service from Java

I had to get the Exchange Web Service (Exchange Version: 2010) APIs consumed from a Java program. Here is a set of preconditions, that I had, to start working on this.

  • Need to use Apache Axis2 web service stack, version 1.4
  • Consume mail and calendar APIs from Java

I did some research on any existing work for the same. I couldn’t find anything specific for Axis2. However, I found this great wiki page from imap2exchange project, which explains how to do it from Metro. In this blog series, I am trying to put together the sequence of actions I had to do to get the proxy code working from Axis2.

To get the email from user’s inbox, I had to do the following sequence.

  1. Setup your development environment
  2. Customize the WSDL & Schema to get Axis2 generate the proxy
  3. Fix compilation issues of Axis2 generated proxy
  4. Remove some namespace attaching in the request to avoid EWS complaining about the request format
  5. Edit the schema to resolve bugs in Axis2, regenerate proxy code and fix compilation issues

Back to blogging

Title could be little confusing. When I say back to blogging, I wasn’t blogging so frequently earlier. So that is probably a partially correct sentence. What I want to say is, I am starting to blog again now. :)

Wednesday, October 7, 2009

LINQ / Lambda Examples : Aggregate collection


///////////////////////////////////////////////////////////////////////////////
//
// Copyright © Schakra Inc. 2009. All rights reserved.
//

///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace Schakra.Samples.DotNet.Linq
{
///
/// Sample demonstrating aggregating content of a Collection.
///

public class LinqSample_02
{
public void AggregateRequestParameters()
{
// Generate Data.
Random random = new Random();
List uids = new List();
for (int i = 0; i < 10; i++)
{
uids.Add(random.Next(1, int.MaxValue));
}

// Had to use similar code snippet while working with Facebook APIs.
string uidString = uids.Aggregate(
string.Empty,
(s, uid) => string.Format("{0},{1}", s, uid.ToString())
// (s, uid) => s + "," + uid.ToString())
).Substring(1);

// Had to use similar code while working with OAuth signature creation.
SortedList oauthParams = new SortedList();

// Append all parameters in sorted order.
string sigBaseString = oauthParams.Aggregate(
string.Empty,
(s, kvp) => string.Format(
"{0}&{1}={2}", s, UrlEncode(kvp.Key), UrlEncode(kvp.Value))
).Substring(1);
}

private static Regex hexCharsExp = new Regex("%.{2}", RegexOptions.Compiled);

// Custom encoding in upper case for OAuth String.
private static string UrlEncode(string input)
{
if (string.IsNullOrEmpty(input))
{
return input;
}

return hexCharsExp.Replace(
HttpUtility.UrlEncode(input), m => m.Value.ToUpper());
}
}
}

Tuesday, September 29, 2009

LINQ / Lambda Examples : Convert list of one type to another


///////////////////////////////////////////////////////////////////////////////
//
// Copyright © Schakra Inc. 2009. All rights reserved.
//

///////////////////////////////////////////////////////////////////////////////

using System.Collections.Generic;
using System.Linq;

namespace Schakra.Samples.DotNet.Linq
{
public class LinqSample_01
{
List OutlookContacts { get; set; }

public void ConvertListFromOneTypeToAnother()
{
List winLiveContacts =
OutlookContacts.ConvertAll(
contact => contact.ToWindowsLiveContact());

List outlookContacts =
winLiveContacts.ConvertAll(
contact => new OutlookContact()
{
Name = contact.DisplayName,
Phone = contact.MobilePhone
});

List outlookContacts2 =
(from contact in winLiveContacts
select new OutlookContact()
{
Name = contact.DisplayName,
Phone = contact.MobilePhone
}).ToList();
}
}

public class OutlookContact
{
public string Name { get; set; }

public string Phone { get; set; }

public WindowsLiveContact ToWindowsLiveContact()
{
return
new WindowsLiveContact()
{
DisplayName = this.Name,
MobilePhone = this.Phone
};
}
}

public class WindowsLiveContact
{
public string DisplayName { get; set; }

public string MobilePhone { get; set; }
}
}

Wednesday, July 22, 2009

BlackBerry File Explorer

As part of work, we had to generate code coverage report for the application on BlackBerry. We have used Cobertura for J2ME for generating the code coverage results. However, we had to develop a quick tool to transfer the coverage result file generated on the simulator to desktop. For this purpose, we have developed the file explorer / transfer tool for BlackBerry, which works on USB connection.

We would make this tool available tool for public download soon.

Sunday, July 12, 2009

Overriding ServerCertificateValidation

I found the following code very useful, when trying to debug https calls through fiddler. During this proxying, fiddler creates its own certificates, which will be failed by the programs. In order to override the behavior, while doing debugging, the following code could be used.


//using System.Net;
//using System.Security.Cryptography.X509Certificates;
//using System.Net.Security;

ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};

Monday, May 18, 2009

Msbuild throwing exception for v3.5 target code

As part of my current project, I had to build solution which contained both C++ and C# projects. C# project was written for target version of .NET 3.5. Whenever, I tried msbuild from command prompt, it complained ‘must declare a body because it is not marked abstract or extern’ for the property declarations in my C# classes. I have done a lot of research (Thanks to Google) to find a solution for this.

1. I ensured that the csproj file contains the target framework version of 3.5

         <targetframeworkversion>v3.5</targetframeworkversion>

2. Tried to override version through msbuild parameters

         /p:Configuration=Debug;TargetFrameworkVersion=v3.5 /toolsversion:3.5 /property:TargetFrameworkVersion=v3.5 

3. Enabled diagnostic log information for msbuild and identified that csc.exe file from v2.0.50727 is picked up during the build (event though Microsoft.Common.targets is picked up from v3.5)

        /v:diag

4. Did some more search and found out this thread from msdn. So the problem was in my environment COMPLUS_VERSION was set to v2.0.50727

I fixed the problem by setting environment variable 'COMPLUS_VERSION' value to empty. (Since my project file was already set for v3.5, clearing the environment variable helped me. Otherwise, you will need to set it to v3.5)

Thursday, March 26, 2009

Live Messenger IM Control on Blogger

I was reading Mix’09 update from Angus Logan’s blog and noticed Live Messenger IM Control on the side. I found it cool and wanted to add it to my blogger blog as well. Here are the steps that I have followed to get this up and working on my blog.

  1. Get html code for Live Messenger IM Control as specified at Delegated Authentication with the Windows Live Messenger IM Control
  2. Go to Customize > Layout > ‘Page Elements’ on your blogger site
  3. Click on ‘Add a Gadget’ link
  4. Select HTML/JavaScript gadget from Basics collection
  5. Insert the html code generated in step 1 to the ‘Content’ area and give an apt title.
    • Note: You will have to adjust the height and width of iframe to fit correctly with your blogger page template
  6. Save and view your blog. You are all set. :)

Thanks to Rajendra for helping me with this. :)

Wednesday, March 25, 2009

Writing blogs using Live Writer

Windows Live Essentials come with a set of goodies. Out of which Live Writer is a tool which can be used to write blogs and publish to most of the popular blog sites. I am also trying out the same. And this blog is written and posted to my blogger site using Windows Live Writer.

I am listing down, what I liked about Live Writer.

  • Preview of blog is much much better from Live Writer. I love it.
  • Switching between Edit, Preview and Source is faster.
  • I don’t need to do an explicit spell checker
  • I have better control while inserting hyperlinks
  • Tables, alignments, picture, formatting etc looks good. (Haven’t used it really)

What did I not like about Writer?

  • While showing the preview, the labels shown do not seem to be correct. This could be a bug with Writer.
  • With Live Writer also, I am not able to see the code block, custom edit of the template that I made is not coming proper in the preview mode. Yea, I understand that it is difficult for both Blogger and Writer to do it, as it need to sort of invoke the runtime page execution to run the custom script and generate the html output. This is something which I would really like to have. (Either auto execution of script in preview mode, or code style inbuilt in the blogger theme).

Disclaimer: I haven’t used blogger for long time. So I am not really sure about all the features of blogger create page. These are my initial impressions. :)

Debugging using Fiddler

I have been using Fiddler for a long time. I use fiddler to trace http/https calls to see what is the actual http messages (request - response).

From C#, I typically use the following configuration.


<system.net>
<defaultproxy>
<proxy bypassonlocal="False" usesystemdefault="True" />
</defaultproxy>
</system.net>

Sunday, March 22, 2009

Customizing Blogger Template

When I started blogging, one of the main requirements I had was to enable code block on my blog. I have enabled syntax highlighting on my blog by taking help from Using SyntaxHighlighter on BLOGGER and How to get syntax highlighting in Blogger with SyntaxHighlighter.

Also, by default the template that I was using was having smaller width for the main post area. To increase this I have followed Rounders 2 with a wider post area.

APM pattern with Anonymous methods

Jeffrey Ritcher has explained the APM pattern with anonymous methods in one of the concurrent affairs article in msdn magazine. Here, one of the key things to notice is that anonymous delegate method could be executed on another thread at a later point of time (after executing the statements below the BeginXYZ method).

Consider the following APM code.

static void Main(string[] args)
{
// Create instnace of LongTask that is executed asynchronously
// Ref: http://msdn.microsoft.com/en-us/magazine/cc163467.aspx
LongTask task = new LongTask(15); // Task should run for 15 seconds
Console.WriteLine(
string.Format("Thread-{0} : {1}",
Thread.CurrentThread.ManagedThreadId, "Starting Task"));

// APM pattern with anonymous method
task.BeginDoTask(
delegate(IAsyncResult ar)
{
Console.WriteLine(
string.Format("Thread-{0} : {1}",
Thread.CurrentThread.ManagedThreadId, "Delegate called"));
},
null);

Console.WriteLine(
string.Format("Thread-{0} : {1}",
Thread.CurrentThread.ManagedThreadId, "Control came back after BeginDoTask"));

Thread.Sleep(25 * 1000); // Sleep for 25 seconds
}
When I run the above code, output is coming as given below.

Thread-1 : Starting Task
Thread-1 : Control came back after BeginDoTask
Thread-3 : Delegate called
This means that the anonymous method could be called from another thread at a later point of time. So the below given code is very very wrong.

// Following code is very very wrong.
// Never use this approach
int returnData = 0;
asyncObj.BeginXYZ(
delegate(IAsyncResult ar)
{
returnData = asyncObj.EndXYZ(ar);
},
null);

// It is most likely that returnData is 0
return returnData;

Hello World

Hello everyone.. :)

Disclaimer: I have created this blog to share my thoughts, learning, experience and knowledge around various technical areas that I come across. All the information posted here in this blog are solely my own personal opinions and are not related to the company that I work for or anybody else.