use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class AuthContext method processRequest.
protected Document processRequest(String xmlRequest) throws AuthLoginException {
Document doc = null;
try {
Request request = new Request(xmlRequest);
RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
set.addRequest(request);
URL url = authServiceURL;
if (url.getProtocol().equals("https") && (nickName != null)) {
Class[] paramtype = { String.class };
Object[] param = { nickName };
String protHandler = protHandlerPkg + ".https.Handler";
Constructor construct = Class.forName(protHandler).getConstructor(paramtype);
URLStreamHandler handler = (URLStreamHandler) construct.newInstance(param);
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), handler);
}
if (authDebug.messageEnabled()) {
authDebug.message("Service URL : " + url.toString());
}
Vector responses = PLLClient.send(url, set, cookieTable);
if ((responses.isEmpty()) || (responses.size() != 1)) {
throw new L10NMessageImpl(amAuthContext, "responseError", null);
}
Response res = (Response) responses.elementAt(0);
String responseStr = (String) res.getContent();
doc = XMLUtils.getXMLDocument(new ByteArrayInputStream(responseStr.getBytes("UTF-8")));
} catch (Exception e) {
authDebug.message("error in getting service url", e);
throw new AuthLoginException(amAuthContext, "xmlProcessError", null, e);
}
return (doc);
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class WebtopNaming method getNamingTable.
private static Hashtable getNamingTable(URL nameurl) throws Exception {
Hashtable nametbl = null;
NamingRequest nrequest = new NamingRequest(NamingRequest.reqVersion);
Request request = new Request(nrequest.toXMLString());
RequestSet set = new RequestSet(NAMING_SERVICE);
set.addRequest(request);
Vector responses = null;
try {
responses = PLLClient.send(nameurl, set);
if (responses.size() != 1) {
throw new Exception(NamingBundle.getString("unexpectedResponse"));
}
Response res = (Response) responses.elementAt(0);
NamingResponse nres = NamingResponse.parseXML(res.getContent());
if (nres.getException() != null) {
throw new Exception(nres.getException());
}
nametbl = nres.getNamingTable();
} catch (SendRequestException sre) {
debug.error("Naming service connection failed for " + nameurl, sre);
} catch (Exception e) {
debug.error("getNamingTable: ", e);
}
return nametbl;
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class AuthXMLHandler method processRequest.
/* process the request */
private Response processRequest(PLLAuditor auditor, Request req, HttpServletRequest servletReq, HttpServletResponse servletRes) {
// this call is to create a http session so that the JSESSIONID cookie
// is created. The appserver(8.1) load balancer plugin relies on the
// JSESSIONID cookie to set its JROUTE sticky cookie.
debug.message("=======================Entering processRequest");
servletReq.getSession(true);
String content = req.getContent();
AuthXMLResponse authResponse = null;
// Check for mis-routed requests
String cookieURL = null;
int index = content.indexOf(AuthXMLTags.AUTH_ID_HANDLE);
if (index != -1) {
// Check for mis-routed requests, get server URL for
// AuthIdentifier
int beginIndex = content.indexOf('"', index);
int endIndex = content.indexOf('"', beginIndex + 1);
String authIdentifier = content.substring(beginIndex + 1, endIndex);
if (debug.messageEnabled()) {
debug.message("authIdentifier = " + authIdentifier + "beginIndex = " + beginIndex + "endIndex =" + endIndex);
}
if (!authIdentifier.equals("0")) {
try {
SessionID sessionID = new SessionID(authIdentifier);
URL sessionServerURL = SESSION_SERVICE_URL_SERVICE.getSessionServiceURL(sessionID);
StringBuilder srtBuff = new StringBuilder(100);
srtBuff.append(sessionServerURL.getProtocol()).append("://").append(sessionServerURL.getHost()).append(":").append(Integer.toString(sessionServerURL.getPort())).append(serviceURI);
cookieURL = srtBuff.toString();
} catch (Exception exp) {
debug.error("Error in getting URL from session", exp);
cookieURL = null;
}
}
}
if ((cookieURL != null) && (cookieURL.trim().length() != 0) && !(AuthUtils.isLocalServer(cookieURL, serviceURI))) {
// Routing to the correct server, the looks like a mis-routed
// requested.
HashMap cookieTable = new HashMap();
Map headers = new HashMap();
Enumeration headerNames = servletReq.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
List headerValues = new ArrayList();
Enumeration enum1 = servletReq.getHeaders(headerName);
while (enum1.hasMoreElements()) {
headerValues.add(enum1.nextElement());
}
headers.put(headerName, headerValues);
}
if (debug.messageEnabled()) {
debug.message("Headers: " + headers);
}
PLLClient.parseCookies(headers, cookieTable);
if (debug.messageEnabled()) {
debug.message("Cookies: " + cookieTable);
}
RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
set.addRequest(req);
try {
Vector responses = PLLClient.send(new URL(cookieURL), set, cookieTable);
if (!responses.isEmpty()) {
auditor.auditAccessAttempt();
// Just record result as success here to avoid parsing response
auditor.auditAccessSuccess();
debug.message("=====================Returning redirected");
return ((Response) responses.elementAt(0));
}
} catch (Exception e) {
debug.error("Error in misrouted ", e);
// Attempt to contact server failed
authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
setErrorCode(authResponse, e);
auditor.auditAccessAttempt();
auditor.auditAccessFailure(authResponse.errorCode, authResponse.authErrorMessage);
return new Response(authResponse.toXMLString());
}
}
// Either local request or new request, handle it locally
try {
AuthXMLRequest sreq = AuthXMLRequest.parseXML(content, servletReq);
sreq.setHttpServletRequest(servletReq);
authResponse = processAuthXMLRequest(content, auditor, sreq, servletReq, servletRes);
} catch (AuthException e) {
debug.error("Got Auth Exception", e);
authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
authResponse.setErrorCode(e.getErrorCode());
} catch (Exception ex) {
debug.error("Error while processing xml request", ex);
authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
setErrorCode(authResponse, ex);
}
debug.message("=======================Returning");
if (authResponse.isException) {
auditor.auditAccessFailure(authResponse.errorCode, authResponse.authErrorMessage);
} else {
auditor.auditAccessSuccess();
}
return new Response(authResponse.toXMLString());
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class RemoteHandler method flush.
/**
* Flush any buffered output.
*/
public synchronized void flush() {
if (recCount <= 0) {
if (Debug.messageEnabled()) {
Debug.message("RemoteHandler.flush(): no records " + "in buffer to send");
}
return;
}
Vector responses = new Vector();
if (Debug.messageEnabled()) {
Debug.message("RemoteHandler.flush(): sending buffered records");
}
String thisAMException = null;
try {
Iterator sidIter = reqSetMap.keySet().iterator();
while (sidIter.hasNext()) {
String currentLoggedBySID = (String) sidIter.next();
URL logHostURL = getLogHostURL(currentLoggedBySID);
if (logHostURL == null) {
Debug.error("RemoteHandler.flush(): logHostURL is null");
this.recCount = 0;
reqSetMap = new HashMap();
return;
}
RequestSet reqSet = (RequestSet) reqSetMap.get(currentLoggedBySID);
responses = PLLClient.send(logHostURL, reqSet);
Iterator respIter = responses.iterator();
while (respIter.hasNext()) {
Response resp = (Response) respIter.next();
String respContent = resp.getContent();
if (!respContent.equals("OK")) {
Debug.error("RemoteHandler.flush(): " + respContent + " on remote machine");
if (thisAMException == null) {
thisAMException = "RemoteHandler.flush(): " + respContent + " on remote machine";
}
}
}
}
} catch (Exception e) {
Debug.error("RemoteHandler.flush(): ", e);
}
this.recCount = 0;
reqSetMap = new HashMap();
if (thisAMException != null) {
throw new AMLogException(thisAMException);
}
}
use of com.iplanet.services.comm.share.Response in project OpenAM by OpenRock.
the class SessionRequestHandler method process.
public ResponseSet process(PLLAuditor auditor, List<Request> requests, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext) {
ResponseSet rset = new ResponseSet(SessionService.SESSION_SERVICE);
auditor.setComponent(SESSION);
for (Request req : requests) {
Response res = processRequest(auditor, req, servletRequest, servletResponse);
rset.addResponse(res);
}
return rset;
}
Aggregations