Compare commits
5 Commits
1297458c60
...
6147cebfc6
| Author | SHA1 | Date |
|---|---|---|
|
|
6147cebfc6 | 9 months ago |
|
|
b63f746475 | 9 months ago |
|
|
00222c595a | 9 months ago |
|
|
f1287f5bc5 | 9 months ago |
|
|
f1d0456ec5 | 9 months ago |
@ -0,0 +1,8 @@
|
|||||||
|
auth {
|
||||||
|
mode: basic
|
||||||
|
}
|
||||||
|
|
||||||
|
auth:basic {
|
||||||
|
username:
|
||||||
|
password:
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
meta {
|
||||||
|
name: updateUser
|
||||||
|
type: http
|
||||||
|
seq: 3
|
||||||
|
}
|
||||||
|
|
||||||
|
post {
|
||||||
|
url: http://localhost:9090/services/api/user
|
||||||
|
body: json
|
||||||
|
auth: basic
|
||||||
|
}
|
||||||
|
|
||||||
|
headers {
|
||||||
|
Content-Type: application/json
|
||||||
|
X-MethodName: updateUser
|
||||||
|
}
|
||||||
|
|
||||||
|
auth:basic {
|
||||||
|
username: cxfrs
|
||||||
|
password: password
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Bruce Wayne"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,10 +1,19 @@
|
|||||||
server:
|
server:
|
||||||
port: 9090
|
port: 9090
|
||||||
|
|
||||||
camel:
|
camel:
|
||||||
springboot:
|
springboot:
|
||||||
main-run-controller: true
|
main-run-controller: true
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
activemq:
|
activemq:
|
||||||
broker-url: "tcp://localhost:61616"
|
broker-url: "tcp://localhost:61616"
|
||||||
|
ldap:
|
||||||
|
urls: ldap://localhost:10389
|
||||||
|
base: dc=example,dc=com
|
||||||
|
username: uid=admin,ou=system
|
||||||
|
password: secret
|
||||||
|
|
||||||
app:
|
app:
|
||||||
queue-name: "UserServiceQueue"
|
queue-name: "UserServiceQueue"
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,40 @@
|
|||||||
|
version: 1
|
||||||
|
|
||||||
|
dn: uid=cxfrs,ou=users,dc=example,dc=com
|
||||||
|
objectClass: inetOrgPerson
|
||||||
|
objectClass: organizationalPerson
|
||||||
|
objectClass: person
|
||||||
|
objectClass: top
|
||||||
|
cn: CXFRS server
|
||||||
|
sn: CXFRS
|
||||||
|
uid: cxfrs
|
||||||
|
userPassword:: e1NTSEF9QXhLYjdpeVNuWEhYMTBGaGxzU0RoOFdzU0d1VnpWbzJIcGFTcHc9P
|
||||||
|
Q==
|
||||||
|
|
||||||
|
dn: cn=backend,ou=groups,dc=example,dc=com
|
||||||
|
objectClass: groupOfNames
|
||||||
|
objectClass: top
|
||||||
|
cn: backend
|
||||||
|
member: uid=cxfrs,ou=users,dc=example,dc=com
|
||||||
|
|
||||||
|
dn: ou=groups,dc=example,dc=com
|
||||||
|
objectclass: organizationalUnit
|
||||||
|
objectclass: top
|
||||||
|
ou: groups
|
||||||
|
|
||||||
|
dn: ou=users,dc=example,dc=com
|
||||||
|
objectclass: organizationalUnit
|
||||||
|
objectclass: top
|
||||||
|
ou: users
|
||||||
|
|
||||||
|
dn: cn=server,ou=groups,dc=example,dc=com
|
||||||
|
objectClass: groupOfNames
|
||||||
|
objectClass: top
|
||||||
|
cn: server
|
||||||
|
member: uid=cxfrs,ou=users,dc=example,dc=com
|
||||||
|
|
||||||
|
dn: dc=example,dc=com
|
||||||
|
objectclass: domain
|
||||||
|
objectclass: top
|
||||||
|
dc: example
|
||||||
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
== Spring Boot Example with Camel exposing REST services using Apache CXF
|
|
||||||
|
|
||||||
=== Introduction
|
|
||||||
|
|
||||||
This example illustrates how to use https://projects.spring.io/spring-boot/[Spring Boot] with http://camel.apache.org[Camel]. It provides a simple REST service that is created using https://cxf.apache.org/[Apache CXF].
|
|
||||||
|
|
||||||
|
|
||||||
=== Build
|
|
||||||
|
|
||||||
You can build this example using:
|
|
||||||
|
|
||||||
$ mvn package
|
|
||||||
|
|
||||||
=== Run
|
|
||||||
|
|
||||||
You can run this example using:
|
|
||||||
|
|
||||||
$ mvn spring-boot:run
|
|
||||||
|
|
||||||
After the Spring Boot application is started, you can open the following URL in your web browser to access the list of services: http://localhost:8080/services/ including WADL definition
|
|
||||||
|
|
||||||
You can also access the REST endpoint from the command line:
|
|
||||||
|
|
||||||
List all the users
|
|
||||||
[source,text]
|
|
||||||
----
|
|
||||||
$ curl http://localhost:8080/services/api/user -s | jq .
|
|
||||||
----
|
|
||||||
|
|
||||||
The command will produce the following output:
|
|
||||||
|
|
||||||
[source,json]
|
|
||||||
----
|
|
||||||
[ {
|
|
||||||
"id" : 1,
|
|
||||||
"name" : "John Coltrane"
|
|
||||||
}, {
|
|
||||||
"id" : 2,
|
|
||||||
"name" : "Miles Davis"
|
|
||||||
}, {
|
|
||||||
"id" : 3,
|
|
||||||
"name" : "Sonny Rollins"
|
|
||||||
} ]
|
|
||||||
----
|
|
||||||
|
|
||||||
Retrieve a specific user
|
|
||||||
[source,text]
|
|
||||||
----
|
|
||||||
$ curl http://localhost:8080/services/api/user/1 -s | jq .
|
|
||||||
----
|
|
||||||
|
|
||||||
The command will produce the following output:
|
|
||||||
|
|
||||||
[source,json]
|
|
||||||
----
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"name": "John Coltrane"
|
|
||||||
}
|
|
||||||
----
|
|
||||||
|
|
||||||
Insert/update user
|
|
||||||
|
|
||||||
[source,text]
|
|
||||||
----
|
|
||||||
$ curl -X PUT http://localhost:8080/services/api/user --data '{"id":4,"name":"Charlie Parker"}' -H 'Content-Type: application/json' -v
|
|
||||||
----
|
|
||||||
|
|
||||||
The http status code of the response will be https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml#http-status-codes-1[201]
|
|
||||||
|
|
||||||
Moreover, the input user is validated according to the annotations on the link:src/main/java/org/apache/camel/example/springboot/cxf/User.java[User bean]
|
|
||||||
|
|
||||||
[source,text]
|
|
||||||
----
|
|
||||||
$ curl -X PUT http://localhost:8080/services/api/user --data '{"id":4,"name":"C"}' -H 'Content-Type: application/json'
|
|
||||||
----
|
|
||||||
|
|
||||||
will produce a validation error
|
|
||||||
|
|
||||||
|
|
||||||
The Spring Boot application can be stopped pressing `[CTRL] + [C]` in the shell.
|
|
||||||
|
|
||||||
=== Help and contributions
|
|
||||||
|
|
||||||
If you hit any problem using Camel or have some feedback, then please
|
|
||||||
https://camel.apache.org/community/support/[let us know].
|
|
||||||
|
|
||||||
We also love contributors, so
|
|
||||||
https://camel.apache.org/community/contributing/[get involved] :-)
|
|
||||||
|
|
||||||
The Camel riders!
|
|
||||||
@ -0,0 +1,98 @@
|
|||||||
|
**Please start the following services before testing**
|
||||||
|
|
||||||
|
1. ApacheDS Server 2.0.0.AM27
|
||||||
|
|
||||||
|
2. Apache ActiveMQ 6.1.5
|
||||||
|
|
||||||
|
|
||||||
|
**Startup screens**
|
||||||
|
|
||||||
|
1. ApacheDS Server 2.0.0.AM27
|
||||||
|
|
||||||
|
```
|
||||||
|
C:\Users\XXX\apacheds-2.0.0.AM28-SNAPSHOT\bin>apacheds.bat default start
|
||||||
|
Starting ApacheDS instance 'default'...
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.DefaultAttribute] - ERR_13207_VALUE_ALREADY_EXISTS The value '1.3.6.1.4.1.42.2.27.8.5.1' already exists in the attribute (supportedControl)
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.DefaultAttribute] - ERR_13207_VALUE_ALREADY_EXISTS The value '1.2.840.113556.1.4.841' already exists in the attribute (supportedControl)
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.DefaultAttribute] - ERR_13207_VALUE_ALREADY_EXISTS The value '1.3.6.1.4.1.4203.1.9.1.2' already exists in the attribute (supportedControl)
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.DefaultAttribute] - ERR_13207_VALUE_ALREADY_EXISTS The value '1.2.840.113556.1.4.319' already exists in the attribute (supportedControl)
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.DefaultAttribute] - ERR_13207_VALUE_ALREADY_EXISTS The value '1.2.840.113556.1.4.528' already exists in the attribute (supportedControl)
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.api.ldap.model.entry.Value] - MSG_13202_AT_IS_NULL ()
|
||||||
|
[20:22:19] WARN [org.apache.directory.server.core.DefaultDirectoryService] - You didn't change the admin password of directory service instance 'default'. Please update the admin password as soon as possible to prevent a possible security breach.
|
||||||
|
_ _ ____ ____
|
||||||
|
/ \ _ __ ___ ___| |__ ___| _ \/ ___|
|
||||||
|
/ _ \ | '_ \ / _` |/ __| '_ \ / _ \ | | \___ \
|
||||||
|
/ ___ \| |_) | (_| | (__| | | | __/ |_| |___) |
|
||||||
|
/_/ \_\ .__/ \__,_|\___|_| |_|\___|____/|____/
|
||||||
|
|_|
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Apache ActiveMQ 6.1.5
|
||||||
|
|
||||||
|
```
|
||||||
|
C:\Users\XXX\apache-activemq-6.1.5\bin>activemq start
|
||||||
|
|
||||||
|
Warning: JAVA_HOME environment variable is not set.
|
||||||
|
|
||||||
|
Java Runtime: Oracle Corporation 17.0.14 C:\Users\XXX\graalvm-jdk-17.0.14+8.1
|
||||||
|
Heap sizes: current=1048576k free=1039360k max=1048576k
|
||||||
|
JVM args: -XX:ThreadPriorityPolicy=1 -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:-UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=C:\Users\XXX\apache-activemq-6.1.5\bin\..\conf\login.config -Dactivemq.classpath=C:\Users\XXX\apache-activemq-6.1.5\bin\..\conf;C:\Users\XXX\apache-activemq-6.1.5\bin\../conf;C:\Users\XXX\apache-activemq-6.1.5\bin\../conf; -Dactivemq.home=C:\Users\XXX\apache-activemq-6.1.5\bin\.. -Dactivemq.base=C:\Users\XXX\apache-activemq-6.1.5\bin\.. -Dactivemq.conf=C:\Users\XXX\apache-activemq-6.1.5\bin\..\conf -Dactivemq.data=C:\Users\XXX\apache-activemq-6.1.5\bin\..\data -Djolokia.conf=file:C:\\Users\\XXX\\apache-activemq-6.1.5\\bin\\..\\conf\\jolokia-access.xml -Djava.io.tmpdir=C:\Users\XXX\apache-activemq-6.1.5\bin\..\data\tmp
|
||||||
|
Extensions classpath:
|
||||||
|
[C:\Users\XXX\apache-activemq-6.1.5\bin\..\lib,C:\Users\XXX\apache-activemq-6.1.5\bin\..\lib\camel,C:\Users\XXX\apache-activemq-6.1.5\bin\..\lib\optional,C:\Users\XXX\apache-activemq-6.1.5\bin\..\lib\web,C:\Users\XXX\apache-activemq-6.1.5\bin\..\lib\extra]
|
||||||
|
ACTIVEMQ_HOME: C:\Users\XXX\apache-activemq-6.1.5\bin\..
|
||||||
|
ACTIVEMQ_BASE: C:\Users\XXX\apache-activemq-6.1.5\bin\..
|
||||||
|
ACTIVEMQ_CONF: C:\Users\XXX\apache-activemq-6.1.5\bin\..\conf
|
||||||
|
ACTIVEMQ_DATA: C:\Users\XXX\apache-activemq-6.1.5\bin\..\data
|
||||||
|
Loading message broker from: xbean:activemq.xml
|
||||||
|
INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\Users\XXX\apache-activemq-6.1.5\bin\..\data\kahadb]
|
||||||
|
INFO | Starting Persistence Adapter: KahaDBPersistenceAdapter[C:\Users\XXX\apache-activemq-6.1.5\bin\..\data\kahadb]
|
||||||
|
INFO | Starting KahaDBStore
|
||||||
|
INFO | Opening MessageDatabase
|
||||||
|
INFO | Page File: C:\Users\XXX\apache-activemq-6.1.5\bin\..\data\kahadb\db.data. Recovering pageFile free list due to prior unclean shutdown..
|
||||||
|
INFO | KahaDB is version 7
|
||||||
|
INFO | Page File: C:\Users\XXX\apache-activemq-6.1.5\bin\..\data\kahadb\db.data. Recovered pageFile free list of size: 0
|
||||||
|
INFO | Starting Temp Data Store
|
||||||
|
INFO | PListStore:[C:\Users\XXX\apache-activemq-6.1.5\bin\..\data\localhost\tmp_storage] started
|
||||||
|
INFO | Starting Job Scheduler Store
|
||||||
|
INFO | Persistence Adapter successfully started
|
||||||
|
INFO | Apache ActiveMQ 6.1.5 (localhost, ID:DESKTOP-66E87L5-60208-1739018831814-0:1) is starting
|
||||||
|
INFO | Listening for connections at: tcp://DESKTOP-66E87L5:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600
|
||||||
|
INFO | Connector openwire started
|
||||||
|
INFO | Listening for connections at: amqp://DESKTOP-66E87L5:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600
|
||||||
|
INFO | Connector amqp started
|
||||||
|
INFO | Listening for connections at: stomp://DESKTOP-66E87L5:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600
|
||||||
|
INFO | Connector stomp started
|
||||||
|
INFO | Listening for connections at: mqtt://DESKTOP-66E87L5:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600
|
||||||
|
INFO | Connector mqtt started
|
||||||
|
INFO | Starting Jetty server
|
||||||
|
INFO | Creating Jetty connector
|
||||||
|
WARN | ServletContext@o.e.j.s.ServletContextHandler@33425811{/,null,STARTING} has uncovered HTTP methods for the following paths: [/]
|
||||||
|
INFO | Listening for connections at ws://DESKTOP-66E87L5:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600
|
||||||
|
INFO | Connector ws started
|
||||||
|
INFO | Apache ActiveMQ 6.1.5 (localhost, ID:DESKTOP-66E87L5-60208-1739018831814-0:1) started
|
||||||
|
INFO | For help or more information please see: http://activemq.apache.org
|
||||||
|
INFO | ActiveMQ WebConsole available at http://127.0.0.1:8161/
|
||||||
|
INFO | ActiveMQ Jolokia REST API available at http://127.0.0.1:8161/api/jolokia/
|
||||||
|
```
|
||||||
|
|
||||||
|
**Setup**
|
||||||
|
|
||||||
|
* Please see conf/springboot.yml for LDAP/ActiveMQ Address
|
||||||
|
|
||||||
|
* For LDAP group and user setup, see misc/ldapdb.ldif
|
||||||
|
|
||||||
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package com.example.camel;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class CxfConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public JacksonJsonProvider jaxrsProvider() {
|
|
||||||
return new JacksonJsonProvider();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package com.example.camel;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.ldap.core.support.BaseLdapPathContextSource;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.Customizer;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.ldap.LdapBindAuthenticationManagerFactory;
|
||||||
|
import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator;
|
||||||
|
import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SecurityConfig {
|
||||||
|
|
||||||
|
public static final String ROLE_BACKEND = "ROLE_BACKEND";
|
||||||
|
public static final String ROLE_SERVER = "ROLE_SERVER";
|
||||||
|
|
||||||
|
@Value("${app.group-search-base:ou=groups}")
|
||||||
|
private String groupSearchBase;
|
||||||
|
|
||||||
|
@Value("${app.group-search-filter:(member={0})}")
|
||||||
|
private String groupSearchFilter;
|
||||||
|
|
||||||
|
@Value("${app.user-search-base:ou=users}")
|
||||||
|
private String userSearchBase;
|
||||||
|
|
||||||
|
@Value("${app.user-search-filter:(uid={0})}")
|
||||||
|
private String userSearchFilter;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
|
http.authorizeHttpRequests(
|
||||||
|
(authorize) -> authorize.requestMatchers(HttpMethod.GET, "/**").hasAuthority(ROLE_BACKEND)
|
||||||
|
.requestMatchers(HttpMethod.POST, "/**").hasAuthority(ROLE_SERVER))
|
||||||
|
.httpBasic(Customizer.withDefaults()).csrf(csrf -> csrf.disable());
|
||||||
|
return http.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LdapAuthoritiesPopulator authorities(BaseLdapPathContextSource contextSource) {
|
||||||
|
DefaultLdapAuthoritiesPopulator authorities = new DefaultLdapAuthoritiesPopulator(contextSource,
|
||||||
|
groupSearchBase);
|
||||||
|
authorities.setGroupSearchFilter(groupSearchFilter);
|
||||||
|
return authorities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManager(BaseLdapPathContextSource contextSource,
|
||||||
|
LdapAuthoritiesPopulator authorities) {
|
||||||
|
LdapBindAuthenticationManagerFactory factory = new LdapBindAuthenticationManagerFactory(contextSource);
|
||||||
|
factory.setUserSearchBase(userSearchBase);
|
||||||
|
factory.setUserSearchFilter(userSearchFilter);
|
||||||
|
factory.setLdapAuthoritiesPopulator(authorities);
|
||||||
|
return factory.createAuthenticationManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JacksonJsonProvider jaxrsProvider() {
|
||||||
|
return new JacksonJsonProvider();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue