Modified: cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/XMLUtils.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/XMLUtils.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/XMLUtils.java (original) +++ cxf/fediz/trunk/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/XMLUtils.java Wed May 16 21:29:53 2012 @@ -1,18 +1,20 @@ -/* - * 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. +/** + * 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.core.util; @@ -70,10 +72,10 @@ public final class XMLUtils { // private static final Logger LOG = LogUtils.getL7dLogger(XMLUtils.class); private static final Map<ClassLoader, DocumentBuilderFactory> DOCUMENT_BUILDER_FACTORIES = Collections - .synchronizedMap(new WeakHashMap<ClassLoader, DocumentBuilderFactory>()); + .synchronizedMap(new WeakHashMap<ClassLoader, DocumentBuilderFactory>()); private static final Map<ClassLoader, TransformerFactory> TRANSFORMER_FACTORIES = Collections - .synchronizedMap(new WeakHashMap<ClassLoader, TransformerFactory>()); + .synchronizedMap(new WeakHashMap<ClassLoader, TransformerFactory>()); private XMLUtils() { } @@ -111,13 +113,11 @@ public final class XMLUtils { return factory; } - public static Transformer newTransformer() - throws TransformerConfigurationException { + public static Transformer newTransformer() throws TransformerConfigurationException { return getTransformerFactory().newTransformer(); } - public static Transformer newTransformer(int indent) - throws TransformerConfigurationException { + public static Transformer newTransformer(int indent) throws TransformerConfigurationException { if (indent > 0) { TransformerFactory f = TransformerFactory.newInstance(); try { @@ -131,33 +131,29 @@ public final class XMLUtils { return getTransformerFactory().newTransformer(); } - public static DocumentBuilder getParser() - throws ParserConfigurationException { + public static DocumentBuilder getParser() throws ParserConfigurationException { return getDocumentBuilderFactory().newDocumentBuilder(); } - public static Document parse(InputSource is) - throws ParserConfigurationException, SAXException, IOException { + public static Document parse(InputSource is) throws ParserConfigurationException, SAXException, + IOException { return getParser().parse(is); } - public static Document parse(File is) throws ParserConfigurationException, - SAXException, IOException { + public static Document parse(File is) throws ParserConfigurationException, SAXException, IOException { return getParser().parse(is); } - public static Document parse(InputStream in) - throws ParserConfigurationException, SAXException, IOException { + public static Document parse(InputStream in) throws ParserConfigurationException, SAXException, + IOException { return getParser().parse(in); } - public static Document parse(String in) - throws ParserConfigurationException, SAXException, IOException { + public static Document parse(String in) throws ParserConfigurationException, SAXException, IOException { return parse(in.getBytes()); } - public static Document parse(byte[] in) - throws ParserConfigurationException, SAXException, IOException { + public static Document parse(byte[] in) throws ParserConfigurationException, SAXException, IOException { if (in == null) { return null; } @@ -194,10 +190,9 @@ public final class XMLUtils { public static void writeTo(Source src, OutputStream os, int indent) { String enc = null; - if (src instanceof DOMSource - && ((DOMSource) src).getNode() instanceof Document) { + if (src instanceof DOMSource && ((DOMSource)src).getNode() instanceof Document) { try { - enc = ((Document) ((DOMSource) src).getNode()).getXmlEncoding(); + enc = ((Document)((DOMSource)src).getNode()).getXmlEncoding(); } catch (Exception ex) { // ignore - not DOM level 3 } @@ -207,10 +202,9 @@ public final class XMLUtils { public static void writeTo(Source src, Writer os, int indent) { String enc = null; - if (src instanceof DOMSource - && ((DOMSource) src).getNode() instanceof Document) { + if (src instanceof DOMSource && ((DOMSource)src).getNode() instanceof Document) { try { - enc = ((Document) ((DOMSource) src).getNode()).getXmlEncoding(); + enc = ((Document)((DOMSource)src).getNode()).getXmlEncoding(); } catch (Exception ex) { // ignore - not DOM level 3 } @@ -218,8 +212,7 @@ public final class XMLUtils { writeTo(src, os, indent, enc, "no"); } - public static void writeTo(Source src, OutputStream os, int indent, - String charset, String omitXmlDecl) { + public static void writeTo(Source src, OutputStream os, int indent, String charset, String omitXmlDecl) { Transformer it; try { if (StringUtils.isEmpty(charset)) { @@ -230,9 +223,7 @@ public final class XMLUtils { it.setOutputProperty(OutputKeys.METHOD, "xml"); if (indent > -1) { it.setOutputProperty(OutputKeys.INDENT, "yes"); - it.setOutputProperty( - "{http://xml.apache.org/xslt}indent-amount", - Integer.toString(indent)); + it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent)); } it.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDecl); it.setOutputProperty(OutputKeys.ENCODING, charset); @@ -242,8 +233,7 @@ public final class XMLUtils { } } - public static void writeTo(Source src, Writer os, int indent, - String charset, String omitXmlDecl) { + public static void writeTo(Source src, Writer os, int indent, String charset, String omitXmlDecl) { Transformer it; try { if (StringUtils.isEmpty(charset)) { @@ -254,9 +244,7 @@ public final class XMLUtils { it.setOutputProperty(OutputKeys.METHOD, "xml"); if (indent > -1) { it.setOutputProperty(OutputKeys.INDENT, "yes"); - it.setOutputProperty( - "{http://xml.apache.org/xslt}indent-amount", - Integer.toString(indent)); + it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", Integer.toString(indent)); } it.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDecl); it.setOutputProperty(OutputKeys.ENCODING, charset); @@ -266,13 +254,11 @@ public final class XMLUtils { } } - public static String toString(Source source) throws TransformerException, - IOException { + public static String toString(Source source) throws TransformerException, IOException { return toString(source, null); } - public static String toString(Source source, Properties props) - throws TransformerException, IOException { + public static String toString(Source source, Properties props) throws TransformerException, IOException { StringWriter bos = new StringWriter(); StreamResult sr = new StreamResult(bos); Transformer trans = newTransformer(); @@ -311,8 +297,7 @@ public final class XMLUtils { return el.getAttributeNode(attrName); } - public static void replaceAttribute(Element element, String attr, - String value) { + public static void replaceAttribute(Element element, String attr, String value) { if (element.hasAttribute(attr)) { element.removeAttribute(attr); } @@ -334,13 +319,12 @@ public final class XMLUtils { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); - System.err.println("## prefix=" + node.getPrefix() + " localname:" - + node.getLocalName() + " value=" + node.getNodeValue()); + System.err.println("## prefix=" + node.getPrefix() + " localname:" + node.getLocalName() + + " value=" + node.getNodeValue()); } } - public static QName getNamespace(Map<String, String> namespaces, - String str, String defaultNamespace) { + public static QName getNamespace(Map<String, String> namespaces, String str, String defaultNamespace) { String prefix = null; String localName = null; @@ -354,7 +338,7 @@ public final class XMLUtils { String namespceURI = defaultNamespace; if (prefix != null) { - namespceURI = (String) namespaces.get(prefix); + namespceURI = (String)namespaces.get(prefix); } return new QName(namespceURI, localName); } @@ -365,8 +349,7 @@ public final class XMLUtils { it.setOutputProperty(OutputKeys.METHOD, "xml"); it.setOutputProperty(OutputKeys.INDENT, "yes"); - it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", - "2"); + it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); it.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); it.transform(new DOMSource(element), new StreamResult(writer)); } catch (Exception e) { @@ -375,17 +358,14 @@ public final class XMLUtils { } public static Element createElementNS(Node node, QName name) { - return createElementNS(node.getOwnerDocument(), name.getNamespaceURI(), - name.getLocalPart()); + return createElementNS(node.getOwnerDocument(), name.getNamespaceURI(), name.getLocalPart()); } public static Element createElementNS(Document root, QName name) { - return createElementNS(root, name.getNamespaceURI(), - name.getLocalPart()); + return createElementNS(root, name.getNamespaceURI(), name.getLocalPart()); } - public static Element createElementNS(Document root, String namespaceURI, - String qualifiedName) { + public static Element createElementNS(Document root, String namespaceURI, String qualifiedName) { return root.createElementNS(namespaceURI, qualifiedName); } @@ -411,17 +391,15 @@ public final class XMLUtils { // Try to get the DOMImplementation from doc first before // defaulting to the sun implementation. if (docImpl != null && docImpl.hasFeature("LS", "3.0")) { - impl = (DOMImplementationLS) docImpl.getFeature("LS", "3.0"); + impl = (DOMImplementationLS)docImpl.getFeature("LS", "3.0"); } else { - DOMImplementationRegistry registry = DOMImplementationRegistry - .newInstance(); - impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); if (impl == null) { System.setProperty(DOMImplementationRegistry.PROPERTY, - "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); + "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); registry = DOMImplementationRegistry.newInstance(); - impl = (DOMImplementationLS) registry - .getDOMImplementation("LS"); + impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); } } LSOutput output = impl.createLSOutput(); @@ -433,11 +411,9 @@ public final class XMLUtils { return new ByteArrayInputStream(buf); } - public static Element fetchElementByNameAttribute(Element parent, - String targetName, String nameValue) { + public static Element fetchElementByNameAttribute(Element parent, String targetName, String nameValue) { - List<Element> elemList = DOMUtils.findAllElementsByTagName(parent, - targetName); + List<Element> elemList = DOMUtils.findAllElementsByTagName(parent, targetName); for (Element elem : elemList) { if (elem.getAttribute("name").equals(nameValue)) { return elem;
Modified: cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/FederationProcessorTest.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/FederationProcessorTest.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/FederationProcessorTest.java (original) +++ cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/FederationProcessorTest.java Wed May 16 21:29:53 2012 @@ -1,18 +1,20 @@ -/* - * 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. +/** + * 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.core; @@ -38,7 +40,7 @@ public class FederationProcessorTest { private static final String CONFIG_FILE = "fediz_test_config.xml"; private static final String CONFIG_FILE_WRONG_ISSUER = "fediz_test_config2.xml"; - private static String sRSTR = null; + private static String sRSTR; @BeforeClass public static void readWResult() { Modified: cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java (original) +++ cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java Wed May 16 21:29:53 2012 @@ -1,3 +1,22 @@ +/** + * 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.core.config; import java.io.File; @@ -62,6 +81,7 @@ public class FedizConfigurationTest { private static final String CONFIG_FILE = "./target/fedizconfig.xml"; + //CHECKSTYLE:OFF private FedizConfig createConfiguration() throws JAXBException { FedizConfig rootConfig = new FedizConfig(); Modified: cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java (original) +++ cxf/fediz/trunk/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java Wed May 16 21:29:53 2012 @@ -1,3 +1,22 @@ +/** + * 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.core.config; import java.io.File; @@ -56,6 +75,7 @@ public class FedizConfigurationWriterTes private static final String CONFIG_FILE = "./target/fediz_test_config.xml"; + //CHECKSTYLE:OFF private FedizConfig createConfiguration() throws JAXBException { FedizConfig rootConfig = new FedizConfig(); @@ -64,18 +84,6 @@ public class FedizConfigurationWriterTes config.setName(CONFIG_NAME); config.setMaximumClockSkew(new BigInteger(CLOCK_SKEW)); - //config.setCertificateValidation(ValidationType.CHAIN_TRUST); - - // TrustManagersType tm0 = new TrustManagersType(); - // - // KeyStoreType ks0 = new KeyStoreType(); - // ks0.setType(FILE_TYPE); - // ks0.setPassword(KEYSTORE_PASSWORD); - // ks0.setFile(KEYSTORE_FILE); - // - // tm0.setKeyStore(ks0); - // - // config.setServiceCertificate(tm0); FederationProtocolType protocol = new FederationProtocolType(); config.setProtocol(protocol); @@ -198,8 +206,7 @@ public class FedizConfigurationWriterTes AudienceUris audience = config.getAudienceUris(); Assert.assertEquals(1, audience.getAudienceItem().size()); Assert.assertTrue(config.getProtocol() instanceof FederationProtocolType); - FederationProtocolType fp = (FederationProtocolType) config - .getProtocol(); + FederationProtocolType fp = (FederationProtocolType)config.getProtocol(); Assert.assertEquals(HOME_REALM_CLASS, fp.getHomeRealm().getValue()); //Assert.assertEquals(config.getCertificateValidation(),ValidationType.CHAIN_TRUST); @@ -211,24 +218,24 @@ public class FedizConfigurationWriterTes Protocol protocol = fedContext.getProtocol(); Assert.assertTrue(protocol instanceof FederationProtocol); FederationProtocol fedProtocol = (FederationProtocol) protocol; - Assert.assertEquals(TARGET_REALM,fedProtocol.getRealm()); + Assert.assertEquals(TARGET_REALM, fedProtocol.getRealm()); Authentication auth = fedProtocol.getAuthenticationType(); - Assert.assertEquals(auth.getType(),PropertyType.STRING); - Assert.assertEquals(auth.getValue(),AUTH_TYPE_VALUE); + Assert.assertEquals(auth.getType(), PropertyType.STRING); + Assert.assertEquals(auth.getValue(), AUTH_TYPE_VALUE); //Assert.assertEquals(ValidationMethod.CHAIN_TRUST, fedContext.getCertificateValidation()); List<String> audienceUris = fedContext.getAudienceUris(); - Assert.assertEquals(1,audienceUris.size()); + Assert.assertEquals(1, audienceUris.size()); List<TrustedIssuer> trustedIssuers = fedContext.getTrustedIssuers(); - Assert.assertEquals(1,trustedIssuers.size()); + Assert.assertEquals(1, trustedIssuers.size()); TrustedIssuer issuer = trustedIssuers.get(0); Assert.assertEquals(TRUST_ISSUER_NAME, issuer.getName()); Assert.assertEquals(CertificateValidationMethod.CHAIN_TRUST, issuer.getCertificateValidationMethod()); Assert.assertEquals(TRUST_ISSUER_CERT_CONSTRAINT, issuer.getSubject()); List<TrustManager> trustManagers = fedContext.getCertificateStores(); - Assert.assertEquals(1,trustManagers.size()); + Assert.assertEquals(1, trustManagers.size()); TrustManager manager = trustManagers.get(0); KeyStore keyStore = manager.getKeyStore(); Assert.assertEquals(JKS_TYPE, keyStore.getType()); Modified: cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationAuthenticator.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationAuthenticator.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationAuthenticator.java (original) +++ cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationAuthenticator.java Wed May 16 21:29:53 2012 @@ -1,19 +1,22 @@ -/* - * 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. +/** + * 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.tomcat; import java.io.File; @@ -36,7 +39,6 @@ import org.apache.catalina.authenticator import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; import org.apache.catalina.deploy.LoginConfig; -import org.apache.cxf.fediz.core.Claim; import org.apache.cxf.fediz.core.FederationConstants; import org.apache.cxf.fediz.core.FederationProcessor; import org.apache.cxf.fediz.core.FederationProcessorImpl; @@ -49,31 +51,26 @@ import org.apache.juli.logging.LogFactor public class FederationAuthenticator extends FormAuthenticator { - // [TODO] Expired token - - private static final Log log = LogFactory.getLog(FormAuthenticator.class); - + public static final String FEDERATION_NOTE = "org.apache.cxf.fediz.tomcat.FEDERATION"; + public static final String SECURITY_TOKEN = "org.apache.fediz.SECURITY_TOKEN"; + /** * Descriptive information about this implementation. */ - protected static final String info = "org.apache.cxf.fediz.tomcat.WsFedAuthenticator/1.0"; - - public static final String FEDERATION_NOTE = "org.apache.cxf.fediz.tomcat.FEDERATION"; - - public static final String SECURITY_TOKEN = "org.apache.fediz.SECURITY_TOKEN"; - + protected static final String INFO = "org.apache.cxf.fediz.tomcat.WsFedAuthenticator/1.0"; protected static final String TRUSTED_ISSUER = "org.apache.cxf.fediz.tomcat.TRUSTED_ISSUER"; + private static final Log LOG = LogFactory.getLog(FormAuthenticator.class); /** * Fediz Configuration file */ - protected String configFile = null; + protected String configFile; - private FederationConfigurator configurator = null; + private FederationConfigurator configurator; public FederationAuthenticator() { - log.debug("WsFedAuthenticator()"); + LOG.debug("WsFedAuthenticator()"); } /** @@ -81,7 +78,7 @@ public class FederationAuthenticator ext */ @Override public String getInfo() { - return (info); + return INFO; } public String getConfigFile() { @@ -105,7 +102,7 @@ public class FederationAuthenticator ext } configurator = new FederationConfigurator(); configurator.loadConfig(f); - log.debug("Fediz configuration read from " + f.getAbsolutePath()); + LOG.debug("Fediz configuration read from " + f.getAbsolutePath()); } catch (JAXBException e) { throw new LifecycleException("Failed to load Fediz configuration", e); @@ -133,16 +130,17 @@ public class FederationAuthenticator ext public void invoke(Request request, Response response) throws IOException, ServletException { - log.debug("WsFedAuthenticator:invoke()"); + LOG.debug("WsFedAuthenticator:invoke()"); super.invoke(request, response); } + //CHECKSTYLE:OFF @Override public boolean authenticate(Request request, HttpServletResponse response, LoginConfig config) throws IOException { - log.debug("authenticate invoked"); + LOG.debug("authenticate invoked"); // References to objects we will need later Session session = null; @@ -150,8 +148,9 @@ public class FederationAuthenticator ext Principal principal = request.getUserPrincipal(); // String ssoId = (String) request.getNote(Constants.REQ_SSOID_NOTE); if (principal != null) { - if (log.isDebugEnabled()) - log.debug("Already authenticated '" + principal.getName() + "'"); + if (LOG.isDebugEnabled()) { + LOG.debug("Already authenticated '" + principal.getName() + "'"); + } // Associate the session with any existing SSO session /* * if (ssoId != null) associate(ssoId, @@ -161,67 +160,69 @@ public class FederationAuthenticator ext // Check whether security token still valid session = request.getSessionInternal(); if (session == null) { - log.debug("Session should not be null after authentication"); + LOG.debug("Session should not be null after authentication"); } else { - FederationResponse wfRes = (FederationResponse) session - .getNote(FEDERATION_NOTE); + FederationResponse wfRes = (FederationResponse)session.getNote(FEDERATION_NOTE); Date tokenExpires = wfRes.getTokenExpires(); if (tokenExpires == null) { - log.debug("Token doesn't expire"); - return (true); + LOG.debug("Token doesn't expire"); + return true; } Calendar cal = Calendar.getInstance(); if (cal.getTime().after(wfRes.getTokenExpires())) { - log.debug("Token already expired. Clean up and redirect"); + LOG.debug("Token already expired. Clean up and redirect"); session.removeNote(FEDERATION_NOTE); session.removeNote(Constants.FORM_PRINCIPAL_NOTE); session.setPrincipal(null); request.getSession().removeAttribute(SECURITY_TOKEN); - if (log.isDebugEnabled()) - log.debug("Save request in session '" + if (LOG.isDebugEnabled()) { + LOG.debug("Save request in session '" + session.getIdInternal() + "'"); + } try { saveRequest(request, session); } catch (IOException ioe) { - log.debug("Request body too big to save during authentication"); + LOG.debug("Request body too big to save during authentication"); response.sendError(HttpServletResponse.SC_FORBIDDEN, sm.getString("authenticator.requestBodyTooBig")); - return (false); + return false; } FederationProcessor wfProc = new FederationProcessorImpl(); redirectToIssuer(request, response, wfProc); - return (false); + return false; } } - return (true); + return true; } // Is this the re-submit of the original request URI after successful // authentication? If so, forward the *original* request instead. if (matchRequest(request)) { session = request.getSessionInternal(true); - if (log.isDebugEnabled()) - log.debug("Restore request from session '" + if (LOG.isDebugEnabled()) { + LOG.debug("Restore request from session '" + session.getIdInternal() + "'"); - principal = (Principal) session - .getNote(Constants.FORM_PRINCIPAL_NOTE); + } + principal = (Principal)session.getNote(Constants.FORM_PRINCIPAL_NOTE); register(request, response, principal, FederationConstants.WSFED_METHOD, null, null); if (restoreRequest(request, session)) { - if (log.isDebugEnabled()) - log.debug("Proceed to restored request"); - return (true); + if (LOG.isDebugEnabled()) { + LOG.debug("Proceed to restored request"); + } + return true; } else { - if (log.isDebugEnabled()) - log.debug("Restore of original request failed"); + if (LOG.isDebugEnabled()) { + LOG.debug("Restore of original request failed"); + } response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return (false); + return false; } } @@ -237,20 +238,20 @@ public class FederationAuthenticator ext // Unauthenticated -> redirect if (wa == null) { session = request.getSessionInternal(true); - if (log.isDebugEnabled()) - log.debug("Save request in session '" + session.getIdInternal() - + "'"); + if (LOG.isDebugEnabled()) { + LOG.debug("Save request in session '" + session.getIdInternal() + "'"); + } try { saveRequest(request, session); } catch (IOException ioe) { - log.debug("Request body too big to save during authentication"); + LOG.debug("Request body too big to save during authentication"); response.sendError(HttpServletResponse.SC_FORBIDDEN, sm.getString("authenticator.requestBodyTooBig")); - return (false); + return false; } FederationProcessor wfProc = new FederationProcessorImpl(); redirectToIssuer(request, response, wfProc); - return (false); + return false; } // Check whether it is the signin request, validate the token. @@ -258,22 +259,23 @@ public class FederationAuthenticator ext String wresult = request.getParameter("wresult"); FederationResponse wfRes = null; if (wa.equals(FederationConstants.ACTION_SIGNIN)) { - if (log.isDebugEnabled()) { - log.debug("SignIn request found"); - log.debug("SignIn action..."); + if (LOG.isDebugEnabled()) { + LOG.debug("SignIn request found"); + LOG.debug("SignIn action..."); } if (wresult == null) { - if (log.isDebugEnabled()) - log.debug("SignIn request must contain wresult"); + if (LOG.isDebugEnabled()) { + LOG.debug("SignIn request must contain wresult"); + } response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return (false); + return false; } else { request.getResponse().sendAcknowledgement(); // processSignInRequest - if (log.isDebugEnabled()) { - log.debug("Process SignIn request"); - log.debug("wresult=\n" + wresult); + if (LOG.isDebugEnabled()) { + LOG.debug("Process SignIn request"); + LOG.debug("wresult=\n" + wresult); } FederationRequest wfReq = new FederationRequest(); @@ -324,13 +326,14 @@ public class FederationAuthenticator ext } if (!validAudience) { - log.warn("Token AudienceRestriction [" + wfRes.getAudience() + "] doesn't match with specified list of URIs."); - response.sendError(HttpServletResponse.SC_FORBIDDEN); - return (false); + LOG.warn("Token AudienceRestriction [" + wfRes.getAudience() + + "] doesn't match with specified list of URIs."); + response.sendError(HttpServletResponse.SC_FORBIDDEN); + return false; } - if (log.isDebugEnabled() && request.getRequestURL().indexOf(wfRes.getAudience()) == -1) { - log.debug("Token AudienceRestriction doesn't match with request URL [" + if (LOG.isDebugEnabled() && request.getRequestURL().indexOf(wfRes.getAudience()) == -1) { + LOG.debug("Token AudienceRestriction doesn't match with request URL [" + wfRes.getAudience() + "] [" + request.getRequestURL() + "]"); } @@ -350,9 +353,9 @@ public class FederationAuthenticator ext // [TODO] clocksqew } } else { - log.error("Not supported action found in parameter wa: " + wa); + LOG.error("Not supported action found in parameter wa: " + wa); response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return (false); + return false; } /* @@ -366,22 +369,23 @@ public class FederationAuthenticator ext */ if (principal == null) { forwardToErrorPage(request, response, config); - return (false); + return false; } - if (log.isDebugEnabled()) { - log.debug("Authentication of '" + principal + "' was successful"); + if (LOG.isDebugEnabled()) { + LOG.debug("Authentication of '" + principal + "' was successful"); } // context.addServletContainerInitializer(sci, classes) // session.addSessionListener(listener) // HttpSessionAttributeListener - if (session == null) + if (session == null) { session = request.getSessionInternal(false); + } if (session == null) { - if (containerLog.isDebugEnabled()) - containerLog - .debug("User took so long to log on the session expired"); + if (containerLog.isDebugEnabled()) { + containerLog.debug("User took so long to log on the session expired"); + } if (landingPage == null) { response.sendError(HttpServletResponse.SC_REQUEST_TIMEOUT, sm.getString("authenticator.sessionExpired")); @@ -392,11 +396,10 @@ public class FederationAuthenticator ext SavedRequest saved = new SavedRequest(); saved.setMethod("GET"); saved.setRequestURI(uri); - request.getSessionInternal(true).setNote( - Constants.FORM_REQUEST_NOTE, saved); + request.getSessionInternal(true).setNote(Constants.FORM_REQUEST_NOTE, saved); response.sendRedirect(response.encodeRedirectURL(uri)); } - return (false); + return false; } // Save the authenticated Principal in our session @@ -416,9 +419,10 @@ public class FederationAuthenticator ext // Redirect the user to the original request URI (which will cause // the original request to be restored) requestURI = savedRequestURL(session); - if (log.isDebugEnabled()) - log.debug("Redirecting to original '" + requestURI + "'"); - if (requestURI == null) + if (LOG.isDebugEnabled()) { + LOG.debug("Redirecting to original '" + requestURI + "'"); + } + if (requestURI == null) { if (landingPage == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, sm.getString("authenticator.formlogin")); @@ -433,9 +437,10 @@ public class FederationAuthenticator ext response.sendRedirect(response.encodeRedirectURL(uri)); } - else + } else { response.sendRedirect(response.encodeRedirectURL(requestURI)); - return (false); + } + return false; } @Override @@ -457,9 +462,8 @@ public class FederationAuthenticator ext * {@link HttpServletResponse#sendError(int, String)} throws an * {@link IOException} */ - protected void redirectToIssuer(Request request, - HttpServletResponse response, FederationProcessor processor) - throws IOException { + protected void redirectToIssuer(Request request, HttpServletResponse response, FederationProcessor processor) + throws IOException { String contextName = request.getServletContext().getContextPath(); if (contextName == null || contextName.isEmpty()) { @@ -468,7 +472,7 @@ public class FederationAuthenticator ext FederationContext fedCtx = this.configurator.getFederationContext(contextName); String redirectURL = processor.createSignInRequest(request, fedCtx); if (redirectURL == null) { - log.warn("Failed to create SignInRequest."); + LOG.warn("Failed to create SignInRequest."); response.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create SignInRequest."); } else { Modified: cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationPrincipalImpl.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationPrincipalImpl.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationPrincipalImpl.java (original) +++ cxf/fediz/trunk/plugins/tomcat/src/main/java/org/apache/cxf/fediz/tomcat/FederationPrincipalImpl.java Wed May 16 21:29:53 2012 @@ -1,19 +1,22 @@ -/* - * 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. +/** + * 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.tomcat; import java.util.List; Modified: cxf/fediz/trunk/pom.xml URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/pom.xml?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/pom.xml (original) +++ cxf/fediz/trunk/pom.xml Wed May 16 21:29:53 2012 @@ -422,7 +422,6 @@ </dependency> </dependencies> </plugin> -<!-- Comment out for now <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> @@ -457,12 +456,6 @@ </execution> </executions> </plugin> ---> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - <version>2.9.1</version> - </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java (original) +++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpSTSClient.java Wed May 16 21:29:53 2012 @@ -46,7 +46,7 @@ import org.slf4j.LoggerFactory; public class IdpSTSClient extends STSClient { - private final static Logger LOG = LoggerFactory.getLogger(IdpSTSClient.class); + private static final Logger LOG = LoggerFactory.getLogger(IdpSTSClient.class); public IdpSTSClient(Bus b) { super(b); @@ -56,8 +56,7 @@ public class IdpSTSClient extends STSCli return requestSecurityTokenResponse(null); } - public String requestSecurityTokenResponse(String appliesTo) - throws Exception { + public String requestSecurityTokenResponse(String appliesTo) throws Exception { String action = null; if (isSecureConv) { action = namespace + "/RST/SCT"; Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpServlet.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpServlet.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpServlet.java (original) +++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/IdpServlet.java Wed May 16 21:29:53 2012 @@ -29,6 +29,8 @@ import javax.servlet.http.HttpServletReq import javax.servlet.http.HttpServletResponse; import javax.xml.namespace.QName; +import org.w3c.dom.Element; + import org.apache.commons.lang3.StringEscapeUtils; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; @@ -41,12 +43,9 @@ import org.apache.ws.security.WSConstant import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; -import org.w3c.dom.Element; public class IdpServlet extends HttpServlet { - private final static Logger LOG = LoggerFactory.getLogger(IdpServlet.class); - public static final String PARAM_ACTION = "wa"; public static final String ACTION_SIGNIN = "wsignin1.0"; @@ -64,6 +63,9 @@ public class IdpServlet extends HttpServ public static final String AUTH_HEADER_NAME = "WWW-Authenticate"; public static final String SERVLET_PARAM_TOKENTYPE = "ws-trust-tokentype"; + + private static final Logger LOG = LoggerFactory.getLogger(IdpServlet.class); + /** * @@ -94,6 +96,7 @@ public class IdpServlet extends HttpServ } + //CHECKSTYLE:OFF public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -169,8 +172,7 @@ public class IdpServlet extends HttpServ } } catch (Exception ex) { LOG.info("Requesting security token failed", ex); - response.sendError( - HttpServletResponse.SC_FORBIDDEN, + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Requesting security token failed"); return; } @@ -180,14 +182,11 @@ public class IdpServlet extends HttpServ // response); // this.getServletContext().getRequestDispatcher("/WEB-INF/signinresponse.jsp").forward(request, // response); - this.getServletContext() - .getRequestDispatcher( - "/WEB-INF/signinresponse.jsp") + this.getServletContext().getRequestDispatcher("/WEB-INF/signinresponse.jsp") .forward(request, response); } else { - response.sendError(HttpServletResponse.SC_BAD_REQUEST, - "Invalid Authorization header"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Authorization header"); return; } } catch (Exception ex) { Modified: cxf/fediz/trunk/services/sts/src/main/java/org/apache/cxf/fediz/service/sts/FileClaimsHandler.java URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/sts/src/main/java/org/apache/cxf/fediz/service/sts/FileClaimsHandler.java?rev=1339377&r1=1339376&r2=1339377&view=diff ============================================================================== --- cxf/fediz/trunk/services/sts/src/main/java/org/apache/cxf/fediz/service/sts/FileClaimsHandler.java (original) +++ cxf/fediz/trunk/services/sts/src/main/java/org/apache/cxf/fediz/service/sts/FileClaimsHandler.java Wed May 16 21:29:53 2012 @@ -39,7 +39,7 @@ public class FileClaimsHandler implement public static final URI ROLE = URI.create("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role"); - private Map<String, Map<String, String>> userClaims = null; + private Map<String, Map<String, String>> userClaims; public void setUserClaims(Map<String, Map<String, String>> userClaims) { this.userClaims = userClaims; @@ -51,7 +51,7 @@ public class FileClaimsHandler implement @Override public List<URI> getSupportedClaimTypes() { - ArrayList<URI> list = new ArrayList<URI>(); + List<URI> list = new ArrayList<URI>(); list.add(ClaimTypes.EMAILADDRESS); list.add(ClaimTypes.LASTNAME); list.add(ClaimTypes.FIRSTNAME);
