I added a "domain" field to the CAS login page. For testing I used an input
text field in which the user had to specify a hardcoded value.
Now I want to replace the text field with a selection list (of domains) which
is put together when the user has entered his username and
leaves the username field (jquery onBlur). In the onBlur callback I want to
make a Ajax call to a servlet/controller/..
I tried with a servlet registered in web.xml which I first tried to run
directly in the address bar:
https://(machinename):11143/cas/domsecservice/userdomains?username=(username)&role=ROLE_DOMAIN_USER
However, this is always redirected to https://(machinename):11143/cas/login?...
I really don't know how to handle this. Do I have to create a mvc controller?
Do I have to add this to cas-servlet.xml or to web.xml? Or ...?
This is the controller I created but I do not how to access it in the Ajax call
or how to configure it.
------
package be.vlaamsbrabant.cas.extension.controllers;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import be.vlaamsbrabant.domainsecurity.DomainSecurityClient;
import be.vlaamsbrabant.domainsecurity.DomainSecurityClientFactory;
import be.vlaamsbrabant.domainsecurity.wsdl.DomainSecurityException;
@Controller
@RequestMapping(value = "/domsecservice")
public class DomainSecurityServiceController
{
// --------------------------------------------------------------------------
private static Logger logger =
Logger.getLogger(DomainSecurityServiceController.class);
// --------------------------------------------------------------------------
/**
* @param username
* @param role
* @return
*/
@RequestMapping(value = "/userdomains", method = RequestMethod.GET)
public @ResponseBody
String getDomainUsers(@RequestParam String username, @RequestParam String
role)
{
logger.debug("DomainSecurityServiceRequestor::getDomainUsers");
// if more than one role, they must be separated with a semicolon
String[] roles = role.split(";");
// get domains for given username and role from domain security web
service
// via client library
DomainSecurityClient dsClient = DomainSecurityClientFactory.getInstance();
Map<String, String> userDomains = new HashMap<String, String>();
try
{
for (String r : roles)
{
Map<String, String> retDomains = dsClient.getUserDomains(username,
r);
for (String dName : retDomains.keySet())
{
if (!userDomains.containsKey(dName)) userDomains.put(dName,
retDomains.get(dName));
}
}
}
catch (DomainSecurityException dse)
{
logger.error(dse);
}
// insert userDomains map in other map so that we have a "header" field
in the generated Json
Map<String, Map<String, String>> userDomainsWrapper = new HashMap<String,
Map<String, String>>();
userDomainsWrapper.put("domains", userDomains);
// build json representation of map with domain names and descriptions
ObjectMapper om = new ObjectMapper();
String userDomainsJson = null;
try
{
userDomainsJson = om.writeValueAsString(userDomainsWrapper);
}
catch (JsonGenerationException e)
{
logger.error(e);
}
catch (JsonMappingException e)
{
logger.error(e);
}
catch (IOException e)
{
logger.error(e);
}
logger.debug("userDomainsJson: " + userDomainsJson);
return userDomainsJson;
}
}
Guy Thomas
Analist-Programmeur
Dienst Projecten en Ontwikkelingen
Provinciehuis
Provincieplein 1
3010 Leuven
Tel: 016267945
--------------------------------------------------------------------------------
Aan dit bericht kunnen geen rechten worden ontleend. Alle berichten naar dit
professioneel e-mailadres kunnen door de werkgever gelezen worden. In het kader
van de vervulling van onze taak van openbaar belang nemen wij uw relevante
persoonlijke gegevens op in onze bestanden. U kunt deze inzien en verbeteren
conform de Wet Verwerking Persoonsgegevens van 8 december 1992.
Het ondernemingsnummer van het provinciebestuur is 0253.973.219
--
You are currently subscribed to [email protected] as:
[email protected]
To unsubscribe, change settings or access archives, see
http://www.ja-sig.org/wiki/display/JSG/cas-user