Index: /trunk/prototype/config/Tonic.srv
===================================================================
--- /trunk/prototype/config/Tonic.srv	(revision 6559)
+++ /trunk/prototype/config/Tonic.srv	(revision 6578)
@@ -15,5 +15,5 @@
 
 [/sharedcontact/:id]
-SharedContactsResource = /catalog/SharedContactResource.php
+SharedContactResource = /catalog/SharedContactResource.php
 
 [/groups]
@@ -24,5 +24,5 @@
 
 [/sharedgroup/:id]
-SharedGroupsResource = /catalog/SharedGroupResource.php
+SharedGroupResource = /catalog/SharedGroupResource.php
 
 [/dynamiccontacts]
Index: /trunk/prototype/config/contactGroup.ini
===================================================================
--- /trunk/prototype/config/contactGroup.ini	(revision 6528)
+++ /trunk/prototype/config/contactGroup.ini	(revision 6578)
@@ -3,5 +3,5 @@
 
 [after.find]
-findGroupConnections = modules/catalog/interceptors/DBMapping.php
+findGroupConnections = modules/catalog/interceptors/CatalogDBMapping.php
 
 [PostgreSQL.mapping]
Index: /trunk/prototype/config/contact.ini
===================================================================
--- /trunk/prototype/config/contact.ini	(revision 6528)
+++ /trunk/prototype/config/contact.ini	(revision 6578)
@@ -3,5 +3,5 @@
 
 [after.find]
-findConnections = modules/catalog/interceptors/DBMapping.php
+findConnections = modules/catalog/interceptors/CatalogDBMapping.php
 
 [PostgreSQL.mapping]
