martes, 9 de junio de 2015

CAML Designer for SP2013

As you probably know the U2U Caml Query Builder was taken out and it is unavailable to download at this moment. In the other you could have your saved copy of the older versions of U2U Caml Query Builder, but unfortunately they are also not compatible with SharePoint 2013.

The alternative:
camlDesignerLogo.png





 These good guys at BIWUG (http://www.biwug.be/resources) have published a cool tool called: CAML Designer, it has a nice "Metro" UI and several cool features:

  • Connects against SP2010, SP2013 and Office 365 (If you want to use Caml Designer together with O365. It can be that you first have to install the SP 2013 Server SDK first, because of a dll that is needed by MS.SP.Client.dll to connect  via de CSOM)
  • Query generation tools: ViewFields, OrderBy, Where, Query Options and Online Test.
  • Auto-generated source code for: CAML, Server OB, CSOM .NET, CSOM REST, Web Services and also PowerShell !!
  • Debug info while testing queries.
I have tried this awesome tool with SP2013 and it works very good.
 

martes, 2 de junio de 2015

Google ReCaptcha 2 in SharePoint 2013 Application Page (or any ASP.NET)

Recently Google has released a new version of recaptcha, with enhanced security and richer user experience. The documentation available at this time does not include the steps to implement Google recaptcha in ASP.NET applications nor SharePoint. My intention in this article is to explain the detailed step by step to add this robot proof widget in our SharePoint application pages, but it would also will work for any ASP.NET application.

The steps:
 
1) Register your application at:

https://www.google.com/recaptcha/admin#list
 
You must enter an identifying label of your web application, which will help you later to manage keys and our application domain, for example: "myapp.com". Important: You don't need add a public domain, private domains as "
svr2013-local" will also work fine.

2) After registering our application you have the keys to implement recaptcha: "Site key" which you will use to create our recaptcha widget in html, and also "Secret key" which you will use to communicate with the recaptcha validator service but from the server's side. 

3) To integrate in your HTML client the recaptcha script reference must be incorporated in the HEAD section of the page : 

<Script src = 'https: //www.google.com/recaptcha/api.js'> </ script> 

In the case of an application page of SharePoint 2013, as all .js, style sheets and others will go into this container: 

<Asp: Content ID = "PageHead" ContentPlaceHolderID = "PlaceHolderAdditionalPageHead" runat = "server"><Script src = 'https: //www.google.com/recaptcha/api.js'> </ script></ Asp: Content>

4) then you must incorporate the widget recaptcha:
 
<div class = "g-recaptcha" This data-SiteKey = "here's your key site"> </ div>

 
within the web form (before the </ form>), in the case of an application page of SharePoint 2013 anger within the container:

 
<asp: Content ID = "Main" ContentPlaceHolderID = "PlaceHolderMain" runat = "server">
<div id="section0">
                <div class="field">
                    <label for="FullName">Full Name</label>
                   
                    <asp:TextBox runat="server" ID="FullName" ClientIDMode="Static" required placeholder="enter your first name and surname" />
                </div>
                <div class="field">
                    <label for="Email">Email</label>
                   
                    <asp:TextBox runat="server" ID="Email" ClientIDMode="Static" required placeholder="enter your email address" type="email" />
                </div>
                <div class="field">
                    <label for="Country">Location</label>
                    <asp:HiddenField runat="server" ID="HiddenCountry" ClientIDMode="Static" />
                    <asp:TextBox runat="server" ID="Country" ClientIDMode="Static" placeholder="enter your location" required />
                </div>
                <div class="field">
                    <label for="Company">Company</label>
                    <asp:HiddenField runat="server" ID="HiddenCompany" ClientIDMode="Static" />
                    <asp:TextBox runat="server" ID="Company" ClientIDMode="Static" placeholder="enter your company" required />
                    </div>
                <div class="field">
                    <label for="Community">Community</label>
                    <asp:HiddenField runat="server" ID="HiddenCommunity" ClientIDMode="Static" />
                    <asp:TextBox runat="server" ID="Community" ClientIDMode="Static" placeholder="enter the community you want to join" />
                </div>
                <div class="field">
                    <label for="Comments">Comments</label>
                    <!--<input id="Comments" name="Comments" size="65" placeholder="if you have any comment or sugestion please enter here" type="text" />-->
                    <asp:TextBox runat="server" ID="Comments" ClientIDMode="Static" placeholder="if you have any comment or sugestion please leave it here"  />
                </div>
                <div class="field">                   

