This commit is contained in:
Arjen Poutsma
2008-05-03 13:21:13 +00:00
parent 13f5bb8872
commit 557fa9d12b
7 changed files with 42 additions and 88 deletions

View File

@@ -11,11 +11,14 @@
xmlns="http://www.springframework.org/spring-ws/include/schema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute ref="xml:lang" use="required"/>
</xsd:complexType>
</xsd:element>

View File

@@ -5,12 +5,14 @@
attributeFormDefault="unqualified">
<xsd:include schemaLocation="included.xsd"/>
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute ref="xml:lang" use="required"/>
</xsd:complexType>
</xsd:element>

View File

@@ -3,6 +3,7 @@
targetNamespace="urn:1"
xmlns="urn:1"
xmlns:imported="urn:2" elementFormDefault="qualified">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:include schemaLocation="C.xsd"/>
<xsd:import schemaLocation="D.xsd" namespace="urn:2"/>
<xsd:complexType name="B">
@@ -10,5 +11,6 @@
<xsd:element type="C" name="c"/>
<xsd:element type="imported:D" name="d"/>
</xsd:sequence>
<!--<xsd:attribute ref="xml:lang" use="required"/>-->
</xsd:complexType>
</xsd:schema>

View File

@@ -1,84 +0,0 @@
/*
* Copyright 2006 the original author or authors.
*
* Licensed 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.springframework.ws.samples.airline.security;
import org.acegisecurity.Authentication;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
import org.springframework.ws.samples.airline.service.NoSuchFrequentFlyerException;
/**
* Implementation of the <code>FrequentFlyerSecurityService</code> that uses Acegi.
*
* @author Arjen Poutsma
*/
public class AcegiFrequentFlyerSecurityService implements FrequentFlyerSecurityService, UserDetailsService {
private FrequentFlyerDao frequentFlyerDao;
public AcegiFrequentFlyerSecurityService(FrequentFlyerDao frequentFlyerDao) {
this.frequentFlyerDao = frequentFlyerDao;
}
@Transactional
public FrequentFlyer getCurrentlyAuthenticatedFrequentFlyer() {
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
if (authentication != null) {
if (authentication.getPrincipal() instanceof FrequentFlyerDetails) {
FrequentFlyerDetails details = (FrequentFlyerDetails) authentication.getPrincipal();
return details.getFrequentFlyer();
}
else {
return (FrequentFlyer) authentication.getPrincipal();
}
}
else {
return null;
}
}
@Transactional
public FrequentFlyer getFrequentFlyer(String username) throws NoSuchFrequentFlyerException {
FrequentFlyer frequentFlyer = frequentFlyerDao.get(username);
if (frequentFlyer != null) {
return frequentFlyer;
}
else {
throw new NoSuchFrequentFlyerException(username);
}
}
@Transactional
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
FrequentFlyer frequentFlyer = frequentFlyerDao.get(username);
if (frequentFlyer != null) {
return new FrequentFlyerDetails(frequentFlyer);
}
else {
throw new UsernameNotFoundException("Frequent flyer '" + username + "' not found");
}
}
}

View File

@@ -159,12 +159,12 @@ public class CommonsXsdSchemaCollection implements XsdSchemaCollection, Initiali
private void findImports(XmlSchema schema, List processedSchemas) {
processedSchemas.add(schema);
XmlSchemaObjectCollection includes = schema.getIncludes();
for (int i = 0; i < includes.getCount(); i++) {
XmlSchemaExternal external = (XmlSchemaExternal) includes.getItem(i);
XmlSchemaObjectCollection imports = schema.getIncludes();
for (int i = 0; i < imports.getCount(); i++) {
XmlSchemaExternal external = (XmlSchemaExternal) imports.getItem(i);
if (external instanceof XmlSchemaImport) {
XmlSchema importedSchema = external.getSchema();
if (!processedSchemas.contains(importedSchema)) {
if (importedSchema != null && !processedSchemas.contains(importedSchema)) {
inlineIncludes(importedSchema, processedSchemas);
findImports(importedSchema, processedSchemas);
xmlSchemas.add(importedSchema);

View File

@@ -85,6 +85,19 @@ public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
assertXMLEqual("Invalid Source returned", expected, result);
}
public void testXmlNamespace() throws Exception {
Resource resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
XsdSchema importing = createSchema(resource);
String namespace = "http://www.springframework.org/spring-ws/xmlNamespace";
assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
DOMResult domResult = new DOMResult();
transformer.transform(importing.getSource(), domResult);
Document result = (Document) domResult.getNode();
assertXMLEqual("Invalid Source returned", expected, result);
}
public void testCreateValidator() throws Exception {
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
XsdSchema single = createSchema(resource);

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/xmlNamespace"
xmlns="http://www.springframework.org/spring-ws/xmlNamespace" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:element name="GetOrderRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="child" type="xsd:string"/>
</xsd:sequence>
<xsd:attribute ref="xml:lang" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>