Index: /trunk/prototype/rest/catalog/SharedContactResource.php
===================================================================
--- /trunk/prototype/rest/catalog/SharedContactResource.php	(revision 6578)
+++ /trunk/prototype/rest/catalog/SharedContactResource.php	(revision 6578)
@@ -0,0 +1,292 @@
+<?php
+
+if (!defined('ROOTPATH'))
+    define('ROOTPATH', dirname(__FILE__) . '/..');
+
+require_once(ROOTPATH . '/rest/hypermedia/hypermedia.php');
+
+use prototype\api\Config as Config;
+
+class SharedContactResource extends Resource {
+
+    /**
+     * Retorna um contato compartilhado 
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     Retorna um contato Compartilhado
+     * @access     public
+     * */
+    function get($request, $id) {
+
+	$this->secured();
+
+	$response = new Response($request);
+	$response->addHeader('Content-type', 'aplication/json');
+	$response->code = Response::OK;
+
+	$h = new Hypermedia();
+	$c = new Collection($request->resources, 'SharedGroupResource');
+
+	try {
+
+	    //Recupera o contato
+            $contact = Controller::find( array( 'concept' => 'contact' ), false, array( 'filter' => array('=', 'id', $id) ) );
+
+            if (!$contact) {
+                $this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Resource not found.');
+                return $response;
+            }
+
+	    //Proprietario do contato 
+	    $ownerId = $contact[0]['user'];
+
+	    $idS = array(Config::me("uidNumber"));
+	    $acl = array();
+
+	    //Recupera o uidNumber do usuário que compartilhou o grupo com o usuário logado
+	    $sql = 'SELECT acl_account as "uidNumber", acl_rights as "acl" '.
+		   'FROM phpgw_acl '.
+		   'WHERE (acl_location =   \'' . Config::me("uidNumber") . '\' AND acl_appname =  \'contactcenter\' AND acl_account = \''.$ownerId.'\')';
+	    $shareds = Controller::service('PostgreSQL')->execResultSql($sql);
+
+	    //Verifica o acesso definido para o usuario logado
+	    $flagContact = false;
+	    if (!empty($shareds) && $shareds){
+		foreach ($shareds as $s) {
+		    array_push($idS, $s['uidNumber']);
+		    $acl[$s['uidNumber']] = $this->decodeAcl(decbin($s['acl']));
+
+		    //verifica se o proprietario do contato habilitou o acesso de leitura para o usuario logado
+		    if($s['uidNumber'] == $ownerId && $acl[$s['uidNumber']]['read']){
+			$flagContact = true;
+		    }
+		}
+	    }
+
+	    //Se o contato nao esta compartilhado
+	    if(!$flagContact){
+		$this->createException($request, $response, Response::UNAUTHORIZED, 'unauthorized', 'Resource unauthorized.');
+		return $response;
+	    }
+
+	    //Obtem informacoes do proprietario do contato
+	    $userOwner = Controller::read(
+					   array('concept' => 'user','service'=>'OpenLDAP'), 
+					   false, 
+					   array('filter' => array('=', 'id', $ownerId ), 'notExternal' => true)
+	    );
+
+	    if(is_array($userOwner)){
+		$userOwner = $userOwner[0];
+	    }
+
+            $t = new Template();
+            $d = new Data();
+
+            $d->setName('name');
+            $d->setValue(null);
+            $d->setPrompt('Nome do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('email');
+            $d->setValue(null);
+            $d->setPrompt('Email do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('telefone');
+            $d->setValue(null);
+            $d->setPrompt('Telefone do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $c->setTemplate($t);
+
+
+            $d = new Data();
+            $d->setName('name');
+            $d->setValue($contact[0]['name']);
+            $d->setPrompt('Nome do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength('100');
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('email');
+            $d->setValue($contact[0]['email']);
+            $d->setPrompt('Email do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength('100');
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('telephone');
+            $d->setValue($contact[0]['telephone']);
+            $d->setPrompt('Telefone do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength('100');
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('ownerId');
+            $d->setValue($userOwner['id']);
+            $d->setPrompt('Atributo UID (LDAP)');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('ownerName');
+            $d->setValue($userOwner['name']);
+            $d->setPrompt('Atributo cn (LDAP)');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            //Define os link baseado nas permissoes de acesso
+            if(Config::me('uidNumber') != $value['user']){
+                    /*Descomentar ao implementar os métodos
+                    if($acl[$value['user']]['delete']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('delete');
+                          $l->setAlt('Remover');
+                          $l->setPrompt('Remover');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }
+
+                    if($acl[$value['user']]['update']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('put');
+                          $l->setAlt('Atualizar');
+                          $l->setPrompt('Atualizar');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }
+
+                    if($acl[$value['user']]['write']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('post');
+			  $l->setAlt('Criar');
+                          $l->setPrompt('Criar novo');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }
+
+                    if($acl[$value['user']]['read']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('get');
+                          $l->setAlt('Buscar');
+                          $l->setPrompt('Buscar');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }*/
+            }
+            else{
+                    /*Descomentar ao implementar métodos no recurso
+                    $l = new Link();
+                    $l->setHref('');
+                    $l->setRel('delete');
+                    $l->setAlt('Remover');
+                    $l->setPrompt('Remover');
+                    $l->setRender('link');
+                    $i->addLink($l);
+
+                    $l = new Link();
+                    $l->setHref('');
+                    $l->setRel('put');
+                    $l->setAlt('Atualizar');
+                    $l->setPrompt('Atualizar');
+                    $l->setRender('link');
+                    $i->addLink($l);
+
+                    $l = new Link();
+                    $l->setHref('');
+                    $l->setRel('get');
+                    $l->setAlt('Buscar');
+                    $l->setPrompt('Buscar');
+                    $l->setRender('link');
+
+                    $i->addLink($l);
+                    */
+            }
+
+            $h->setCollection($c);
+
+	} catch (Exception $ex) {
+	    $this->createException($request, $response, Response::INTERNALSERVERERROR, 'Internal Server Error', $ex);
+	    return $response;
+	}
+
+	$response->body = $h->getHypermedia($request->accept[10][0]);
+	return $response;
+    }
+
+    function decodeAcl($bin) {
+
+	$acl = array();
+	$bin = str_split($bin);
+	$acl['read'] = (isset($bin[0]) && $bin[0] == 1) ? true : false;
+	$acl['write'] = (isset($bin[1]) && $bin[1] == 1) ? true : false;
+	$acl['update'] = (isset($bin[2]) && $bin[2] == 1) ? true : false;
+	$acl['delete'] = (isset($bin[3]) && $bin[3] == 1) ? true : false;
+
+	return $acl;
+    }
+
+    private function createException($request, &$response, $code, $title, $description) {
+	$response->code = $code;
+
+	$h = new Hypermedia();
+	$c = new Collection($request->resources, 'DynamicContactResource');
+	$e = new Error();
+
+	$e->setCode($code);
+	$e->setTitle($title);
+	$e->setDescription($description);
+
+	$c->setError($e);
+	$h->setCollection($c);
+
+	$response->body = $h->getHypermedia($request->accept[10][0]);
+    }
+}
+
+?>
Index: /trunk/prototype/rest/catalog/DynamicContactsResource.php
===================================================================
--- /trunk/prototype/rest/catalog/DynamicContactsResource.php	(revision 6528)
+++ /trunk/prototype/rest/catalog/DynamicContactsResource.php	(revision 6578)
@@ -189,5 +189,5 @@
 	}
 
-	//recupera os atributos definidos no conceito 'user'
+	//recuperar os atributos definidos no conceito 'user'
 	$map = Config::get('dynamicContact', 'PostgreSQL.mapping');
 
@@ -207,5 +207,4 @@
 	}
 
-
 	$response = new Response($request);
 	$response->addHeader('Content-type', 'aplication/json');
@@ -220,16 +219,43 @@
 
 	try {
-	    $idDynamicContact = Controller::create(
-			    array('concept' => 'dynamicContact'), $params
-	    );
-
-	    if (!$idDynamicContact) {
-		throw new Exception(Controller::service('PostgreSQL')->error);
-	    }
+
+		//verificar o limite maximo de contatos dinamicos nas preferencias do administrador
+		$sql = 	"SELECT config_value ".
+			"FROM phpgw_config ".
+			"WHERE config_app = 'expressoMail1_2' ".
+				"AND config_name = 'expressoMail_Number_of_dynamic_contacts'";
+
+		$numberOfMessages = Controller::service('PostgreSQL')->execResultSql($sql, true);
+		$numberOfMessages = (count($numberOfMessages) > 0) ? (int)$numberOfMessages['config_value'] : 0;
+
+		//realizar busca de contatos dinamicos ordenados pela data de utilizacao
+		$dynamicContacts = Controller::find(array('concept' => 'dynamicContact'), false, array('filter' => array('=', 'owner', Config::me("uidNumber")), 'order' => array('timestamp') ) );
+		$numberOfDynamicContacts = ($dynamicContacts !== false) ? count($dynamicContacts) : 0;
+
+
+		//se a quantidade de contatos dinamicos de usuario exceder o limite maximo definido nas preferencias do administrador,
+		//remover o contato dinamico mais antigo
+		if($numberOfDynamicContacts >= $numberOfMessages){
+			$id = $dynamicContacts[0]['id'];
+			$delete = Controller::delete(array('concept' => 'dynamicContact', 'id' => $id));
+
+			if (!$delete) {
+				$this->createException($request, $response, Response::INTERNALSERVERERROR, 'Internal Server Error', Controller::service('PostgreSQL')->error);
+				return $response;
+			}
+		}	
+
+		//inserir o novo contato dinamico
+		$create = Controller::create( array('concept' => 'dynamicContact'), $params );
+
+		if (!$create) {
+			throw new Exception(Controller::service('PostgreSQL')->error);
+		}
+
 	} catch (Exception $ex) {
+
 	    $response->code = Response::INTERNALSERVERERROR;
 	    return $response;
 	}
-
 	$response->body = json_encode(null);
 
Index: /trunk/prototype/rest/catalog/SharedGroupResource.php
===================================================================
--- /trunk/prototype/rest/catalog/SharedGroupResource.php	(revision 6578)
+++ /trunk/prototype/rest/catalog/SharedGroupResource.php	(revision 6578)
@@ -0,0 +1,413 @@
+<?php
+
+if (!defined('ROOTPATH'))
+    define('ROOTPATH', dirname(__FILE__) . '/..');
+
+require_once(ROOTPATH . '/rest/hypermedia/hypermedia.php');
+
+use prototype\api\Config as Config;
+
+class SharedGroupResource extends Resource {
+
+    /**
+     * Retorna um grupo compartilhado 
+     *
+     * @license    http://www.gnu.org/copyleft/gpl.html GPL
+     * @author     Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br)
+     * @sponsor    Caixa Econômica Federal
+     * @author     José Vicente Tezza Jr. 
+     * @return     Retorna os contatos de um Grupo Compartilhado
+     * @access     public
+     * */
+    function get($request, $id) {
+
+	$this->secured();
+
+	$response = new Response($request);
+	$response->addHeader('Content-type', 'aplication/json');
+	$response->code = Response::OK;
+
+	$h = new Hypermedia();
+	$c = new Collection($request->resources, 'SharedGroupResource');
+
+	try {
+
+	    //Recupera o grupo 
+	    $group = Controller::read(array('concept' => 'contactGroup'), false, array('filter' => array('=', 'id', $id)));
+
+            if (!$group) {
+                $this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Resource not found.');
+                return $response;
+            }
+
+	    //Proprietario do grupo
+	    $ownerId = $group[0]['user'];
+
+	    $idS = array(Config::me("uidNumber"));
+	    $acl = array();
+
+	    //Recupera o uidNumber do usuário que compartilhou o grupo com o usuário logado
+	    $sql = 'SELECT acl_account as "uidNumber", acl_rights as "acl" '.
+		   'FROM phpgw_acl '.
+		   'WHERE (acl_location =   \'' . Config::me("uidNumber") . '\' AND acl_appname =  \'contactcenter\' AND acl_account = \''.$ownerId.'\')';
+	    $shareds = Controller::service('PostgreSQL')->execResultSql($sql);
+
+	    //Verifica o acesso definido para o usuario logado
+	    $flagGroup = false;
+	    if (!empty($shareds) && $shareds){
+		foreach ($shareds as $s) {
+		    array_push($idS, $s['uidNumber']);
+		    $acl[$s['uidNumber']] = $this->decodeAcl(decbin($s['acl']));
+
+		    //verifica se o proprietario do grupo habilitou o acesso de leitura para o usuario logado
+		    if($s['uidNumber'] == $ownerId && $acl[$s['uidNumber']]['read']){
+			$flagGroup = true;
+		    }
+		}
+	    }
+
+	    //Se o grupo nao esta compartilhado
+	    if(!$flagGroup){
+		$this->createException($request, $response, Response::UNAUTHORIZED, 'unauthorized', 'Resource unauthorized.');
+		return $response;
+	    }
+
+	    //Obtem informacoes do proprietario do grupo
+	    $userOwner = Controller::read(
+					   array('concept' => 'user','service'=>'OpenLDAP'), 
+					   false, 
+					   array('filter' => array('=', 'id', $ownerId ), 'notExternal' => true)
+	    );
+
+	    if(is_array($userOwner)){
+		$userOwner = $userOwner[0];
+	    }
+
+	    //Recupera os grupos do usuario
+	    $groups = Controller::find(array('concept' => 'contactGroup'), false, array('filter' => array('=', 'user', $ownerId), 'order' => array('name')));
+
+	    if($groups){
+                foreach($groups[0]['contacts'] as $value){
+                        $d = new Data();
+                        $i = new Item($request->resources, 'ContactResource', $value['id']);
+
+                        $d->setName('name');
+                        $d->setValue($value['name']);
+                        $d->setPrompt('Nome do Grupo');
+                        $d->setDataType('string');
+                        $d->setMaxLength('100');
+                        $d->setMinLength(null);
+                        $d->setRequired(true);
+
+                        $i->addData($d);
+
+                        $d = new Data();
+                        $d->setName('id');
+                        $d->setValue($value['id']);
+                        $d->setPrompt('Id do Contato');
+                        $d->setDataType('string');
+                        $d->setMaxLength('100');
+                        $d->setMinLength(null);
+                        $d->setRequired(true);
+
+                        $i->addData($d);
+
+                        $d = new Data();
+                        $d->setName('email');
+                        $d->setValue($value['email']);
+                        $d->setPrompt('Email do Contato');
+                        $d->setDataType('string');
+                        $d->setMaxLength('100');
+                        $d->setMinLength(null);
+                        $d->setRequired(true);
+
+                        $i->addData($d);
+
+			//Define os link baseado nas permissoes de acesso
+			if(Config::me('uidNumber') != $value['user']){
+				/*Descomentar ao implementar os métodos
+				if($acl[$value['user']]['delete']){
+		                        $l = new Link();
+		                        $l->setHref('');
+        		                $l->setRel('delete');
+                		        $l->setAlt('Remover');
+	                	        $l->setPrompt('Remover');
+        	                	$l->setRender('link');
+	                	        $i->addLink($l);
+				}
+
+				if($acl[$value['user']]['update']){
+		                        $l = new Link();
+	        	                $l->setHref('');
+        	        	        $l->setRel('put');
+                	        	$l->setAlt('Atualizar');
+	                	        $l->setPrompt('Atualizar');
+        	                	$l->setRender('link');
+		                        $i->addLink($l);
+				}
+
+				if($acl[$value['user']]['write']){
+	        	                $l = new Link();
+        	                	$l->setHref('');
+                		        $l->setRel('post');
+	                	        $l->setAlt('Criar');
+        	                	$l->setPrompt('Criar novo');
+	                	        $l->setRender('link');
+        	                	$i->addLink($l);
+				}
+
+                                if($acl[$value['user']]['read']){
+                                        $l = new Link();
+                                        $l->setHref('');
+                                        $l->setRel('get');
+                                        $l->setAlt('Buscar');
+                                        $l->setPrompt('Buscar');
+                                        $l->setRender('link');
+                                        $i->addLink($l);
+                                }*/
+			}
+			else{
+                        	/*Descomentar ao implementar métodos no recurso
+	                        $l = new Link();
+	                        $l->setHref('');
+        	                $l->setRel('delete');
+                	        $l->setAlt('Remover');
+	                        $l->setPrompt('Remover');
+                        	$l->setRender('link');
+        	                $i->addLink($l);
+
+	                        $l = new Link();
+        	                $l->setHref('');
+                	        $l->setRel('put');
+                        	$l->setAlt('Atualizar');
+	                        $l->setPrompt('Atualizar');
+        	                $l->setRender('link');
+                	        $i->addLink($l);
+
+	                        $l = new Link();
+        	                $l->setHref('');
+                	        $l->setRel('get');
+                        	$l->setAlt('Buscar');
+	                        $l->setPrompt('Buscar');
+        	                $l->setRender('link');
+
+                	        $i->addLink($l);
+				*/
+			}
+                        $c->addItem($i);
+		}
+	    }
+
+	    if (!$groups) {
+		$this->createException($request, $response, Response::NOTFOUND, 'Bad request', 'Resource not found.');
+		return $response;
+	    }
+
+	    $t = new Template();
+            $d = new Data();
+
+            $d->setName('name');
+            $d->setValue(null);
+            $d->setPrompt('Nome do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('email');
+            $d->setValue(null);
+            $d->setPrompt('Email do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $d = new Data();
+            $d->setName('telefone');
+            $d->setValue(null);
+            $d->setPrompt('Telefone do Contato');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $t->addData($d);
+
+            $c->setTemplate($t);
+
+            $d = new Data();
+            $d->setName('id');
+            $d->setValue($groups[0]['id']);
+
+            $d->setPrompt('Id do Grupo');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('name');
+            $d->setValue($groups[0]['name']);
+            $d->setPrompt('Nome do Grupo');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('email');
+            $d->setValue($groups[0]['email']);
+            $d->setPrompt('Email do Grupo');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+            $d = new Data();
+            $d->setName('ownerId');
+            $d->setValue($userOwner['id']);
+            $d->setPrompt('Atributo UID (LDAP)');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+	    $c->addData($d);
+
+            $d = new Data();
+            $d->setName('ownerName');
+            $d->setValue($userOwner['name']);
+            $d->setPrompt('Atributo cn (LDAP)');
+            $d->setDataType('string');
+            $d->setMaxLength(100);
+            $d->setMinLength(null);
+            $d->setRequired(true);
+
+            $c->addData($d);
+
+
+            //Define os link baseado nas permissoes de acesso
+            if(Config::me('uidNumber') != $value['user']){
+                    /*Descomentar ao implementar os métodos
+                    if($acl[$value['user']]['delete']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('delete');
+                          $l->setAlt('Remover');
+                          $l->setPrompt('Remover');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }
+
+                    if($acl[$value['user']]['update']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('put');
+                          $l->setAlt('Atualizar');
+                          $l->setPrompt('Atualizar');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }
+
+                    if($acl[$value['user']]['write']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('post');
+                          $l->setAlt('Criar');
+                          $l->setPrompt('Criar novo');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }
+
+                    if($acl[$value['user']]['read']){
+                          $l = new Link();
+                          $l->setHref('');
+                          $l->setRel('get');
+                          $l->setAlt('Buscar');
+                          $l->setPrompt('Buscar');
+                          $l->setRender('link');
+                          $i->addLink($l);
+                    }*/
+            }
+            else{
+                    /*Descomentar ao implementar métodos no recurso
+                    $l = new Link();
+                    $l->setHref('');
+                    $l->setRel('delete');
+                    $l->setAlt('Remover');
+                    $l->setPrompt('Remover');
+                    $l->setRender('link');
+                    $i->addLink($l);
+
+                    $l = new Link();
+                    $l->setHref('');
+                    $l->setRel('put');
+                    $l->setAlt('Atualizar');
+                    $l->setPrompt('Atualizar');
+                    $l->setRender('link');
+                    $i->addLink($l);
+
+                    $l = new Link();
+                    $l->setHref('');
+                    $l->setRel('get');
+                    $l->setAlt('Buscar');
+                    $l->setPrompt('Buscar');
+                    $l->setRender('link');
+
+                    $i->addLink($l);
+                    */
+            }
+
+            $h->setCollection($c);
+
+	} catch (Exception $ex) {
+	    $this->createException($request, $response, Response::INTERNALSERVERERROR, 'Internal Server Error', $ex);
+	    return $response;
+	}
+
+	$response->body = $h->getHypermedia($request->accept[10][0]);
+	return $response;
+    }
+
+    function decodeAcl($bin) {
+
+	$acl = array();
+	$bin = str_split($bin);
+	$acl['read'] = (isset($bin[0]) && $bin[0] == 1) ? true : false;
+	$acl['write'] = (isset($bin[1]) && $bin[1] == 1) ? true : false;
+	$acl['update'] = (isset($bin[2]) && $bin[2] == 1) ? true : false;
+	$acl['delete'] = (isset($bin[3]) && $bin[3] == 1) ? true : false;
+
+	return $acl;
+    }
+
+    private function createException($request, &$response, $code, $title, $description) {
+	$response->code = $code;
+
+	$h = new Hypermedia();
+	$c = new Collection($request->resources, 'DynamicContactResource');
+	$e = new Error();
+
+	$e->setCode($code);
+	$e->setTitle($title);
+	$e->setDescription($description);
+
+	$c->setError($e);
+	$h->setCollection($c);
+
+	$response->body = $h->getHypermedia($request->accept[10][0]);
+    }
+}
+
+?>
Index: /trunk/prototype/rest/user/UsersResource.php
===================================================================
--- /trunk/prototype/rest/user/UsersResource.php	(revision 6543)
+++ /trunk/prototype/rest/user/UsersResource.php	(revision 6578)
@@ -30,5 +30,6 @@
 
 	$this->secured();
-	
+
+
 	try {	    
 	    //Executa uma consulta de usuários do LDAP a partir de um determinado atributo e valor
@@ -40,5 +41,9 @@
 		    //verifica se o campo(atributo) passado pelo usuário está definido no conceito 'user'
 		    if(isset($map[ $_GET['field'] ])){
-			    $users = Controller::find(array('concept' => 'user','service'=>'OpenLDAP'), false, array('filter' => array('=', $_GET['field'],$_GET['value'] )));
+			    $users = Controller::find(
+							array('concept' => 'user','service'=>'OpenLDAP'), 
+							false, 
+							array('filter' => array('=', $_GET['field'],$_GET['value'] ), 'notExternal' => true)
+			    );
 		    }
 		    else{
@@ -66,5 +71,11 @@
 	    else{
 		    //Executa a consulta dos primeiros 20 usuarios do LDAP
-		    $users = Controller::find(array('concept' => 'user','service'=>'OpenLDAP'), false, array('filter' => array('=', 'phpgwAccountType', 'u'),'limit'=>20));
+		    $users = Controller::find(
+						array('concept' => 'user','service'=>'OpenLDAP'), 
+						false, 
+						array('filter' => array('=', 'phpgwAccountType', 'u'),
+						      'limit' => 20,
+						      'notExternal' => true)
+		    );
 	    }
 
Index: /trunk/prototype/rest/user/UserResource.php
===================================================================
--- /trunk/prototype/rest/user/UserResource.php	(revision 6528)
+++ /trunk/prototype/rest/user/UserResource.php	(revision 6578)
@@ -31,5 +31,10 @@
 	    $this->secured();
 
-	    $user = Controller::find(array('concept' => 'user','service'=>'OpenLDAP'), false, array('filter' => array('=', 'uid', $id )));
+	    $user = Controller::find(
+					array('concept' => 'user','service'=>'OpenLDAP'), 
+					false, 
+					array('filter' => array('=', 'uid', $id ),
+					      'notExternal' => true)
+	    );
 
 	    //Se nao foi encontrado usuario na consulta
