Skip to content

Commit c489bfe

Browse files
Obtained jwt token from spring auth server
Pendind to obtain an opaque
1 parent 38dc01f commit c489bfe

20 files changed

+44
-37
lines changed

selenium/authorization-server/src/main/java/com/rabbitmq/authorization_server/SecurityConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.security.KeyPairGenerator;
55
import java.security.interfaces.RSAPrivateKey;
66
import java.security.interfaces.RSAPublicKey;
7-
import java.util.List;
87
import java.util.UUID;
98

109
import org.springframework.context.annotation.Bean;
@@ -15,8 +14,6 @@
1514
import org.springframework.security.config.Customizer;
1615
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1716
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
18-
import org.springframework.security.core.userdetails.User;
19-
import org.springframework.security.core.userdetails.UserDetails;
2017
import org.springframework.security.core.userdetails.UserDetailsService;
2118
import org.springframework.security.oauth2.jwt.JwtDecoder;
2219
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
@@ -120,6 +117,10 @@ public OAuth2TokenCustomizer<JwtEncodingContext> jwtTokenCustomizer() {
120117
return (context) -> {
121118
if (OAuth2TokenType.ACCESS_TOKEN.equals(context.getTokenType())) {
122119
AbstractAuthenticationToken principal = context.getPrincipal();
120+
System.out.println("registered client: " + context.getRegisteredClient());
121+
System.out.println("authorities : " + principal.getAuthorities());
122+
System.out.println("authorized scopes : " + context.getAuthorizedScopes());
123+
123124
context.getClaims()
124125
.audience(AudienceAuthority.getAll(principal))
125126
.claim("extra_scope", ScopeAuthority.getAllUnauthorized(principal,

selenium/authorization-server/src/main/resources/application.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ spring:
1212
alias: server-spring-tls
1313
password: foobar
1414
keystore:
15-
location: ../test/oauth/spring/server_spring.jks
15+
location: ../test/authnz-msg-protocols/spring/server_spring.jks
1616
password: foobar
1717
type: PKCS12
1818
security:
@@ -28,22 +28,25 @@ spring:
2828
- rabbitmq
2929
authorizationserver:
3030
client:
31-
mgt_api_client:
31+
producer:
3232
registration:
3333
provider: spring
34-
client-id: mgt_api_client
34+
client-id: producer
35+
client-secret: "{noop}producer"
3536
authorization-grant-types:
3637
- client_credentials
3738
client-authentication-methods:
38-
- client_secret_basic
39-
require-proof-key: true
39+
- client_secret_post
4040
token-settings:
41-
access-token-format: reference
41+
access-token-format: reference
4242
scopes:
4343
- openid
4444
- profile
4545
- rabbitmq.tag:management
46-
client-name: mgt_api_client
46+
- rabbitmq.configure:*/*
47+
- rabbitmq.read:*/*
48+
- rabbitmq.write:*/*
49+
client-name: producer
4750
rabbitmq_client_code:
4851
registration:
4952
provider: spring

selenium/suites/authnz-messaging/auth-cache-http-backends.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="http-user auth-http auth_backends-cache-http "
6+
PROFILES="amqp-http-user auth-http auth_backends-cache-http "
77

88
source $SCRIPT/../../bin/suite_template
99
runWith mock-auth-backend-http

selenium/suites/authnz-messaging/auth-cache-ldap-backends.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="ldap-user auth-ldap auth_backends-cache-ldap"
6+
PROFILES="amqp-ldap-user auth-ldap auth_backends-cache-ldap"
77

88
source $SCRIPT/../../bin/suite_template
99
runWith mock-auth-backend-ldap

selenium/suites/authnz-messaging/auth-http-backend-with-mtls.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="internal-user auth-http auth_backends-http auth-mtls"
6+
PROFILES="amqp-internal-user auth-http auth_backends-http auth-mtls"
77
# internal-user profile is used because the client certificates to
88
# access rabbitmq are issued with the alt_name = internal-user
99

selenium/suites/authnz-messaging/auth-http-internal-backends-with-internal.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="internal-user auth-http auth_backends-http-internal "
6+
PROFILES="amqp-internal-user auth-http auth_backends-http-internal "
77

88
source $SCRIPT/../../bin/suite_template
99
runWith mock-auth-backend-http

selenium/suites/authnz-messaging/auth-http-internal-backends.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="http-user auth-http auth_backends-http-internal "
6+
PROFILES="amqp-http-user auth-http auth_backends-http-internal "
77

88
source $SCRIPT/../../bin/suite_template
99
runWith mock-auth-backend-http

selenium/suites/authnz-messaging/auth-internal-backend.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="internal-user auth_backends-internal"
6+
PROFILES="amqp-internal-user auth_backends-internal"
77

88
source $SCRIPT/../../bin/suite_template
99
run

selenium/suites/authnz-messaging/auth-internal-http-backends.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="internal-user auth_http auth_backends-internal-http "
6+
PROFILES="amqp-internal-user auth_http auth_backends-internal-http "
77

88
source $SCRIPT/../../bin/suite_template
99
runWith mock-auth-backend-http

selenium/suites/authnz-messaging/auth-internal-mtls-backend.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="internal-user auth_backends-internal tls auth-mtls"
6+
PROFILES="amqp-internal-user auth_backends-internal tls auth-mtls"
77

88
source $SCRIPT/../../bin/suite_template
99
run

selenium/suites/authnz-messaging/auth-ldap-backend.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="ldap-user auth-ldap auth_backends-ldap "
6+
PROFILES="amqp-ldap-user auth-ldap auth_backends-ldap "
77

88
source $SCRIPT/../../bin/suite_template
99
runWith mock-auth-backend-ldap

selenium/suites/authnz-messaging/auth-oauth-backend-with-opaque-tokens.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

55
TEST_CASES_PATH=/authnz-msg-protocols
6-
PROFILES="spring oauth-producer auth-oauth-spring auth_backends-opaque-oauth auth-mtls"
6+
PROFILES="spring oauth-producer auth-oauth-spring auth_backends-opaque-oauth "
77

88
source $SCRIPT/../../bin/suite_template
99
runWith spring
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export RABBITMQ_AMQP_USERNAME=internaluser
22
export RABBITMQ_AMQP_PASSWORD=management
3+
export RABBITMQ_MQTT_CLIENT_ID=internaluser
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export SPRING_URL=https://localhost:8443
22
export OAUTH_PROVIDER_URL=https://localhost:8443
3-
export SPRING_CA_CERT=authnz-msg-protocols/spring/ca_spring_certificate.pem
3+
export SPRING_CA_CERT=${TEST_CONFIG_PATH}/spring/ca_spring_certificate.pem
44
export OAUTH_NODE_EXTRA_CA_CERTS=authnz-msg-protocols/spring/ca_spring_certificate.pem

selenium/test/authnz-msg-protocols/mqtt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('Having MQTT protocol enbled and the following auth_backends: ' + backe
2121
let mqttUrl = process.env.RABBITMQ_MQTT_URL || "mqtt://" + rabbit + ":1883"
2222
let username = process.env.RABBITMQ_AMQP_USERNAME
2323
let password = process.env.RABBITMQ_AMQP_PASSWORD
24-
let client_id = process.env.RABBITMQ_AMQP_USERNAME || 'selenium-client'
24+
let client_id = process.env.RABBITMQ_MQTT_CLIENT_ID || 'selenium-client'
2525

2626
before(function () {
2727
if (backends.includes("http") && (username.includes("http") || usemtls)) {
@@ -47,7 +47,7 @@ describe('Having MQTT protocol enbled and the following auth_backends: ' + backe
4747
log("Obtening OpenId configuration from " + oauthProviderUrl)
4848
let openIdConfig = openIdConfiguration(oauthProviderUrl)
4949
log("Obtaining token from " + openIdConfig.token_endpoint + " using " + oauthClientId + ":" + oauthClientSecret)
50-
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint)
50+
password = tokenFor(oauthClientId, oauthClientSecret, openIdConfig.token_endpoint, "rabbitmq.configure:*/*")
5151
log("Obtained access token : " + password)
5252
}
5353
mqttOptions = {

selenium/test/authnz-msg-protocols/rabbitmq.auth_backends-opaque-oauth.conf

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ log.console.level = debug
44
auth_backends.1 = rabbit_auth_backend_oauth2
55

66
# Common auth_oauth2 settings for all resources
7-
auth_oauth2.preferred_username_claims.1 = preferred_username
8-
auth_oauth2.preferred_username_claims.2 = user_name
9-
auth_oauth2.preferred_username_claims.3 = email
7+
auth_oauth2.preferred_username_claims.1 = sub
108

11-
## Resource servers hosted by this rabbitmq instance
12-
auth_oauth2.resource_servers.1.id = rabbitmq
13-
auth_oauth2.resource_servers.1.oauth_provider_id = spring
9+
## Resource server hosted by this rabbitmq instance
10+
auth_oauth2.resource_server_id = rabbitmq
11+
auth_oauth2.verify_aud = false
12+
auth_oauth2.issuer = ${SPRING_URL}
13+
auth_oauth2.https.cacertfile = ${SPRING_CA_CERT}
14+
auth_oauth2.https.verify = verify_peer
15+
auth_oauth2.https.hostname_verification = wildcard
1416

15-
## Oauth providers
16-
auth_oauth2.oauth_providers.spring.issuer = ${SPRING_URL}
17-
auth_oauth2.oauth_providers.spring.https.cacertfile = ${SPRING_CA_CERT}
18-
auth_oauth2.oauth_providers.spring.https.verify = verify_peer
19-
auth_oauth2.oauth_providers.spring.https.hostname_verification = wildcard

selenium/test/authnz-msg-protocols/spring/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ spring:
4343
- openid
4444
- profile
4545
- rabbitmq.tag:management
46+
- rabbitmq.configure:*/*
47+
- rabbitmq.read:*/*
48+
- rabbitmq.write:*/*
4649
client-name: producer
4750
rabbitmq_client_code:
4851
registration:

selenium/test/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ module.exports = {
236236
}
237237
},
238238

239-
tokenFor: (client_id, client_secret, url = uaaUrl) => {
239+
tokenFor: (client_id, client_secret, url = uaaUrl, scopes = "") => {
240240
const req = new XMLHttpRequest()
241-
const params = 'client_id=' + client_id +
241+
let params = 'client_id=' + client_id +
242242
'&client_secret=' + client_secret +
243243
'&grant_type=client_credentials' +
244244
'&token_format=jwt' +
245245
'&response_type=token'
246-
246+
if (scopes != "") {
247+
params = params + "&scope=" + scopes
248+
}
247249
req.open('POST', url, false)
248250
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
249251
req.setRequestHeader('Accept', 'application/json')

0 commit comments

Comments
 (0)