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: DSTRequestHandler.java,v 1.3 2008/06/25 05:47:14 qcheng Exp $ 026 * 027 */ 028 029package com.sun.identity.liberty.ws.dst.service; 030 031import com.sun.identity.liberty.ws.disco.jaxb.ResourceIDType; 032import com.sun.identity.liberty.ws.disco.jaxb.EncryptedResourceIDType; 033import com.sun.identity.liberty.ws.disco.EncryptedResourceID; 034import com.sun.identity.liberty.ws.dst.DSTUtils; 035import com.sun.identity.liberty.ws.soapbinding.SOAPFaultException; 036import com.sun.identity.liberty.ws.soapbinding.Message; 037import com.sun.identity.liberty.ws.soapbinding.RequestHandler; 038import com.sun.identity.liberty.ws.soapbinding.Utils; 039import com.sun.identity.liberty.ws.security.SecurityTokenManager; 040import com.sun.identity.liberty.ws.common.wsse.BinarySecurityToken; 041import com.sun.identity.liberty.ws.dst.DSTException; 042import com.sun.identity.liberty.ws.disco.common.DiscoUtils; 043import com.sun.identity.shared.xml.XMLUtils; 044import java.util.List; 045import java.util.ArrayList; 046import org.w3c.dom.Document; 047import org.w3c.dom.Node; 048 049/** 050 * The class <code>DSTRequestHandler</code> is a handler for processing 051 * Query or Modify Requests for any generic data service that are built 052 * using Liberty SIS specifications. This class includes common processing 053 * rules defined by Liberty DST specification, it is an extension point 054 * for any Liberty DST based web services. 055 * 056 * @supported.all.api 057 */ 058public abstract class DSTRequestHandler implements RequestHandler { 059 060 /** 061 * Default constructor 062 */ 063 protected DSTRequestHandler() {} 064 065 /** 066 * Processes the request for the given personal profile service request. 067 * @param msg SOAP Request message 068 * @return Message SOAP Response Message. 069 * @exception SOAPFaultException if the service requires an interaction. 070 * @exception Exception for any generic failure. 071 */ 072 public Message processRequest(Message msg) 073 throws SOAPFaultException, Exception { 074 075 if(DSTUtils.debug.messageEnabled()) { 076 DSTUtils.debug.message("DSTRequestHandler:processRequest:" + 077 "Request received: " + msg.toString()); 078 } 079 080 List requestBodies = msg.getBodies(); 081 requestBodies = Utils.convertElementToJAXB(requestBodies); 082 083 if(requestBodies == null || requestBodies.size() == 0) { 084 DSTUtils.debug.error("DSTRequestHandler:processRequest:"+ 085 "SOAPBodies are null"); 086 throw new Exception(DSTUtils.bundle.getString("nullInputParams")); 087 } 088 089 Message response = null; 090 int securityProfile = msg.getSecurityProfileType(); 091 if((securityProfile == Message.X509_TOKEN) || 092 (securityProfile == Message.SAML_TOKEN) || 093 (securityProfile == Message.BEARER_TOKEN)) { 094 response = new Message(null, generateBinarySecurityToken(msg)); 095 } else { 096 response = new Message(); 097 } 098 099 response.setCorrelationHeader(msg.getCorrelationHeader()); 100 101 response.setWSFVersion(msg.getWSFVersion()); 102 List responseBodies = processSOAPBodies(requestBodies, msg, response); 103 responseBodies = Utils.convertJAXBToElement(responseBodies); 104 105 response.setSOAPBodies(responseBodies); 106 if(DSTUtils.debug.messageEnabled()) { 107 DSTUtils.debug.message("DSTRequestHandler:processRequest:" + 108 "returned response: " + response.toString()); 109 } 110 return response; 111 } 112 113 /** 114 * Processes each SOAPBody. 115 * @param requestBodies list of request bodies 116 * @return List list of response bodies. 117 * @exception SOAPFaultException for the interaction queries. 118 * @exception DSTException for any failure. 119 */ 120 private List processSOAPBodies(List requestBodies, 121 Message msg, Message response) 122 throws SOAPFaultException, DSTException { 123 124 DSTUtils.debug.message("DSTRequestHandler:processSOAPBodies:Init"); 125 List responseBodies = new ArrayList(); 126 int size = requestBodies.size(); 127 for(int i=0; i < size; i++) { 128 Object request = requestBodies.get(i); 129 responseBodies.add(processDSTRequest(request, msg, response)); 130 } 131 return responseBodies; 132 } 133 134 /** 135 * Generates the binary security token if the security profile is X509. 136 * @param msg Request Message. 137 * @return BinarySecurityToken. 138 * @exception DSTException. 139 */ 140 private BinarySecurityToken generateBinarySecurityToken(Message msg) 141 throws DSTException { 142 try { 143 SecurityTokenManager manager = new SecurityTokenManager( 144 msg.getToken()); 145 BinarySecurityToken binaryToken = manager.getX509CertificateToken(); 146 binaryToken.setWSFVersion(msg.getWSFVersion()); 147 return binaryToken; 148 } catch (Exception e) { 149 DSTUtils.debug.error("DSTRequestHandler:generateBinary" + 150 "SecurityToken: Error in generating binary security token.", e); 151 throw new DSTException(e); 152 } 153 } 154 155 156 /** 157 * Processes query/modify request. 158 * @param request query or modify object. 159 * @param msg Request Message. 160 * @param response response Message. 161 * @return Object processed response object. 162 * @exception DSTException for failure. 163 * @exception SOAPFaultException for the interaction redirects 164 */ 165 public abstract Object processDSTRequest( 166 Object request, Message msg, Message response) 167 throws SOAPFaultException, DSTException; 168 169 /** 170 * Gets the Resource ID given in the Query or Modify Request. 171 * @param resourceIDType JAXB ResourceIDType Object. 172 * @param providerID Provider ID. 173 * @param serviceType Service Type. 174 * @return String resource id. 175 */ 176 protected String getResourceID( 177 Object resourceIDType, 178 String providerID, 179 String serviceType) { 180 181 DSTUtils.debug.message("PPRequestHandler:getResourceID:Init"); 182 183 if(resourceIDType == null) { 184 if(DSTUtils.debug.messageEnabled()) { 185 DSTUtils.debug.message("PPRequestHandler:getResourceID:" + 186 "ResourceIDType is null"); 187 } 188 return null; 189 } 190 191 if(resourceIDType instanceof ResourceIDType) { 192 ResourceIDType resID = (ResourceIDType)resourceIDType; 193 return resID.getValue(); 194 } else if( resourceIDType instanceof EncryptedResourceIDType) { 195 EncryptedResourceIDType encID = 196 (EncryptedResourceIDType)resourceIDType; 197 try { 198 Document encDoc = XMLUtils.newDocument(); 199 DiscoUtils.getDiscoMarshaller().marshal(encID, encDoc); 200 201 if(DSTUtils.debug.messageEnabled()) { 202 DSTUtils.debug.message("PPRequestHandler.getResourceID:" + 203 "Encrypted ResourceID = " + XMLUtils.print((Node)encDoc)); 204 } 205 206 EncryptedResourceID encryptedId = new EncryptedResourceID( 207 encDoc.getDocumentElement(), serviceType); 208 String resIDStr = EncryptedResourceID.getDecryptedResourceID( 209 encryptedId, providerID).getResourceID(); 210 211 if(DSTUtils.debug.messageEnabled()) { 212 DSTUtils.debug.message("PPRequestHandler.getResourceID: " + 213 "ResourceID Value after decryption" + resIDStr); 214 } 215 return resIDStr; 216 } catch (Exception ex) { 217 DSTUtils.debug.error("PPRequestHandler.getResourceID:error", ex); 218 return null; 219 } 220 } else { 221 DSTUtils.debug.error("PPRequestHandler:getResourceID:invalid" + 222 "resource ID type."); 223 return null; 224 } 225 226 } 227 /* 228 * Issue to be resolved: DST Schema does not have any name space associated 229 * with it. These schemas are included in each service schema., so that they 230 * would inherit the name spaces of respective processing service. 231 * Hence, DST JAXBElements have to be different for each data service. This 232 * issue might need to escalate to the JAXB team so that we should be able 233 * to specify the name space at runtime. 234 * Till then, we will have one request handler for each data service, other 235 * wise resolving imports is really difficult. 236 */ 237}
Copyright © 2010-2017, ForgeRock All Rights Reserved.