Skip to content

Commit

Permalink
Merge pull request #3648 from DedunuKarunarathne/graceful-start
Browse files Browse the repository at this point in the history
Handle null pointers in server startup
  • Loading branch information
DedunuKarunarathne authored Oct 1, 2024
2 parents 5545f5f + da870c5 commit d2bcfcf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.synapse.rest.RESTConstants;
import org.apache.synapse.rest.RESTUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -110,7 +111,11 @@ private APIResource findResource(MessageContext synCtx, InternalAPI internalApi)
subPath = "/";
}

for (APIResource resource : internalApi.getResources()) {
APIResource[] resources = internalApi.getResources();
if (resources == null) {
return null;
}
for (APIResource resource : resources) {
if (!resource.getMethods().contains(method)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ public Set<String> getMethods() {
public boolean invoke(MessageContext messageContext, org.apache.axis2.context.MessageContext axis2MessageContext,
SynapseConfiguration synapseConfiguration) {

if (!JWTConfig.getInstance().getJwtConfigDto().isJwtHandlerEngaged()) {
JWTConfig jwtConfig = JWTConfig.getInstance();
if (jwtConfig == null || jwtConfig.getJwtConfigDto() == null) {
handleServerError(axis2MessageContext, "JWT configuration error");
return true;
}
if (!jwtConfig.getJwtConfigDto().isJwtHandlerEngaged()) {
LOG.error("/Login is accessible only when JWT based auth handler is engaged");
handleServerError(axis2MessageContext, "Login is accessible only when JWT based auth handler is engaged");
return true;
}

//Init token store
JWTTokenStore tokenStore =
JWTInMemoryTokenStore.getInstance(JWTConfig.getInstance().getJwtConfigDto().getTokenStoreSize());
JWTInMemoryTokenStore.getInstance(jwtConfig.getJwtConfigDto().getTokenStoreSize());

//UUID used as unique token
UUID uuid = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private static void setTokenStore(Map<String, JWTTokenInfoDTO> tokenStore) {

@Override
public JWTTokenInfoDTO getToken(String token) {
if (getTokenStore() == null) {
return null;
}
return getTokenStore().get(token);
}

Expand Down

0 comments on commit d2bcfcf

Please sign in to comment.