Skip to content

Commit 3fd9907

Browse files
committed
wip
Signed-off-by: Richard Salac <richard.salac@broadcom.com>
1 parent 871dbc0 commit 3fd9907

22 files changed

Lines changed: 51 additions & 396 deletions

File tree

api-catalog-services/src/main/java/org/zowe/apiml/apicatalog/config/SecurityConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ WebFilter tokenAuthenticationFilter(
322322
}
323323
})
324324
.map(pair -> ReactiveSecurityContextHolder.withAuthentication(
325-
//TODO: WTF?! token used as username?
326325
createAuthenticated(pair.getValue().getUserId(), pair.getKey(), TokenAuthentication.Type.JWT)
327326
))
328327
.orElse(context)

apiml-security-common/src/main/java/org/zowe/apiml/security/common/token/TokenAuthentication.java

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,26 @@
3131
public class TokenAuthentication extends AbstractAuthenticationToken {
3232

3333
@Serial
34-
//TODO: regenerate
3534
private static final long serialVersionUID = 82346593850419807L;
3635

3736
private static final String DOMAIN_CLAIM_NAME = "dom";
3837
private static final String SCOPES = "scopes";
3938

4039

40+
@Getter
4141
private final JWT jwt;
4242
private final JWTClaimsSet claims;
43+
@Getter
4344
private final QueryResponse queryResponse;
4445

4546
@Getter
4647
private Type type;
4748

49+
public enum Type {
50+
JWT,
51+
OIDC
52+
}
53+
4854
public TokenAuthentication(String tokenString) {
4955
this(tokenString, (Type) null);
5056
}
@@ -89,10 +95,6 @@ public static TokenAuthentication createAuthenticated(String userId, String toke
8995
return tokenAuthentication;
9096
}
9197

92-
public JWT getJwt() {
93-
return jwt;
94-
}
95-
9698
public boolean isExpired() {
9799
return queryResponse.isExpired();
98100
}
@@ -109,24 +111,6 @@ public String getClaimAsString(String claimName) throws ParseException {
109111
return claims.getClaimAsString(claimName);
110112
}
111113

112-
public QueryResponse getQueryResponse() {
113-
return queryResponse;
114-
}
115-
116-
// public TokenAuthenticationEnhanced(String token, Type type) {
117-
// this(null, token, type);
118-
// }
119-
//
120-
// public TokenAuthenticationEnhanced(String username, String token) {
121-
// this(username, token, (Type) null);
122-
// }
123-
//
124-
// public TokenAuthenticationEnhanced(String username, String token, Type type) {
125-
// super(Collections.emptyList());
126-
// this.token = token;
127-
// this.type = type;
128-
// }
129-
130114
/**
131115
* @return the token that prove the username is correct
132116
*/
@@ -144,29 +128,12 @@ public String getPrincipal() {
144128
return queryResponse.getUserId();
145129
}
146130

147-
// /**
148-
// * Creates the TokenAuthentication with fulfilled username (principal), token and marked as authenticated.
149-
// * @param username Username, who is authenticated
150-
// * @param token Token, which authenticate the user
151-
// * @return TokenAuthentication marked as authenticated with username, token
152-
// */
153-
// public static TokenAuthenticationEnhanced createAuthenticated(String username, String token, Type type) {
154-
// final TokenAuthenticationEnhanced out = new TokenAuthenticationEnhanced(username, token, type);
155-
// out.setAuthenticated(true);
156-
// return out;
157-
// }
158-
159131
@SuppressWarnings("squid:S3655")
160132
public static TokenAuthentication createAuthenticatedFromHeader(String token, String authHeader) {
161133
var loginRequest = LoginFilter.getCredentialFromAuthorizationHeader(Optional.of(authHeader));
162134
return createAuthenticated(loginRequest.get().getUsername(), token, Type.JWT);
163135
}
164136

165-
public enum Type {
166-
JWT,
167-
OIDC
168-
}
169-
170137
private QueryResponse parseQueryResponse(JWTClaimsSet claims) {
171138
Object scopesObject = claims.getClaim(SCOPES);
172139
List<String> scopes = Collections.emptyList();

apiml-security-common/src/main/java/org/zowe/apiml/security/common/token/TokenAuthentication_BCK.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

apiml-security-common/src/main/java/org/zowe/apiml/security/common/util/JwtUtils.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ public class JwtUtils {
4545
* @throws TokenNotValidException in case of invalid input, or TokenExpireException if JWT is expired
4646
*/
4747
public JWTClaimsSet getJwtClaims(String jwt) {
48-
return getJwtClaimsInternal(jwt, true);
49-
}
50-
51-
/**
52-
* This method reads the claims without validating the token signature. It should be used only if the validity was checked in the calling code. Ignores token expiration.
53-
*
54-
* @param jwt token to be parsed
55-
* @return parsed claims
56-
* @throws TokenNotValidException in case of invalid input
57-
*/
58-
public JWTClaimsSet getJwtClaimsIgnoreExpiration(String jwt) {
59-
return getJwtClaimsInternal(jwt, false);
60-
}
61-
62-
private JWTClaimsSet getJwtClaimsInternal(String jwt, boolean validateExpiration) {
6348
/*
6449
* Removes signature, because we don't have key to verify z/OS tokens, and we just need to read claim.
6550
* Verification is done by SAF itself. JWT library doesn't parse signed key without verification.
@@ -69,10 +54,9 @@ private JWTClaimsSet getJwtClaimsInternal(String jwt, boolean validateExpiration
6954
var token = JWTParser.parse(jwtWithoutSignature);
7055
var claims = token.getJWTClaimsSet();
7156

72-
if (validateExpiration && claims.getExpirationTime().toInstant().isBefore(Instant.now())) {
57+
if (claims.getExpirationTime().toInstant().isBefore(Instant.now())) {
7358
throw new ExpiredJWTException("JWT token is expired");
7459
}
75-
7660
return token.getJWTClaimsSet();
7761
} catch (RuntimeException | ParseException | BadJWTException exception) {
7862
throw handleJwtParserException(exception);

apiml/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ dependencies {
8787
testImplementation libs.rest.assured.web.test.client
8888
testImplementation libs.opentelemetry.sdk.testing
8989
testImplementation libs.opentelemetry.sdk.extension.autoconfigure.spi
90-
testImplementation libs.bundles.infinispan
9190

9291
compileOnly libs.lombok
9392
annotationProcessor libs.lombok

apiml/src/test/java/org/zowe/apiml/acceptance/CachesConfigurationTest.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

apiml/src/test/java/org/zowe/apiml/filter/OIDCAuthFilterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.zowe.apiml.security.common.config.AuthConfigurationProperties;
3030
import org.zowe.apiml.security.common.token.OIDCProvider;
3131
import org.zowe.apiml.security.common.token.TokenAuthentication;
32+
import org.zowe.apiml.security.common.util.JWTTestUtils;
3233
import org.zowe.apiml.zaas.security.mapping.AuthenticationMapper;
3334
import org.zowe.apiml.zaas.security.service.schema.source.OIDCAuthSource;
3435
import reactor.core.publisher.Mono;
@@ -46,8 +47,8 @@
4647
@ExtendWith(MockitoExtension.class)
4748
class OIDCAuthFilterTest {
4849

49-
private static final String OIDC_TOKEN = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InRlc3Qta2V5In0.eyJzdWIiOiJ0ZXN0dXNlckBleGFtcGxlLmNvbSIsImlhdCI6MTcxMTUyMDAwMCwiZXhwIjo5OTk5OTk5OTk5fQ.fake-signature";
5050
private static final String MAINFRAME_USER = "TESTUSER";
51+
public static final String OIDC_TOKEN = JWTTestUtils.createDummyJwtToken(MAINFRAME_USER, "https://oidc.provider");
5152
private static final List<String> USER_ID_FIELD_PATH = List.of("sub");
5253

5354
@Mock private OIDCProvider oidcProvider;
@@ -184,7 +185,7 @@ void thenSkipOidcValidation() {
184185
var exchange = MockServerWebExchange.from(request);
185186
when(chain.filter(exchange)).thenReturn(Mono.empty());
186187

187-
Authentication existingAuth = TokenAuthentication.createAuthenticated("EXISTING_USER", "some-jwt", TokenAuthentication.Type.JWT);
188+
Authentication existingAuth = TokenAuthentication.createAuthenticated("EXISTING_USER", JWTTestUtils.createDummyAPIMLToken("EXISTING_USER"), TokenAuthentication.Type.JWT);
188189
var securityContext = new SecurityContextImpl(existingAuth);
189190

190191
var result = filter.filter(exchange, chain)

caching-service/src/main/java/org/zowe/apiml/caching/service/infinispan/config/InfinispanConfig.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ synchronized LazyCacheManager cacheManager(ResourceLoader resourceLoader, Applic
212212
if (applicationInfo.isModulith()) {
213213
caches = new HashMap<>();
214214

215-
//Security distributed caches
216-
//TODO resolve size and lifespan
217215
caches.put(CACHE_ZOWE, getDistributedCacheConfig());
218216
caches.put(CACHE_ZOWE_INVALIDATED_TOKEN, getDistributedCacheConfig());
219217
caches.put("invalidatedJwtTokens", getDistributedCacheConfig());
@@ -232,9 +230,8 @@ synchronized LazyCacheManager cacheManager(ResourceLoader resourceLoader, Applic
232230

233231
} else {
234232
caches = new HashMap<>();
235-
//TODO resolve size and lifespan
236-
var defaultCacheconfig = getDistributedCacheConfig();
237-
Arrays.asList(CACHE_ZOWE, CACHE_ZOWE_INVALIDATED_TOKEN).forEach( c -> caches.put(c,defaultCacheconfig));
233+
var defaultCacheConfig = getDistributedCacheConfig();
234+
Arrays.asList(CACHE_ZOWE, CACHE_ZOWE_INVALIDATED_TOKEN).forEach( c -> caches.put(c,defaultCacheConfig));
238235
}
239236

240237
return new LazyCacheManager(getCacheManagerConfig(resourceLoader), caches);

caching-service/src/main/java/org/zowe/apiml/caching/service/infinispan/config/LazyCacheManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ private boolean createCache(String cacheName) {
326326
try {
327327
underInit.defineConfiguration(cacheName, cacheConfig);
328328
} catch (Exception e) {
329-
//Todo improve message
330329
log.warn("Configuration for cache {} already exists", cacheName, e);
331330
}
332331
} catch (Exception e) {

caching-service/src/main/resources/infinispan-attls.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@
6565

6666
<serialization marshaller="org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller">
6767
<allow-list>
68-
<class>org.zowe.apiml.caching.model.KeyValue</class>
69-
<class>org.zowe.apiml.security.common.token.TokenAuthentication_BCK</class>
70-
<class>org.zowe.apiml.security.common.token.TokenAuthentication_BCK$Type</class>
71-
<class>java.util.HashMap</class>
72-
<class>java.util.Arrays$ArrayList</class>
73-
<class>java.security.cert.Certificate$CertificateRep</class>
68+
<regex>org.zowe.apiml.caching.*</regex>
69+
<regex>org.zowe.apiml.security.common.token.*</regex>
70+
<regex>com.nimbusds.jwt.*</regex>
71+
<regex>com.nimbusds.jose.*</regex>
72+
<regex>java.util.*</regex>
73+
<regex>java.security.cert.*</regex>
7474
</allow-list>
7575
</serialization>
7676

0 commit comments

Comments
 (0)