incubator-stonehenge-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chint...@apache.org
Subject svn commit: r884082 - in /incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services: TradeConfigServiceClient.java TradeServiceImpl.java
Date Wed, 25 Nov 2009 12:50:14 GMT
Author: chintana
Date: Wed Nov 25 12:50:14 2009
New Revision: 884082

URL: http://svn.apache.org/viewvc?rev=884082&view=rev
Log:
Getting profile ID from the token.

Modified:
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java
    incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java?rev=884082&r1=884081&r2=884082&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java
(original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeConfigServiceClient.java
Wed Nov 25 12:50:14 2009
@@ -23,12 +23,14 @@
 import java.util.Properties;
 
 import org.apache.axis2.context.MessageContext;
-import org.apache.stonehenge.stocktrader.config.Config_svcStub;
-import org.apache.stonehenge.stocktrader.config.xsd.BSConfigRequest;
+/*import org.apache.stonehenge.stocktrader.config.xsd.BSConfigRequest;
 import org.apache.stonehenge.stocktrader.config.xsd.BSConfigRequestE;
 import org.apache.stonehenge.stocktrader.config.xsd.BSConfigResponse;
-import org.apache.stonehenge.stocktrader.config.xsd.BSConfigResponseE;
+import org.apache.stonehenge.stocktrader.config.xsd.BSConfigResponseE;*/
 import org.apache.stonehenge.stocktrader.util.StockTraderUtility;
+import org.apache.stonehenge.stocktrader.config.ConfigServiceStub;
+import org.apache.stonehenge.stocktrader.config.trade_configservicedatacontract.*;
+import org.apache.stonehenge.stocktrader.config.trade.*;
 
 public class TradeConfigServiceClient {
 	private static final String SERVICE_URL = "org.apache.stonehenge.stocktrader.TradeConfigServiceClient.url";
@@ -52,7 +54,7 @@
 	}
 
 	public TradeOrderConfig getTradeOrderConfig() throws RemoteException {
-		Config_svcStub stub = new Config_svcStub(prop.getProperty(SERVICE_URL));
+		/*ConfigServiceStub stub = new ConfigServiceStub(prop.getProperty(SERVICE_URL));
 		BSConfigRequestE configRequestE = new BSConfigRequestE();
 		BSConfigRequest param = new BSConfigRequest();
 		param.setBS("WSAS_BS");
@@ -61,8 +63,20 @@
 		BSConfigResponse configResponse = configResponseE.getBSConfigResponse();
 		TradeOrderConfig config = new TradeOrderConfig();
 		config.setEndpointURL(configResponse.getOPS().toString());
-		config.setSecure(configResponse.getSec());
-		return config;
+		config.setSecure(configResponse.getSec());*/
+
+        ConfigServiceStub stub = new ConfigServiceStub(prop.getProperty(SERVICE_URL));
+        BSConfigRequest configRequest = new BSConfigRequest();
+        configRequest.setBSName("WSAS_BS");
+        GetBSConfig bsConfig = new GetBSConfig();
+        bsConfig.setBs(configRequest);
+        GetBSConfigResponse configResponse = stub.getBSConfig(bsConfig);
+        
+        TradeOrderConfig orderConfig = new TradeOrderConfig();
+        orderConfig.setEndpointURL(configResponse.getGetBSConfigResult().getOPS().toString());
+        orderConfig.setSecure(configResponse.getGetBSConfigResult().getSec());
+
+		return orderConfig;
 	}
 
 }

Modified: incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java?rev=884082&r1=884081&r2=884082&view=diff
==============================================================================
--- incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java
(original)
+++ incubator/stonehenge/trunk/stocktrader/wsas/business_service/src/org/apache/stonehenge/stocktrader/services/TradeServiceImpl.java
Wed Nov 25 12:50:14 2009
@@ -70,12 +70,117 @@
 import com.ibm.websphere.samples.trade.UpdateAccountProfileResponse;
 import com.ibm.websphere.samples.trade.GetProfileIdFromStsIdentifier;
 import com.ibm.websphere.samples.trade.GetProfileIdFromStsIdentifierResponse;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.HashMap;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axis2.context.MessageContext;
