1
1
package no .nav .vedtak .sikkerhet .oidc .config .impl ;
2
2
3
- import static no .nav .vedtak .sikkerhet .oidc .config .impl .WellKnownConfigurationHelper .getAuthorizationEndpointFra ;
4
3
import static no .nav .vedtak .sikkerhet .oidc .config .impl .WellKnownConfigurationHelper .getIssuerFra ;
5
4
import static no .nav .vedtak .sikkerhet .oidc .config .impl .WellKnownConfigurationHelper .getJwksFra ;
6
5
import static no .nav .vedtak .sikkerhet .oidc .config .impl .WellKnownConfigurationHelper .getTokenEndpointFra ;
@@ -26,24 +25,16 @@ public final class OidcProviderConfig {
26
25
private static final Environment ENV = Environment .current ();
27
26
private static final Logger LOG = LoggerFactory .getLogger (OidcProviderConfig .class );
28
27
29
- public static final String OPEN_AM_WELL_KNOWN_URL = "oidc.open.am.well.known.url" ;
30
- private static final String OPEN_AM_CONFIG_ISSUER = "oidc.open.am.openid.config.issuer" ;
31
- private static final String OPEN_AM_CONFIG_JWKS_URI = "oidc.open.am.openid.config.jwks.uri" ;
32
- private static final String OPEN_AM_CONFIG_TOKEN_ENDPOINT = "oidc.open.am.openid.config.token.endpoint" ;
33
- private static final String OPEN_AM_CONFIG_AUTH_ENDPOINT = "oidc.open.am.openid.config.authorization.endpoint" ;
34
- public static final String OPEN_AM_CLIENT_ID = "oidc.open.am.client.id" ;
35
- public static final String OPEN_AM_CLIENT_SECRET = "oidc.open.am.client.secret" ;
36
-
37
28
private static final String STS_WELL_KNOWN_URL = "oidc.sts.well.known.url" ;
38
29
private static final String STS_CONFIG_ISSUER = "oidc.sts.openid.config.issuer" ;
39
30
private static final String STS_CONFIG_JWKS_URI = "oidc.sts.openid.config.jwks.uri" ;
40
31
private static final String STS_CONFIG_TOKEN_ENDPOINT = "oidc.sts.openid.config.token.endpoint" ;
41
32
42
- private static final String AZURE_WELL_KNOWN_URL = "azure.app.well.known.url" ; // naiserator
43
- private static final String AZURE_CONFIG_ISSUER = "azure.openid.config.issuer" ; // naiserator
44
- private static final String AZURE_CONFIG_JWKS_URI = "azure.openid.config.jwks.uri" ; // naiserator
33
+ public static final String AZURE_WELL_KNOWN_URL = "azure.app.well.known.url" ; // naiserator
34
+ public static final String AZURE_CONFIG_ISSUER = "azure.openid.config.issuer" ; // naiserator
35
+ public static final String AZURE_CONFIG_JWKS_URI = "azure.openid.config.jwks.uri" ; // naiserator
45
36
private static final String AZURE_CONFIG_TOKEN_ENDPOINT = "azure.openid.config.token.endpoint" ; // naiserator
46
- private static final String AZURE_CLIENT_ID = "azure.app.client.id" ; // naiserator
37
+ public static final String AZURE_CLIENT_ID = "azure.app.client.id" ; // naiserator
47
38
private static final String AZURE_CLIENT_SECRET = "azure.app.client.secret" ; // naiserator
48
39
private static final String AZURE_HTTP_PROXY = "azure.http.proxy" ; // settes ikke av naiserator
49
40
@@ -97,15 +88,12 @@ private static synchronized Set<OpenIDConfiguration> init() {
97
88
private static Set <OpenIDConfiguration > hentConfig () {
98
89
Set <OpenIDConfiguration > idProviderConfigs = new HashSet <>();
99
90
100
- // OpenAM
101
- idProviderConfigs .add (createOpenAmConfiguration (ENV .getProperty (OPEN_AM_WELL_KNOWN_URL )));
102
-
103
91
// OIDC STS
104
- if (ENV .getProperty (STS_WELL_KNOWN_URL ) != null || ENV .getProperty ("oidc.sts.issuer.url" ) != null || ENV . getProperty ( STS_CONFIG_ISSUER ) != null ) { // Det er kanskje noen apper som ikke bruker STS token validering??
92
+ if (ENV .getProperty (STS_WELL_KNOWN_URL ) != null || ENV .getProperty (STS_CONFIG_ISSUER ) != null ) { // Det er kanskje noen apper som ikke bruker STS token validering??
105
93
idProviderConfigs .add (createStsConfiguration (ENV .getProperty (STS_WELL_KNOWN_URL )));
106
94
}
107
95
108
- // Azure
96
+ // Azure - ikke alle apps trenger denne (tokenx-apps)
109
97
var azureKonfigUrl = ENV .getProperty (AZURE_WELL_KNOWN_URL );
110
98
if (azureKonfigUrl != null ) {
111
99
LOG .debug ("Oppretter AzureAD konfig fra '{}'" , azureKonfigUrl );
@@ -127,52 +115,20 @@ private static Set<OpenIDConfiguration> hentConfig() {
127
115
return idProviderConfigs ;
128
116
}
129
117
130
- private static OpenIDConfiguration createOpenAmConfiguration (String wellKnownUrl ) {
131
- return createConfiguration (OpenIDProvider .ISSO ,
132
- Optional .ofNullable (ENV .getProperty (OPEN_AM_CONFIG_ISSUER ))
133
- .or (() -> getIssuerFra (wellKnownUrl ))
134
- .orElseGet (OpenAmProperties ::getIssoIssuerUrl ),
135
- Optional .ofNullable (ENV .getProperty (OPEN_AM_CONFIG_JWKS_URI ))
136
- .or (() -> getJwksFra (wellKnownUrl ))
137
- .orElseGet (OpenAmProperties ::getIssoJwksUrl ),
138
- Optional .ofNullable (ENV .getProperty (OPEN_AM_CONFIG_TOKEN_ENDPOINT ))
139
- .or (() -> getTokenEndpointFra (wellKnownUrl ))
140
- .orElseGet (OpenAmProperties ::getIssoTokenUrl ),
141
- Optional .ofNullable (ENV .getProperty (OPEN_AM_CONFIG_AUTH_ENDPOINT ))
142
- .or (() -> getAuthorizationEndpointFra (wellKnownUrl ))
143
- .orElseGet (OpenAmProperties ::getIssoAuthUrl ),
144
- false , null ,
145
- Optional .ofNullable (ENV .getProperty (OPEN_AM_CLIENT_ID ))
146
- .orElseGet (OpenAmProperties ::getIssoUserName ),
147
- Optional .ofNullable (ENV .getProperty (OPEN_AM_CLIENT_SECRET ))
148
- .orElseGet (OpenAmProperties ::getIssoPassword ),
149
- true );
150
- }
151
-
152
118
private static OpenIDConfiguration createStsConfiguration (String wellKnownUrl ) {
153
119
return createConfiguration (OpenIDProvider .STS ,
154
120
Optional .ofNullable (ENV .getProperty (STS_CONFIG_ISSUER ))
155
- .or (() -> getIssuerFra (wellKnownUrl ))
156
- .orElseGet (() -> ENV .getProperty ("oidc.sts.issuer.url" )),
121
+ .or (() -> getIssuerFra (wellKnownUrl )).orElse (null ),
157
122
Optional .ofNullable (ENV .getProperty (STS_CONFIG_JWKS_URI ))
158
- .or (() -> getJwksFra (wellKnownUrl ))
159
- .orElseGet (() -> ENV .getProperty ("oidc.sts.jwks.url" )),
123
+ .or (() -> getJwksFra (wellKnownUrl )).orElse (null ),
160
124
Optional .ofNullable (ENV .getProperty (STS_CONFIG_TOKEN_ENDPOINT ))
161
- .or (() -> getTokenEndpointFra (wellKnownUrl ))
162
- .orElseGet (OidcProviderConfig ::tokenEndpointFromLegacySTS ),
163
- null ,
125
+ .or (() -> getTokenEndpointFra (wellKnownUrl )).orElse (null ),
164
126
false , null ,
165
127
ENV .getProperty ("systembruker.username" ),
166
- null ,
128
+ ENV . getProperty ( "systembruker.password" ) ,
167
129
true );
168
130
}
169
131
170
- private static String tokenEndpointFromLegacySTS () {
171
- var issuer = ENV .getProperty ("oidc.sts.issuer.url" );
172
- var endpointpath = Optional .ofNullable (ENV .getProperty ("oidc.sts.token.path" )).orElse ("/rest/v1/sts/token" );
173
- return issuer != null ? issuer + endpointpath : null ;
174
- }
175
-
176
132
@ SuppressWarnings ("unused" )
177
133
private static OpenIDConfiguration createAzureAppConfiguration (String wellKnownUrl ) {
178
134
var useProxy = ENV .isLocal () ? null : URI .create (ENV .getProperty (AZURE_HTTP_PROXY , getDefaultProxy ()));
@@ -183,9 +139,6 @@ private static OpenIDConfiguration createAzureAppConfiguration(String wellKnownU
183
139
.orElseGet (() -> getJwksFra (wellKnownUrl , useProxy ).orElse (null )),
184
140
Optional .ofNullable (ENV .getProperty (AZURE_CONFIG_TOKEN_ENDPOINT ))
185
141
.orElseGet (() -> getTokenEndpointFra (wellKnownUrl , useProxy ).orElse (null )),
186
- Optional .ofNullable (ENV .getProperty (AZURE_CONFIG_TOKEN_ENDPOINT ))
187
- .map (s -> s .replace ("/token" , "/authorize" ))
188
- .orElseGet (() -> getAuthorizationEndpointFra (wellKnownUrl , useProxy ).orElse (null )),
189
142
!ENV .isLocal (), useProxy ,
190
143
ENV .getRequiredProperty (AZURE_CLIENT_ID ),
191
144
ENV .getProperty (AZURE_CLIENT_SECRET ),
@@ -197,7 +150,6 @@ private static OpenIDConfiguration createTokenXConfiguration(String wellKnownUrl
197
150
getIssuerFra (wellKnownUrl ).orElseThrow (),
198
151
getJwksFra (wellKnownUrl ).orElseThrow (),
199
152
getTokenEndpointFra (wellKnownUrl ).orElse (null ),
200
- getAuthorizationEndpointFra (wellKnownUrl ).orElse (null ),
201
153
false , null ,
202
154
ENV .getRequiredProperty (TOKEN_X_CLIENT_ID ),
203
155
null , // Signerer requests med jws
@@ -208,7 +160,6 @@ private static OpenIDConfiguration createConfiguration(OpenIDProvider type,
208
160
String issuer ,
209
161
String jwks ,
210
162
String tokenEndpoint ,
211
- String authorizationEndpoint ,
212
163
boolean useProxyForJwks ,
213
164
URI proxy ,
214
165
String clientName ,
@@ -218,7 +169,6 @@ private static OpenIDConfiguration createConfiguration(OpenIDProvider type,
218
169
tilURI (issuer , "issuer" , type ),
219
170
tilURI (jwks , "jwksUri" , type ),
220
171
tokenEndpoint != null ? tilURI (tokenEndpoint , "tokenEndpoint" , type ) : null ,
221
- authorizationEndpoint != null ? tilURI (authorizationEndpoint , "authorizationEndpoint" , type ) : null ,
222
172
useProxyForJwks ,
223
173
proxy ,
224
174
Objects .requireNonNull (clientName ),
0 commit comments