Search in sources :

Example 11 with Response

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);
}
Also used : Constructor(java.lang.reflect.Constructor) L10NMessageImpl(com.sun.identity.shared.locale.L10NMessageImpl) Request(com.iplanet.services.comm.share.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) RemoteHttpServletRequest(org.forgerock.openam.authentication.service.protocol.RemoteHttpServletRequest) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) Document(org.w3c.dom.Document) URL(java.net.URL) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AMSecurityPropertiesException(com.sun.identity.security.AMSecurityPropertiesException) IOException(java.io.IOException) AuthException(com.sun.identity.authentication.service.AuthException) URLStreamHandler(java.net.URLStreamHandler) RemoteHttpServletResponse(org.forgerock.openam.authentication.service.protocol.RemoteHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) RequestSet(com.iplanet.services.comm.share.RequestSet) ByteArrayInputStream(java.io.ByteArrayInputStream) Vector(java.util.Vector)

Example 12 with Response

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;
}
Also used : NamingResponse(com.iplanet.services.naming.share.NamingResponse) Response(com.iplanet.services.comm.share.Response) SendRequestException(com.iplanet.services.comm.client.SendRequestException) NamingRequest(com.iplanet.services.naming.share.NamingRequest) RequestSet(com.iplanet.services.comm.share.RequestSet) Hashtable(java.util.Hashtable) Request(com.iplanet.services.comm.share.Request) NamingRequest(com.iplanet.services.naming.share.NamingRequest) NamingResponse(com.iplanet.services.naming.share.NamingResponse) Vector(java.util.Vector) SendRequestException(com.iplanet.services.comm.client.SendRequestException) MalformedURLException(java.net.MalformedURLException)

Example 13 with Response

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());
}
Also used : Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AuthException(com.sun.identity.authentication.service.AuthException) URL(java.net.URL) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AuthException(com.sun.identity.authentication.service.AuthException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) RequestSet(com.iplanet.services.comm.share.RequestSet) List(java.util.List) ArrayList(java.util.ArrayList) SessionID(com.iplanet.dpro.session.SessionID) Map(java.util.Map) HashMap(java.util.HashMap) Vector(java.util.Vector)

Example 14 with Response

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);
    }
}
Also used : Response(com.iplanet.services.comm.share.Response) RequestSet(com.iplanet.services.comm.share.RequestSet) HashMap(java.util.HashMap) Iterator(java.util.Iterator) AMLogException(com.sun.identity.log.AMLogException) Vector(java.util.Vector) URL(java.net.URL) AMLogException(com.sun.identity.log.AMLogException) ThreadPoolException(com.iplanet.am.util.ThreadPoolException) MalformedURLException(java.net.MalformedURLException) URLNotFoundException(com.iplanet.services.naming.URLNotFoundException)

Example 15 with Response

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;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.iplanet.services.comm.share.Response) SessionResponse(com.iplanet.dpro.session.share.SessionResponse) Request(com.iplanet.services.comm.share.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) ResponseSet(com.iplanet.services.comm.share.ResponseSet)

Aggregations

Response (com.iplanet.services.comm.share.Response)15 Request (com.iplanet.services.comm.share.Request)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 RequestSet (com.iplanet.services.comm.share.RequestSet)7 SSOException (com.iplanet.sso.SSOException)6 Vector (java.util.Vector)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 ResponseSet (com.iplanet.services.comm.share.ResponseSet)5 URL (java.net.URL)4 SessionException (com.iplanet.dpro.session.SessionException)3 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)3 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)3 SendRequestException (com.iplanet.services.comm.client.SendRequestException)3 NamingRequest (com.iplanet.services.naming.share.NamingRequest)3 NamingResponse (com.iplanet.services.naming.share.NamingResponse)3 SSOToken (com.iplanet.sso.SSOToken)3 SSOTokenManager (com.iplanet.sso.SSOTokenManager)3 MalformedURLException (java.net.MalformedURLException)3 SessionID (com.iplanet.dpro.session.SessionID)2 URLNotFoundException (com.iplanet.services.naming.URLNotFoundException)2