+import javax.xml.namespace.QName;
 
 public class TradeServiceImpl extends TradeServiceWcfSkeleton {
 	private static final Log logger = LogFactory.getLog(TradeServiceImpl.class);
 
 	private final TraderServiceManager mgr = new TraderServiceManager();
 
+    private static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
+    private static final String WSSE_LN = "Security";
+    private static final String ASSERTION_TOKEN_IN = "Assertion";
+    private static final String ATTRIBUTE_STATMENT_IN = "AttributeStatement";
+    private static final String ATTRIBUTE_IN = "Attribute";
+
+    private static final String ATTRIBUTE_NS = "AttributeNamespace";
+    private static final String ATTRIBUTE_VALUE = "AttributeValue";
+    private static final QName SEC_HEADER = new QName(WSSE_NS, WSSE_LN);
+    public final static String SAML10_NS = "urn:oasis:names:tc:SAML:1.0:assertion";
+    public final static String SAML11_NS = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1";
+    public final static String SAML20_NS = "urn:oasis:names:tc:SAML:2.0:assertion";
+
+    private String getProfileIdFromClaims() {
+        Map<String, String> attributes = null;
+        attributes = getSAMLAssertions(MessageContext.getCurrentMessageContext().getEnvelope());
+
+        if (attributes != null) {
+            for (String key : attributes.keySet()) {
+                if (key.equals("http://schemas.xmlsoap.org/ws/2005/05/identity/claims"))
{
+                    return attributes.get(key);
+                }
+            }
+        }
+
+        return null;
+    }
+
+    private Map<String, String> getSAMLAssertions(SOAPEnvelope envelope) {
+        SOAPHeaderBlock secHeader = null;
+        OMElement assertionToken = null;
+
+        secHeader = getSecHeader(envelope);
+        if (secHeader == null) {
+            return null;
+        }
+
+        String samlNameSpace = null;
+        assertionToken = secHeader.getFirstChildWithName(new QName(SAML10_NS, ASSERTION_TOKEN_IN));
+        if (assertionToken != null) {
+            samlNameSpace = SAML10_NS;
+        } else {
+            assertionToken = secHeader.getFirstChildWithName(new QName(SAML11_NS,
+                    ASSERTION_TOKEN_IN));
+            if (assertionToken != null) {
+                samlNameSpace = SAML11_NS;
+            } else {
+                assertionToken = secHeader.getFirstChildWithName(new QName(SAML20_NS,
+                        ASSERTION_TOKEN_IN));
+                if (assertionToken != null) {
+                    samlNameSpace = SAML20_NS;
+                }
+            }
+        }
+
+        if (samlNameSpace == null) {
+            logger.info("Unsupported SAML token type");
+            return null;
+        }
+
+        if (assertionToken != null) {
+            OMElement attributeStatementElem = assertionToken.getFirstChildWithName(new QName(
+                    samlNameSpace, ATTRIBUTE_STATMENT_IN));
+            if (attributeStatementElem != null) {
+                Iterator<OMElement> attributes = null;
+                attributes = attributeStatementElem.getChildrenWithName(new QName(samlNameSpace,
+                        ATTRIBUTE_IN));
+                if (attributes != null) {
+                    Map<String, String> attributeMap;
+                    attributeMap = new HashMap<String, String>();
+                    while (attributes.hasNext()) {
+                        OMElement attr = attributes.next();
+                        OMElement attrValElement = null;
+                        String attributeName = null;
+                        String attributeValue = null;
+                        attributeName = attr.getAttributeValue(new QName(ATTRIBUTE_NS));
+                        attrValElement = attr.getFirstChildWithName(new QName(samlNameSpace,
+                                ATTRIBUTE_VALUE));
+                        attributeValue = attrValElement.getText();
+                        attributeMap.put(attributeName, attributeValue);
+                    }
+                    return attributeMap;
+                }
+            }
+        }
+        return null;
+    }
+
+    private SOAPHeaderBlock getSecHeader(SOAPEnvelope envelope) {
+        SOAPHeader header = envelope.getHeader();
+        if (header != null) {
+            return (SOAPHeaderBlock) header.getFirstChildWithName(SEC_HEADER);
+        }
+        return null;
+    }
+
     public String getProfileIdFromStsIdentifier(String uniqueIdentifier, String issuingSts)
{
         // GetProfileIdFromStsIdentifierResponse pid_r = new GetProfileIdFromStsIdentifierResponse();
         String pid = null;
@@ -94,7 +199,11 @@
 	public BuyResponse buy(Buy buy) {
 		CustomOrderBean order;
 		try {
-			order = mgr.buy(buy.getUserID(), buy.getSymbol(), buy.getQuantity());
+            if (buy.getUserID() == null) {
+                order = mgr.buy(getProfileIdFromClaims(), buy.getSymbol(), buy.getQuantity());
+            } else {
+			    order = mgr.buy(buy.getUserID(), buy.getSymbol(), buy.getQuantity());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -107,7 +216,11 @@
 	public GetAccountDataResponse getAccountData(GetAccountData getAccountData) {
 		CustomAccountBean accountData;
 		try {
-			accountData = mgr.getAccountData(getAccountData.getUserID());
+            if (getAccountData.getUserID() == null) {
+                accountData = mgr.getAccountData(getProfileIdFromClaims());
+            } else {
+			    accountData = mgr.getAccountData(getAccountData.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -120,7 +233,11 @@
 	public GetAccountProfileDataResponse getAccountProfileData(GetAccountProfileData getAccountProfileData)
{
 		CustomAccountProfileBean accountProfileData;
 		try {
-			accountProfileData = mgr.getAccountProfileData(getAccountProfileData.getUserID());
+            if (getAccountProfileData.getUserID() == null) {
+                accountProfileData = mgr.getAccountProfileData(getProfileIdFromClaims());
+            } else {
+			    accountProfileData = mgr.getAccountProfileData(getAccountProfileData.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -133,7 +250,11 @@
 	public GetClosedOrdersResponse getClosedOrders(GetClosedOrders getClosedOrders) {
 		List<CustomOrderBean> closedOrders;
 		try {
-			closedOrders = mgr.getClosedOrders(getClosedOrders.getUserID());
+            if (getClosedOrders.getUserID() == null) {
+                closedOrders = mgr.getClosedOrders(getProfileIdFromClaims());
+            } else {
+			    closedOrders = mgr.getClosedOrders(getClosedOrders.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -148,7 +269,11 @@
 	public GetHoldingResponse getHolding(GetHolding getHolding) {
 		CustomHoldingBean holding;
 		try {
-			holding = mgr.getHolding(getHolding.getUserID(), getHolding.getHoldingID());
+            if (getHolding.getUserID() == null) {
+                holding = mgr.getHolding(getProfileIdFromClaims(), getHolding.getHoldingID());
+            } else {
+			    holding = mgr.getHolding(getHolding.getUserID(), getHolding.getHoldingID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -161,7 +286,11 @@
 	public GetHoldingsResponse getHoldings(GetHoldings getHoldings) {
 		List<CustomHoldingBean> holdingBeans;
 		try {
-			holdingBeans = mgr.getHoldings(getHoldings.getUserID());
+            if (getHoldings.getUserID() == null) {
+                holdingBeans = mgr.getHoldings(getProfileIdFromClaims());
+            } else {
+			    holdingBeans = mgr.getHoldings(getHoldings.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -189,7 +318,11 @@
 	public GetOrdersResponse getOrders(GetOrders getOrders) {
 		List<CustomOrderBean> orders;
 		try {
-			orders = mgr.getOrders(getOrders.getUserID());
+            if (getOrders.getUserID() == null) {
+                orders = mgr.getOrders(getProfileIdFromClaims());
+            } else {
+			    orders = mgr.getOrders(getOrders.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -217,7 +350,11 @@
 	public GetTopOrdersResponse getTopOrders(GetTopOrders getTopOrders) {
 		List<CustomOrderBean> topOrders;
 		try {
-			topOrders = mgr.getTopOrders(getTopOrders.getUserID());
+            if (getTopOrders.getUserID() == null) {
+                topOrders = mgr.getTopOrders(getProfileIdFromClaims());
+            } else {
+			    topOrders = mgr.getTopOrders(getTopOrders.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -238,7 +375,11 @@
 	public LoginResponse login(Login login) {
 		CustomAccountBean param;
 		try {
-			param = mgr.login(login.getUserID(), login.getPassword());
+            if (login.getUserID() == null) {
+                param = mgr.login(getProfileIdFromClaims(), login.getPassword());
+            } else {
+			    param = mgr.login(login.getUserID(), login.getPassword());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -250,7 +391,11 @@
 
 	public LogoutResponse logout(Logout logout) {
 		try {
-			mgr.logout(logout.getUserID());
+            if (logout.getUserID() == null) {
+                mgr.logout(getProfileIdFromClaims());
+            } else {
+			    mgr.logout(logout.getUserID());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -262,8 +407,10 @@
 	public RegisterResponse register(Register register) {
 		CustomAccountBean param;
 		try {
+            String userId = (register.getUserID() == null) ? getProfileIdFromClaims()
+                                                            : register.getUserID();
 			param = mgr.register(
-                    register.getUserID(),
+                    userId,
                     register.getPassword(),
 					register.getFullname(),
                     register.getAddress(),
@@ -282,7 +429,11 @@
 	public SellResponse sell(Sell sell) {
 		CustomOrderBean param;
 		try {
-			param = mgr.sell(sell.getUserID(), sell.getHoldingID(), sell.getOrderProcessingMode());
+            if (sell.getUserID() == null) {
+                param = mgr.sell(getProfileIdFromClaims(), sell.getHoldingID(), sell.getOrderProcessingMode());
+            } else {
+			    param = mgr.sell(sell.getUserID(), sell.getHoldingID(), sell.getOrderProcessingMode());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);
@@ -295,7 +446,11 @@
 	public SellEnhancedResponse sellEnhanced(SellEnhanced sellEnhanced) {
 		CustomOrderBean param;
 		try {
-			param = mgr.sellEnhanced(sellEnhanced.getUserID(), sellEnhanced.getHoldingID(), sellEnhanced.getQuantity());
+            if (sellEnhanced.getUserID() == null) {
+                param = mgr.sellEnhanced(getProfileIdFromClaims(), sellEnhanced.getHoldingID(),
sellEnhanced.getQuantity());
+            } else {
+			    param = mgr.sellEnhanced(sellEnhanced.getUserID(), sellEnhanced.getHoldingID(), sellEnhanced.getQuantity());
+            }
 		} catch (DAOException e) {
 			logger.debug("", e);
 			throw new RuntimeException(e);



Mime
View raw message