beautypg.com

Appendix a, Sample trusted application client code in c – Google Search Appliance Security User Manual

Page 40

background image


40

Appendix A

Sample Trusted Application client code in C#

using

System;

using

System

.

Collections

.

Generic;

using

System

.

Linq;

using

System

.

Net;

using

System

.

IO;

using

System

.

Text;

namespace

TrustedApp

{

class

GSAClient

{

String

GSA_SESSION_ID

=

"GSA_SESSION_ID";

String

_gsaSessionId

=

null;

String

_trustedUser;

String

_trustedPwd;

String

_gsaHostName;

String

_endUser;

String

_credentialGroup;

static

void

Main

(

string

[]

args)

{

String

gsaHostName

=

"gsa.acme.com";

String

userName

=

"trusteduser_a"

,

userPassword

=

"pwd";

GSAClient

gsaClient

=

new

GSAClient

(

gsaHostName

,

userName

,

userPassword

,

"Default"

,

"enduser_a"

);

gsaClient

.

search

(

"access=a&q=some_keyword&site=default_frontend"

);

}

public

GSAClient

(

String

gsaHostName

,

String

trustedUser

,

String

trustedPwd

,

String

credentialGroup

,

String

endUser)

{

_gsaHostName

=

gsaHostName;

_trustedUser

=

trustedUser;

_trustedPwd

=

trustedPwd;

_credentialGroup

=

credentialGroup;

_endUser

=

endUser;

}

String

search

(

String

q)

{

int

iRetry

=

0;

HttpWebRequest

request;

Initiate:

request

=

(

HttpWebRequest

)

WebRequest

.

Create

(

"https://"

+

_gsaHostName

+

"/search"

);

request

.

Method

=

"POST";