Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E580C7F38 for ; Wed, 21 Dec 2011 21:54:32 +0000 (UTC) Received: (qmail 6173 invoked by uid 500); 21 Dec 2011 21:54:32 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 6112 invoked by uid 500); 21 Dec 2011 21:54:32 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 6097 invoked by uid 99); 21 Dec 2011 21:54:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2011 21:54:32 +0000 X-ASF-Spam-Status: No, hits=-1997.2 required=5.0 tests=ALL_TRUSTED,LOTTO_AGENT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Dec 2011 21:54:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id B4FD72388A64 for ; Wed, 21 Dec 2011 21:54:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1221896 [3/4] - in /cxf/sandbox/fediz: ./ fediz-core/ fediz-core/.settings/ fediz-core/src/ fediz-core/src/main/ fediz-core/src/main/java/ fediz-core/src/main/java/org/ fediz-core/src/main/java/org/apache/ fediz-core/src/main/java/org/apac... Date: Wed, 21 Dec 2011 21:54:04 -0000 To: commits@cxf.apache.org From: owulff@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111221215407.B4FD72388A64@eris.apache.org> Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/PasswordCallbackHandler.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/PasswordCallbackHandler.java?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/PasswordCallbackHandler.java (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/PasswordCallbackHandler.java Wed Dec 21 21:53:59 2011 @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cxf.fediz.service.sts; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; +import org.apache.ws.security.WSPasswordCallback; + +public class PasswordCallbackHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof WSPasswordCallback) { // CXF + WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; + if ("mystskey".equals(pc.getIdentifier())) { + pc.setPassword("stskpass"); + break; + } + } + } + } + +} Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/UsernamePasswordCallbackHandler.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/UsernamePasswordCallbackHandler.java?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/UsernamePasswordCallbackHandler.java (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/java/org/apache/cxf/fediz/service/sts/UsernamePasswordCallbackHandler.java Wed Dec 21 21:53:59 2011 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cxf.fediz.service.sts; + +import java.io.IOException; +import java.util.Map; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; +import org.apache.ws.security.WSPasswordCallback; + +public class UsernamePasswordCallbackHandler implements CallbackHandler { + + private Map passwords; + + public void setPasswords(Map passwords) { + this.passwords = passwords; + } + + public Map getPasswords() { + return passwords; + } + + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + + if (getPasswords() == null || getPasswords().size() == 0) + return; + + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof WSPasswordCallback) { // CXF + WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; + + String pw = getPasswords().get(pc.getIdentifier()); + pc.setPassword(pw); + } + } + } + + +} Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/log4j.properties URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/log4j.properties?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/log4j.properties (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/log4j.properties Wed Dec 21 21:53:59 2011 @@ -0,0 +1,17 @@ +# Set root category priority to INFO and its only appender to CONSOLE. +log4j.rootCategory=FATAL, CONSOLE +#log4j.rootCategory=DEBUG, CONSOLE + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=DEBUG +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n + +# LOGFILE is set to be a File appender using a PatternLayout. +log4j.appender.LOGFILE=org.apache.log4j.FileAppender +log4j.appender.LOGFILE.File=target/wss4j.log +log4j.appender.LOGFILE.Append=false +log4j.appender.LOGFILE.Threshold=DEBUG +log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout +log4j.appender.LOGFILE.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/logging.properties URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/logging.properties?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/logging.properties (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/logging.properties Wed Dec 21 21:53:59 2011 @@ -0,0 +1,52 @@ +############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ + +############################################################ +# Global properties +############################################################ + +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the WARNING and above levels. +handlers= java.util.logging.ConsoleHandler +#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler + +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overridden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +.level= INFO + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ + +# default file output is in user's home directory. +java.util.logging.FileHandler.pattern = %h/java%u.log +java.util.logging.FileHandler.limit = 50000 +java.util.logging.FileHandler.count = 1 +java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter + +# Limit the message that are printed on the console to WARNING and above. +java.util.logging.ConsoleHandler.level = INFO +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + + +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ + +# For example, set the com.xyz.foo logger to only log SEVERE +# messages: +#com.xyz.foo.level = SEVERE Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsKeystore.properties URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsKeystore.properties?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsKeystore.properties (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsKeystore.properties Wed Dec 21 21:53:59 2011 @@ -0,0 +1,6 @@ +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=stsspass +org.apache.ws.security.crypto.merlin.keystore.alias=mystskey +org.apache.ws.security.crypto.merlin.file=stsstore.jks + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsstore.jks URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsstore.jks?rev=1221896&view=auto ============================================================================== Binary file - no diff available. Propchange: cxf/sandbox/fediz/fediz-idp-sts/src/main/resources/stsstore.jks ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-encrypted-ut.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-encrypted-ut.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-encrypted-ut.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-encrypted-ut.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://localhost:8082/doubleit/services/doubleitasymmetricsaml1encrypted + + + + + + + + + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-servlet.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-servlet.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-servlet.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-servlet.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,32 @@ + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-transport.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-transport.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-transport.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-transport.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .* + https://localhost:(8081|8083)/doubleit/services/doubleittransport.* + + + + + + + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-ut.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-ut.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-ut.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-ut.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://localhost:(8080|8082)/doubleit/services/doubleit(UT|.*symmetric.*) + + + + + + + + + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-x509.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-x509.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-x509.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/cxf-x509.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://localhost:8082/doubleit/services/doubleitsymmetric.* + http://localhost:8082/doubleit/services/doubleitasymmetric.* + + + + + + + + + + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/passwords.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/passwords.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/passwords.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/passwords.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/userClaims.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/userClaims.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/userClaims.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/userClaims.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/web.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/web.xml (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/web.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,24 @@ + + + CXF STS + + sts + org.apache.cxf.transport.servlet.CXFServlet + + + config-location + WEB-INF/cxf-servlet.xml + + + + sts + /* + + + 60 + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4-service.wsdl URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4-service.wsdl?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4-service.wsdl (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4-service.wsdl Wed Dec 21 21:53:59 2011 @@ -0,0 +1,846 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4.wsdl URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4.wsdl?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4.wsdl (added) +++ cxf/sandbox/fediz/fediz-idp-sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4.wsdl Wed Dec 21 21:53:59 2011 @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/sandbox/fediz/fediz-idp/pom.xml URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp/pom.xml?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp/pom.xml (added) +++ cxf/sandbox/fediz/fediz-idp/pom.xml Wed Dec 21 21:53:59 2011 @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.cxf.fediz + fediz + 0.6-SNAPSHOT + + fediz-idp + WS Federation IDP + war + + + + + + + + 2.5.1 + UTF-8 + + + + + + javax.servlet + servlet-api + 2.5 + provided + + + org.slf4j + slf4j-api + 1.6.1 + + + org.slf4j + slf4j-jdk14 + 1.6.1 + + + org.apache.cxf + cxf-rt-ws-security + ${cxf.version} + + + org.apache.cxf + cxf-rt-transports-http + ${cxf.version} + + + org.apache.cxf + cxf-rt-ws-policy + ${cxf.version} + + + org.apache.commons + commons-lang3 + 3.0.1 + + + + + + + org.codehaus.mojo + tomcat-maven-plugin + 1.1 + + myTomcat + http://localhost:9080/manager/text + /${project.build.finalName} + + + + + fedizidp + + + Added: cxf/sandbox/fediz/fediz-idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java URL: http://svn.apache.org/viewvc/cxf/sandbox/fediz/fediz-idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java?rev=1221896&view=auto ============================================================================== --- cxf/sandbox/fediz/fediz-idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java (added) +++ cxf/sandbox/fediz/fediz-idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java Wed Dec 21 21:53:59 2011 @@ -0,0 +1,170 @@ +package org.apache.cxf.fediz.service.idp; + +import java.io.StringWriter; +import java.security.cert.X509Certificate; + +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.cxf.Bus; +import org.apache.cxf.binding.soap.SoapBindingConstants; +import org.apache.cxf.helpers.DOMUtils; +import org.apache.cxf.service.model.BindingOperationInfo; +import org.apache.cxf.staxutils.StaxUtils; +import org.apache.cxf.staxutils.W3CDOMStreamWriter; +import org.apache.cxf.ws.security.tokenstore.SecurityToken; +import org.apache.cxf.ws.security.trust.STSClient; +import org.apache.cxf.ws.security.trust.STSUtils; +import org.apache.ws.security.components.crypto.Crypto; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.Element; + +public class IdpSTSClient extends STSClient { + + private static Logger LOG = LoggerFactory.getLogger(IdpSTSClient.class); + + public IdpSTSClient(Bus b) { + super(b); + } + + + public String requestSecurityTokenResponse() throws Exception { + return requestSecurityTokenResponse(null); + } + + public String requestSecurityTokenResponse(String appliesTo) throws Exception { + String action = null; + if (isSecureConv) { + action = namespace + "/RST/SCT"; + } + return requestSecurityTokenResponse(appliesTo, action, "/Issue", null); + } + + public String requestSecurityTokenResponse(String appliesTo, String action, + String requestType, SecurityToken target) throws Exception { + createClient(); + BindingOperationInfo boi = findOperation("/RST/Issue"); + + client.getRequestContext().putAll(ctx); + if (action != null) { + client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action); + } else { + client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, + namespace + "/RST/Issue"); + } + + W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); + writer.writeStartElement("wst", "RequestSecurityToken", namespace); + writer.writeNamespace("wst", namespace); + if (context != null) { + writer.writeAttribute(null, "Context", context); + } + + boolean wroteKeySize = false; + String keyTypeTemplate = null; + String sptt = null; + + if (template != null) { + if (this.useSecondaryParameters()) { + writer.writeStartElement("wst", "SecondaryParameters", namespace); + } + + Element tl = DOMUtils.getFirstElement(template); + while (tl != null) { + StaxUtils.copy(tl, writer); + if ("KeyType".equals(tl.getLocalName())) { + keyTypeTemplate = DOMUtils.getContent(tl); + } else if ("KeySize".equals(tl.getLocalName())) { + wroteKeySize = true; + keySize = Integer.parseInt(DOMUtils.getContent(tl)); + } else if ("TokenType".equals(tl.getLocalName())) { + sptt = DOMUtils.getContent(tl); + } + tl = DOMUtils.getNextElement(tl); + } + + if (this.useSecondaryParameters()) { + writer.writeEndElement(); + } + } + + addRequestType(requestType, writer); + if (enableAppliesTo) { + addAppliesTo(writer, appliesTo); + } + + addClaims(writer); + + Element onBehalfOfToken = getOnBehalfOfToken(); + if (onBehalfOfToken != null) { + writer.writeStartElement("wst", "OnBehalfOf", namespace); + StaxUtils.copy(onBehalfOfToken, writer); + writer.writeEndElement(); + } + if (sptt == null) { + addTokenType(writer); + } + if (isSecureConv || enableLifetime) { + addLifetime(writer); + } + if (keyTypeTemplate == null) { + keyTypeTemplate = writeKeyType(writer, keyType); + } + + byte[] requestorEntropy = null; + X509Certificate cert = null; + Crypto crypto = null; + + if (keySize <= 0) { + keySize = 256; + } + if (keyTypeTemplate != null && keyTypeTemplate.endsWith("SymmetricKey")) { + requestorEntropy = writeElementsForRSTSymmetricKey(writer, wroteKeySize); + } else if (keyTypeTemplate != null && keyTypeTemplate.endsWith("PublicKey")) { + crypto = createCrypto(false); + cert = getCert(crypto); + writeElementsForRSTPublicKey(writer, cert); + } + + if (target != null) { + writer.writeStartElement("wst", "RenewTarget", namespace); + Element el = target.getUnattachedReference(); + if (el == null) { + el = target.getAttachedReference(); + } + StaxUtils.copy(el, writer); + writer.writeEndElement(); + } + + Element actAsSecurityToken = getActAsToken(); + if (actAsSecurityToken != null) { + writer.writeStartElement(STSUtils.WST_NS_08_02, "ActAs"); + StaxUtils.copy(actAsSecurityToken, writer); + writer.writeEndElement(); + } + + writer.writeEndElement(); + + Object obj[] = client.invoke(boi, new DOMSource(writer.getDocument() + .getDocumentElement())); + + DOMSource rstr = (DOMSource) obj[0]; + + StringWriter sw = new StringWriter(); + try { + Transformer t = TransformerFactory.newInstance().newTransformer(); + t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + t.transform(rstr, new StreamResult(sw)); + } catch (TransformerException te) { + LOG.warn("nodeToString Transformer Exception"); + } + return sw.toString(); + + } + +}