Skip to content
Snippets Groups Projects
Commit c384bdaf authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3928 OZG-4396 adjust property handling for backwards compatibility

parent 62456e8f
No related branches found
No related tags found
No related merge requests found
Showing
with 69 additions and 99 deletions
...@@ -36,19 +36,19 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -36,19 +36,19 @@ import org.springframework.web.bind.annotation.RestController;
public class EnvironmentController { public class EnvironmentController {
@Autowired @Autowired
private KeycloakProperties keycloakProperties; private OAuth2Properties oAuth2Properties;
@Value("${goofy.production}") @Value("${goofy.production}")
private boolean production = true; private boolean production = true;
@GetMapping @GetMapping
public FrontendEnvironment getFrontendEnvironment() { public FrontendEnvironment getFrontendEnvironment() {
return FrontendEnvironment.builder()// return FrontendEnvironment.builder()
.production(production)// .production(production)
.remoteHost(linkTo(RootController.class).toUri().toString())// .remoteHost(linkTo(RootController.class).toUri().toString())
.authServer(keycloakProperties.getAuthServerUrl())// .authServer(oAuth2Properties.getAuthServerUrl())
.clientId(keycloakProperties.getResource())// .clientId(oAuth2Properties.getResource())
.realm(keycloakProperties.getRealm()) .realm(oAuth2Properties.getRealm())
.build(); .build();
} }
} }
\ No newline at end of file
...@@ -32,7 +32,7 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo ...@@ -32,7 +32,7 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo
static final String ROLES_KEY = "roles"; static final String ROLES_KEY = "roles";
@Autowired @Autowired
private JwtAuthConverterProperties jwtAuthConverterProperties; private OAuth2Properties oAuth2Properties;
@Override @Override
public AbstractAuthenticationToken convert(@NonNull Jwt jwt) { public AbstractAuthenticationToken convert(@NonNull Jwt jwt) {
...@@ -44,7 +44,7 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo ...@@ -44,7 +44,7 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo
} }
private String getClaimName() { private String getClaimName() {
return Optional.ofNullable(jwtAuthConverterProperties.getPrincipleAttribute()).orElse(JwtClaimNames.SUB); return Optional.ofNullable(oAuth2Properties.getPrincipleAttribute()).orElse(JwtClaimNames.SUB);
} }
Set<GrantedAuthority> getAuthorities(Jwt jwt) { Set<GrantedAuthority> getAuthorities(Jwt jwt) {
...@@ -56,10 +56,10 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo ...@@ -56,10 +56,10 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo
if (resourceAccess.isEmpty()) { if (resourceAccess.isEmpty()) {
return Collections.emptySet(); return Collections.emptySet();
} }
if (Objects.isNull(resourceAccess.get(jwtAuthConverterProperties.getResourceId()))) { if (Objects.isNull(resourceAccess.get(oAuth2Properties.getResource()))) {
return Collections.emptySet(); return Collections.emptySet();
} }
return extractRoles(getClaimMapFromMap(resourceAccess, jwtAuthConverterProperties.getResourceId())); return extractRoles(getClaimMapFromMap(resourceAccess, oAuth2Properties.getResource()));
} }
private Map<String, Object> getResourceAccess(Jwt jwt) { private Map<String, Object> getResourceAccess(Jwt jwt) {
......
package de.ozgcloud.alfa;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = JwtAuthConverterProperties.PREFIX)
public class JwtAuthConverterProperties {
static final String PREFIX = "ozgcloud.jwt.auth.converter";
/**
* Jwt principle attribute
*/
private String principleAttribute = null;
/**
* Jwt converter resourceId / keycloak clientId
*/
private String resourceId = null;
}
\ No newline at end of file
...@@ -9,23 +9,28 @@ import lombok.Setter; ...@@ -9,23 +9,28 @@ import lombok.Setter;
@Setter @Setter
@Getter @Getter
@Configuration @Configuration
@ConfigurationProperties(prefix = KeycloakProperties.PREFIX) @ConfigurationProperties(prefix = OAuth2Properties.PREFIX)
public class KeycloakProperties { public class OAuth2Properties {
static final String PREFIX = "ozgcloud.keycloak"; static final String PREFIX = "ozgcloud.oauth2";
/** /**
* Keycloak auth server url * OAuth2 auth server url
*/ */
private String authServerUrl; private String authServerUrl;
/** /**
* Keycloak realm * OAuth2 realm
*/ */
private String realm; private String realm;
/** /**
* Keycloak client * OAuth2 resource
*/ */
private String resource; private String resource;
/**
* OAuth2 principle attribute
*/
private String principleAttribute;
} }
\ No newline at end of file
...@@ -44,7 +44,7 @@ class EnvironmentControllerTest { ...@@ -44,7 +44,7 @@ class EnvironmentControllerTest {
@InjectMocks @InjectMocks
private EnvironmentController controller; private EnvironmentController controller;
@Mock @Mock
private KeycloakProperties keycloakProperties; private OAuth2Properties oAuth2Properties;
private MockMvc mockMvc; private MockMvc mockMvc;
...@@ -70,7 +70,7 @@ class EnvironmentControllerTest { ...@@ -70,7 +70,7 @@ class EnvironmentControllerTest {
@Test @Test
void shouldHaveClientId() throws Exception { void shouldHaveClientId() throws Exception {
var client = "goofy"; var client = "goofy";
when(keycloakProperties.getResource()).thenReturn(client); when(oAuth2Properties.getResource()).thenReturn(client);
var response = doRequest(); var response = doRequest();
response.andExpect(jsonPath("$.clientId").value(client)); response.andExpect(jsonPath("$.clientId").value(client));
......
...@@ -30,7 +30,7 @@ class JwtAuthConverterTest { ...@@ -30,7 +30,7 @@ class JwtAuthConverterTest {
@InjectMocks @InjectMocks
private final JwtAuthConverter converter = new JwtAuthConverter(); private final JwtAuthConverter converter = new JwtAuthConverter();
@Mock @Mock
private JwtAuthConverterProperties properties; private OAuth2Properties oAuth2Properties;
@DisplayName("Convert") @DisplayName("Convert")
@Nested @Nested
...@@ -83,7 +83,7 @@ class JwtAuthConverterTest { ...@@ -83,7 +83,7 @@ class JwtAuthConverterTest {
@BeforeEach @BeforeEach
void mock() { void mock() {
when(properties.getPrincipleAttribute()).thenReturn(null); when(oAuth2Properties.getPrincipleAttribute()).thenReturn(null);
} }
@Test @Test
...@@ -100,7 +100,7 @@ class JwtAuthConverterTest { ...@@ -100,7 +100,7 @@ class JwtAuthConverterTest {
@BeforeEach @BeforeEach
void mock() { void mock() {
when(properties.getPrincipleAttribute()).thenReturn(principleClaimKey); when(oAuth2Properties.getPrincipleAttribute()).thenReturn(principleClaimKey);
} }
@Test @Test
...@@ -166,12 +166,12 @@ class JwtAuthConverterTest { ...@@ -166,12 +166,12 @@ class JwtAuthConverterTest {
void shouldCallProperties() { void shouldCallProperties() {
converter.extractResourceRoles(jwt); converter.extractResourceRoles(jwt);
verify(properties).getResourceId(); verify(oAuth2Properties).getResource();
} }
@Test @Test
void shouldReturnEmptySetOnMissingResourceId() { void shouldReturnEmptySetOnMissingResourceId() {
when(properties.getResourceId()).thenReturn(null); when(oAuth2Properties.getResource()).thenReturn(null);
var resourceRoles = converter.extractResourceRoles(jwt); var resourceRoles = converter.extractResourceRoles(jwt);
...@@ -190,7 +190,7 @@ class JwtAuthConverterTest { ...@@ -190,7 +190,7 @@ class JwtAuthConverterTest {
@BeforeEach @BeforeEach
void mock() { void mock() {
doReturn(Collections.emptySet()).when(converter).extractRoles(any()); doReturn(Collections.emptySet()).when(converter).extractRoles(any());
when(properties.getResourceId()).thenReturn(RESOURCE_ID); when(oAuth2Properties.getResource()).thenReturn(RESOURCE_ID);
} }
@Test @Test
......
goofy: goofy:
production: false production: false
keycloak:
auth-server-url: https://sso.dev.by.ozg-cloud.de
realm: by-kiel-dev
resource: alfa
server: server:
error: error:
include-stacktrace: always include-stacktrace: always
...@@ -10,6 +15,3 @@ ozgcloud: ...@@ -10,6 +15,3 @@ ozgcloud:
vorgang-export: true vorgang-export: true
stage: stage:
production: false production: false
\ No newline at end of file
keycloak:
auth-server-url: https://sso.dev.by.ozg-cloud.de
realm: by-kiel-dev
\ No newline at end of file
keycloak:
realm: by-e2e-local-dev
kop: kop:
forwarding: forwarding:
lninfo: lninfo:
...@@ -12,5 +14,3 @@ ozgcloud: ...@@ -12,5 +14,3 @@ ozgcloud:
user-assistance: user-assistance:
documentation: documentation:
url: /assets/benutzerleitfaden/benutzerleitfaden.pdf url: /assets/benutzerleitfaden/benutzerleitfaden.pdf
\ No newline at end of file
keycloak:
realm: by-e2e-local-dev
\ No newline at end of file
...@@ -29,5 +29,8 @@ ozgcloud: ...@@ -29,5 +29,8 @@ ozgcloud:
user-assistance: user-assistance:
documentation: documentation:
url: /assets/benutzerleitfaden/benutzerleitfaden.pdf url: /assets/benutzerleitfaden/benutzerleitfaden.pdf
keycloak: keycloak:
auth-server-url: http://localhost:8088 auth-server-url: http://localhost:8088
realm: sh-kiel-dev #TODO adjust
resource: sh-kiel-dev-goofy #TODO adjust
\ No newline at end of file
ozgcloud:
keycloak: keycloak:
auth-server-url: https://sso.dev.by.ozg-cloud.de auth-server-url: https://sso.dev.by.ozg-cloud.de
realm: by-kiel-dev realm: by-kiel-dev
resource: alfa
\ No newline at end of file
...@@ -5,13 +5,6 @@ logging: ...@@ -5,13 +5,6 @@ logging:
'[de.ozgcloud]': INFO, '[de.ozgcloud]': INFO,
'[org.springframework.security]': WARN '[org.springframework.security]': WARN
ozgcloud:
jwt:
auth:
converter:
resource-id: alfa
principle-attribute: preferred_username
spring: spring:
mvc: mvc:
pathmatch: pathmatch:
...@@ -29,7 +22,7 @@ spring: ...@@ -29,7 +22,7 @@ spring:
oauth2: oauth2:
resourceserver: resourceserver:
jwt: jwt:
issuer-uri: ${ozgcloud.keycloak.auth-server-url}/realms/${ozgcloud.keycloak.realm} issuer-uri: ${ozgcloud.oauth2.issuer-uri}
jwk-set-uri: ${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/certs jwk-set-uri: ${spring.security.oauth2.resourceserver.jwt.issuer-uri}/protocol/openid-connect/certs
server: server:
...@@ -85,3 +78,11 @@ kop: ...@@ -85,3 +78,11 @@ kop:
user-manager: user-manager:
profile-template: /api/userProfiles/%s profile-template: /api/userProfiles/%s
search-template: /api/userProfiles/?searchBy={searchBy} search-template: /api/userProfiles/?searchBy={searchBy}
ozgcloud:
oauth2:
auth-server-url: ${keycloak.auth-server-url}
realm: ${keycloak.realm}
resource: ${keycloak.resource}
principle-attribute: preferred_username
issuer-uri: ${ozgcloud.oauth2.auth-server-url}/realms/${ozgcloud.oauth2.realm}
\ No newline at end of file
...@@ -73,11 +73,11 @@ spec: ...@@ -73,11 +73,11 @@ spec:
value: {{ include "app.grpc_client_user-manager_address" . }} value: {{ include "app.grpc_client_user-manager_address" . }}
- name: spring_profiles_active - name: spring_profiles_active
value: {{ include "app.envSpringProfiles" . }} value: {{ include "app.envSpringProfiles" . }}
- name: ozgcloud_keycloak_realm - name: keycloak_realm
value: {{ include "app.ssoRealm" . }} value: {{ include "app.ssoRealm" . }}
- name: ozgcloud_keycloak_resource - name: keycloak_resource
value: {{ include "app.ssoClientName" . }} value: {{ include "app.ssoClientName" . }}
- name: ozgcloud_keycloak_auth-server-url - name: keycloak_auth-server-url
value: {{ include "app.ssoServerUrl" . }} value: {{ include "app.ssoServerUrl" . }}
- name: kop_user-manager_url - name: kop_user-manager_url
value: {{ include "app.kop_user-manager_url" . }} value: {{ include "app.kop_user-manager_url" . }}
...@@ -85,8 +85,6 @@ spec: ...@@ -85,8 +85,6 @@ spec:
- name: ozgcloud_user-assistance_documentation_url - name: ozgcloud_user-assistance_documentation_url
value: {{ .Values.ozgcloud.user_assistance.documentation.url }} value: {{ .Values.ozgcloud.user_assistance.documentation.url }}
{{- end }} {{- end }}
- name: ozgcloud_jwt_auth_converter_resource-id
value: {{ include "app.ssoClientName" . }}
{{- with (.Values.env).customList }} {{- with (.Values.env).customList }}
{{ toYaml . | indent 8 }} {{ toYaml . | indent 8 }}
{{- end }} {{- end }}
......
...@@ -36,17 +36,17 @@ tests: ...@@ -36,17 +36,17 @@ tests:
- contains: - contains:
path: spec.template.spec.containers[0].env path: spec.template.spec.containers[0].env
content: content:
name: ozgcloud_keycloak_realm name: keycloak_realm
value: sh-helm-test value: sh-helm-test
- contains: - contains:
path: spec.template.spec.containers[0].env path: spec.template.spec.containers[0].env
content: content:
name: ozgcloud_keycloak_resource name: keycloak_resource
value: alfa value: alfa
- contains: - contains:
path: spec.template.spec.containers[0].env path: spec.template.spec.containers[0].env
content: content:
name: ozgcloud_keycloak_auth-server-url name: keycloak_auth-server-url
value: https://sso.sh.ozg-cloud.de value: https://sso.sh.ozg-cloud.de
- it: check realm with long namespace - it: check realm with long namespace
...@@ -58,7 +58,7 @@ tests: ...@@ -58,7 +58,7 @@ tests:
- contains: - contains:
path: spec.template.spec.containers[0].env path: spec.template.spec.containers[0].env
content: content:
name: ozgcloud_keycloak_realm name: keycloak_realm
value: sh-eins-zwei-drei-test value: sh-eins-zwei-drei-test
- it: check different client name - it: check different client name
...@@ -71,18 +71,5 @@ tests: ...@@ -71,18 +71,5 @@ tests:
- contains: - contains:
path: spec.template.spec.containers[0].env path: spec.template.spec.containers[0].env
content: content:
name: ozgcloud_keycloak_resource name: keycloak_resource
value: different-client
- it: should have jwt auth converter resourceId
set:
sso:
client_name: different-client
asserts:
- isKind:
of: Deployment
- contains:
path: spec.template.spec.containers[0].env
content:
name: ozgcloud_jwt_auth_converter_resource-id
value: different-client value: different-client
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment