Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATALDAP-1 - Create namespace handler and XML schema.
Spring Data LDAP now uses its own Namespace: http://www.springframework.org/schema/data/ldap. Using XML configuration for Spring LDAP and Spring Data LDAP requires both namespaces to be declared. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ldap="http://www.springframework.org/schema/ldap" xmlns:data-ldap="http://www.springframework.org/schema/data/ldap" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd http://www.springframework.org/schema/data/ldap http://www.springframework.org/schema/data/ldap/spring-ldap.xsd"> <ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin"/> <ldap:ldap-template/> <data-ldap:repositories base-package="org.springframework.data.ldap.config"/> </beans>
- Loading branch information
Showing
8 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/org/springframework/data/ldap/config/LdapNamespaceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2016 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.data.ldap.config; | ||
|
||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport; | ||
import org.springframework.data.ldap.repository.config.LdapRepositoryConfigurationExtension; | ||
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser; | ||
|
||
/** | ||
* {@link org.springframework.beans.factory.xml.NamespaceHandler} for LDAP configuration. | ||
* | ||
* @author Mark Paluch | ||
*/ | ||
public class LdapNamespaceHandler extends NamespaceHandlerSupport { | ||
|
||
/* | ||
* (non-Javadoc) | ||
* @see org.springframework.beans.factory.xml.NamespaceHandler#init() | ||
*/ | ||
public void init() { | ||
|
||
registerBeanDefinitionParser("repositories", | ||
new RepositoryBeanDefinitionParser(new LdapRepositoryConfigurationExtension())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
http\://www.springframework.org/schema/data/ldap=org.springframework.data.ldap.config.LdapNamespaceHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
http\://www.springframework.org/schema/data/ldap/spring-ldap-1.0.xsd=org/springframework/data/ldap/config/spring-ldap-1.0.xsd | ||
http\://www.springframework.org/schema/data/ldap/spring-ldap.xsd=org/springframework/data/ldap/config/spring-ldap-1.0.xsd |
38 changes: 38 additions & 0 deletions
38
src/main/resources/org/springframework/data/ldap/config/spring-ldap-1.0.xsd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<xsd:schema xmlns="http://www.springframework.org/schema/data/ldap" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:tool="http://www.springframework.org/schema/tool" | ||
xmlns:repository="http://www.springframework.org/schema/data/repository" | ||
targetNamespace="http://www.springframework.org/schema/data/ldap" | ||
elementFormDefault="qualified" | ||
attributeFormDefault="unqualified"> | ||
|
||
<xsd:import namespace="http://www.springframework.org/schema/beans"/> | ||
<xsd:import namespace="http://www.springframework.org/schema/tool"/> | ||
<xsd:import namespace="http://www.springframework.org/schema/data/repository" | ||
schemaLocation="http://www.springframework.org/schema/data/repository/spring-repository.xsd"/> | ||
|
||
<xsd:element name="repositories"> | ||
<xsd:complexType> | ||
<xsd:complexContent> | ||
<xsd:extension base="repository:repositories"> | ||
<xsd:attributeGroup ref="repository:repository-attributes"/> | ||
<xsd:attribute name="ldap-template-ref" type="ldapTemplateRef" | ||
default="ldapTemplate"/> | ||
</xsd:extension> | ||
</xsd:complexContent> | ||
</xsd:complexType> | ||
</xsd:element> | ||
|
||
<xsd:simpleType name="ldapTemplateRef"> | ||
<xsd:annotation> | ||
<xsd:appinfo> | ||
<tool:annotation kind="ref"> | ||
<tool:assignable-to type="org.springframework.ldap.core.LdapTemplate"/> | ||
</tool:annotation> | ||
</xsd:appinfo> | ||
</xsd:annotation> | ||
<xsd:union memberTypes="xsd:string"/> | ||
</xsd:simpleType> | ||
|
||
</xsd:schema> |
44 changes: 44 additions & 0 deletions
44
src/test/java/org/springframework/data/ldap/config/LdapNamespaceHandlerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2016 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.data.ldap.config; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* Unit test for {@link LdapNamespaceHandler}. | ||
* | ||
* @author Mark Paluch | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration | ||
public class LdapNamespaceHandlerTests { | ||
|
||
@Autowired private ApplicationContext context; | ||
|
||
@Test | ||
public void shouldCreateRepository() { | ||
assertThat(context.getBean(DummyLdapRepository.class), is(notNullValue())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:ldap="http://www.springframework.org/schema/ldap" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd"> | ||
|
||
<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin"/> | ||
|
||
<ldap:ldap-template/> | ||
</beans> |
12 changes: 12 additions & 0 deletions
12
...test/resources/org/springframework/data/ldap/config/LdapNamespaceHandlerTests-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:data-ldap="http://www.springframework.org/schema/data/ldap" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/data/ldap http://www.springframework.org/schema/data/ldap/spring-ldap.xsd"> | ||
|
||
<import resource="classpath:infrastructure.xml" /> | ||
|
||
<data-ldap:repositories base-package="org.springframework.data.ldap.config"/> | ||
|
||
</beans> |