001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: AuthnSvcClient.java,v 1.2 2008/06/25 05:47:05 qcheng Exp $
026 * Portions Copyrighted 2014 ForgeRock AS.
027 */
028
029
030package com.sun.identity.liberty.ws.authnsvc;
031
032import java.util.List;
033import org.w3c.dom.Element;
034
035import com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse;
036import com.sun.identity.liberty.ws.authnsvc.protocol.SASLRequest;
037import com.sun.identity.liberty.ws.soapbinding.Client;
038import com.sun.identity.liberty.ws.soapbinding.Message;
039
040/**
041 * The <code>AuthnSvcClient</code> class provides web service clients with
042 * a method to <code>SASL</code> request to the Authentication Service and
043 * receive <code>SASL</code> response.
044 * @supported.all.api
045 * @deprecated since 12.0.0
046 */
047@Deprecated
048public class AuthnSvcClient {
049
050    /**
051     * Sends a <code>SASL</code> request to the Authentication Service SOAP
052     * endpoint and returns a <code>SASL</code> response.
053     *
054     * @param saslReq a <code>SASL</code> request
055     * @param connectTo the SOAP endpoint URL
056     * @return a <code>SASL</code> response from the Authentication Service
057     * @exception AuthnSvcException if authentication service is not available
058     *            or there is an error in <code>SASL</code> request
059     */
060    public static SASLResponse sendRequest(
061        SASLRequest saslReq,
062        String connectTo
063    ) throws AuthnSvcException {
064        Message req = new Message();
065        req.setSOAPBody(saslReq.toElement());
066        req.getCorrelationHeader()
067           .setRefToMessageID(saslReq.getRefToMessageID());
068
069        Message resp = null;
070        try {
071            resp = Client.sendRequest(req, connectTo);
072        } catch (Exception ex) {
073            AuthnSvcUtils.debug.error("AuthnSvcClient.sendRequest:", ex);
074            throw new AuthnSvcException(ex);  
075        }
076
077        List list = resp.getBodies(AuthnSvcConstants.NS_AUTHN_SVC,
078                                   AuthnSvcConstants.TAG_SASL_RESPONSE);
079        if (list.isEmpty()) {
080            throw new AuthnSvcException("missingSASLResponse");
081        } else if (list.size() > 1) {
082            throw new AuthnSvcException("tooManySASLResponse");
083        }
084
085        SASLResponse saslResp = new SASLResponse((Element)list.get(0));
086        saslResp.setMessageID(resp.getCorrelationHeader().getMessageID());
087        saslResp.setRefToMessageID(resp.getCorrelationHeader()
088                                       .getRefToMessageID());
089
090        return saslResp;
091    }
092}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.