Return-Path: Delivered-To: apmail-cxf-users-archive@www.apache.org Received: (qmail 77374 invoked from network); 26 Aug 2010 21:05:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 Aug 2010 21:05:49 -0000 Received: (qmail 26065 invoked by uid 500); 26 Aug 2010 21:05:49 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 25950 invoked by uid 500); 26 Aug 2010 21:05:48 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 25942 invoked by uid 99); 26 Aug 2010 21:05:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Aug 2010 21:05:48 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [64.85.173.253] (HELO server.dankulp.com) (64.85.173.253) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Aug 2010 21:05:42 +0000 Received: by server.dankulp.com (Postfix, from userid 5000) id A37F01863F1; Thu, 26 Aug 2010 17:05:21 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on server.dankulp.com X-Spam-Level: X-Msg-File: /tmp/mailfilter-users@cxf.apache.org.hcYVHFPyz4 Received: from dilbert.dankulp.com (c-24-91-72-253.hsd1.ma.comcast.net [24.91.72.253]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.dankulp.com (Postfix) with ESMTPSA id D00D01863E8; Thu, 26 Aug 2010 17:05:18 -0400 (EDT) From: Daniel Kulp To: users@cxf.apache.org Subject: Re: Moving from Axis to CXF Date: Thu, 26 Aug 2010 17:04:18 -0400 User-Agent: KMail/1.13.5 (Linux/2.6.35; KDE/4.4.5; x86_64; ; ) Cc: kettch References: <1282775096625-2653453.post@n5.nabble.com> In-Reply-To: <1282775096625-2653453.post@n5.nabble.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201008261704.18597.dkulp@apache.org> X-Old-Spam-Status: No, score=-2.8 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.1 MessageContext mc = context.getMessageContext(); Then one of: AuthorizationPolicy policy = (AuthorizationPolicy)mc.get(AuthorizationPolicy.class.getName()); or if you want to use JAX-WS standard calls: mc.getPrincipal() to get the User principal from the HTTP stack and pull the username and password from there. Dan On Wednesday 25 August 2010 6:24:56 pm kettch wrote: > I've got an Axis webservice that I've been charged with moving to CXF. > > The one thing that is confounding me is how to get the authentication info. > > For example, this is the existing snippet in the Axis version: > > MessageContext mc = MessageContext.getCurrentContext(); > try { > authenticator.authenticate(mc.getUsername(),mc.getPassword()); > ... > operation=mc.getOperation().getName(); > } catch(Exception e){ > logger.warn("User authentication error - " + mc.getUsername()); > throw new AxisFault(new QName(""),"User Authentication Error", > "getUser",new Element[]{}); > } > > Now as far as I've been able to find online, the "new" version should look > like: > > @Resource private WebServiceContext context; // In the class definition > .... > > MessageContext mc = context.getMessageContext(); > AuthorizationPolicy policy = > (AuthorizationPolicy)mc.get(AuthorizationPolicy.class); > try { > authenticator.authenticate(policy.getUsername(),policy.getPassword()); > ... > operation = ((QName)mc.get(Message.WSDL_OPERATION)).toString(); > } catch(Exception e){ > logger.warn("User authentication error - " + mc.getUsername()); > throw new AxisFault(new QName(""),"User Authentication Error", > "getUser",new Element[]{}); > } > > > But I am getting an exception thrown when getting the AuthorizationPolicy > like this: > > AuthorizationPolicy policy = > (AuthorizationPolicy)mc.get(AuthorizationPolicy.class); > > saying that "java.lang.Class cannot be cast to java.lang.String". > > All of the examples I've seen online have the exact same code...what am I > doing wrong? I'm new to CXF so I'm sure it's something stupid. I'm using > CXF 2.2.10. -- Daniel Kulp dkulp@apache.org http://dankulp.com/blog