<div class = "g-recaptcha" This data-SiteKey = "here's your key site"> </ div>                
</div>
                <div class="field">
                    <asp:Button runat="server" ID="SendButton" Text="Submit" OnClick="SendButton_Click"  />
                </div>


</ asp: Content>


5) Google recaptcha allows integration with our server side, so you can control the server side validation, to do so you will create a class called "CaptchaResponse":

public class CaptchaResponse
     {

         public bool Success {get; Set; }


         public List <string> ErrorCodes {get; Set; }
     }


You also need to create a method to validate the response recatpcha, this will do in the main class of our website:
 public bool ValidateCaptcha()
        
{
            
var response = Request ["g-recaptcha-response"];
            
secret = const string "here's your secret key";

            
var client = new WebClient ();
            
var reply =
                
client.DownloadString (
                    
string.Format ("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}" secret, response));
           
var serializer = new
JavaScriptSerializer();
            
var captchaResponse = serializer.Deserialize <CaptchaResponse> (reply);

            
if (! captchaResponse.Success)
            
{
                
return false;
            
}


            
return true;
        
}


As you can see you could also control according to the type of error that brings us back but in my case it was not necessary, it is only required to know whether it was valid or not.

5) Finally in the OnClick event of the button on the form called the "ValidateCaptcha" method:

 protected void SendButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.Page.IsValid && ValidateCaptcha())
                {
                    //Do something
.
.
.
                    Response.Redirect("Confirmation.aspx",false);
                }
              
               
            }
            catch(Exception ex)
            {
                Response.RedirectPermanent("Failure.aspx");
            }

        }


Conclusion: Implementing Google recaptcha 2 in our ASP.NET applications could improve the security or the data entries. The implementation requires only a few steps and it is very straight forward to get it work in almost no time.
 

domingo, 26 de enero de 2014

Lista de TemplateType de Listas de SharePoint 2013


Las listas de SharePoint son creadas a partir de un tipo plantilla (TemplateType) predeterminada, en el modelo de objetos de SharePoint 2013 se conocen como SPListTemplateType, en oportunidades es conveniente conocer el tipo de plantilla de una lista en particulas así como su descripción correspondiente. 

Lista de la descripción y su valor:
Not used. Value = -1.
unspecified list type. Value = 0
Custom list. Value = 100.
Document library. Value = 101.
Survey. Value = 102.
Links. Value = 103.
Announcements. Value = 104.
Contacts. Value = 105.
Calendar. Value = 106.
Tasks. Value = 107.
Discussion board. Value = 108.
Picture library. Value = 109.
Data sources for a site. Value = 110.
Site template gallery. Value = 111.
User Information. Value = 112.
Web Part gallery. Value = 113.
List Template gallery. Value = 114.
XML Form library. Value = 115.
Master Page gallery. Value = 116.
No Code Workflows. Value = 117.
Custom Workflow Process. Value = 118.
Wiki Page Library. Value = 119.
Custom grid for a list. Value = 120.
Solutions. Value = 121
No Code Public Workflow. Value = 122
Themes. Value = 123
DesignCatalog.Value = 124
AppDataCatalog.Value = 125
Data connection library for sharing information about external data connections. Value = 130.
Workflow History. Value = 140.
Project Tasks. Value = 150.
Help Library. Value = 151.
Access Request List. Value = 160.
Tasks with Timeline and Hierarchy. Value = 171.
Maintenance Logs Library. Value = 175.
Meeting Series (Meeting). Value = 200.
Agenda (Meeting). Value = 201.
Attendees (Meeting). Value = 202.
Decisions (Meeting). Value = 204.
Objectives (Meeting). Value = 207.
Text Box (Meeting). Value = 210.
Things To Bring (Meeting). Value = 211.
Workspace Pages (Meeting). Value = 212.
Posts (Blog). Value = 301.
Comments (Blog). Value = 302.
Categories (Blog). Value = 303.
Facility. Value = 402
Whereabouts. Value = 403
Call Track. Value = 404
Circulation. Value = 405
Timecard. Value = 420
Holidays. Value = 421
IME (Input Method Editor) Dictionary. Value = 499
External. Value = 600
MySiteDocumentLibrary.Value = 700
Issue tracking. Value = 1100.
Administrator Tasks. Value = 1200.
Health Rules. Value = 1220
Health Reports. Value = 1221
Draft Apps library in Developer Site. Value = 1230

martes, 10 de diciembre de 2013

Habilitar Cambio de Password en Directorio AD LDS sin SSL

Por defecto AD LDS No permite a los usuarios restablecer contraseñas en el repositorio AD LDS a través de conexión sin SSL. La razón es simple, sin SSL la contraseña viaja al igual que los demás datos sin encriptación.
Cuando se instala una instancia de desarrollo de AD LDS es muy probable que no se requiera configurar el SSL para las actividades de desarrollo.
Por conveniencia del AD LDS Permite a los desarrolladores para deshabilitar los requisitos de SSL para la conexión a restablecer las contraseñas.

Procedimiento para deshabilitar el requerimiento de SSL:

C:\Windows\ADAM>dsmgmt
dsmgmt: DS Behavior
AD DS/LDS behavior: Connections
server connections: Connect to server localhost:389
Binding to localhost:389...
Connected to localhost:389 using credentials of locally logged on user.
server connections: q
AD DS/LDS behavior: Allow Passwd op on unsecured connection
Successfully modified AD DS/LDS Behavior to reset password over unsecured network.
AD DS/LDS behavior: q
dsmgmt: q
C:\Windows\ADAM>

Ejemplo:


Luego de ejecutar estos comandos será posible restablecer contraseñas de usuarios del AD LDS sin requerir SSL.

miércoles, 6 de noviembre de 2013

Como generar OID (Object Identifier) mediante Power Shell

Recientemente estuve trabajando en un proyecto que incluyó un directorio de usuarios con AD LDS (Active Directory Light Weight Directory Service), y atributos personalizados para los usuarios. Luego de investigar un poco encontre una manera muy expedita de agregar atributos personalizados al objeto "user" del AD LDS, sin embargo para ello es requerido contar con un OID para identificar cada atributo que se desee crear.
Según Wikipedia: "OID es un identificador utilizado para nombrar un objeto (comparar URN). Estructuralmente, un OID consta de un nodo en un espacio de nombres jerárquico asignado, que se define formalmente mediante ASN.1 estándar de la ITU-T X.690. Números sucesivos de los nodos, a partir de la raíz del árbol, identificar cada nodo en el árbol." dicho en palabras màs simples el OID es el identificador único de todo objeto, para crear nuevos objetos es necesario generar un OID válido que en el caso de Microsoft tienen el prefijo: 1.2.840.113556.1.8000.2554.
Existen varias formas de generar el famoso OID, pero encuentro una forma muy sencilla de hacerlo mediante Power Shell, usuando para ello las siguiente instrucciones:
#---
$Prefix="1.2.840.113556.1.8000.2554"
$GUID=[System.Guid]::NewGuid().ToString()
$Parts=@()
$Parts+=[UInt64]::Parse($guid.SubString(0,4),"AllowHexSpecifier")
$Parts+=[UInt64]::Parse($guid.SubString(4,4),"AllowHexSpecifier")
$Parts+=[UInt64]::Parse($guid.SubString(9,4),"AllowHexSpecifier")
$Parts+=[UInt64]::Parse($guid.SubString(14,4),"AllowHexSpecifier")
$Parts+=[UInt64]::Parse($guid.SubString(19,4),"AllowHexSpecifier")
$Parts+=[UInt64]::Parse($guid.SubString(24,6),"AllowHexSpecifier")
$Parts+=[UInt64]::Parse($guid.SubString(30,6),"AllowHexSpecifier")
$OID=[String]::Format("{0}.{1}.{2}.{3}.{4}.{5}.{6}.{7}",$prefix,$Parts[0],$Parts[1],$Parts[2],$Parts[3],$Parts[4],$Parts[5],$Parts[6])
$oid
#---
 Este Script es una contribución de Jiri Formacek 

Espero les ayude en sus proyectos donde sea necesario generar un OID.