Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed auth health check when auth is disabled and Swagger api #269

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

@Configuration
@EnableWebSecurity
@ConditionalOnProperty(name = "authentication.enabled",havingValue = "true",matchIfMissing = false)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Value("${authentication.enabled:true}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.StatelessKieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import dev.sunbirdrc.registry.identity_providers.pojos.IdentityManager;

Expand All @@ -19,24 +21,26 @@
public class RuleEngineService {
private final KieContainer kieContainer;
private final IdentityManager identityManager;
private final boolean authenticationEnabled;
private static final String PATH = "path";

@Autowired
public RuleEngineService(KieContainer kieContainer, IdentityManager identityManager) {
public RuleEngineService(KieContainer kieContainer,@Nullable IdentityManager identityManager, @Value("${authentication.enabled:true}") boolean authenticationEnabled) {
this.kieContainer = kieContainer;
this.identityManager = identityManager;
this.authenticationEnabled = authenticationEnabled;
}

public void doTransition(List<StateContext> stateContexts) {
StatelessKieSession kieSession = kieContainer.newStatelessKieSession();
kieSession.setGlobal("identityManager", identityManager);
if(authenticationEnabled) kieSession.setGlobal("identityManager", identityManager);
kieSession.setGlobal("ruleEngineService", this);
kieSession.execute(stateContexts);
}

public void doTransition(StateContext stateContext) {
StatelessKieSession kieSession = kieContainer.newStatelessKieSession();
kieSession.setGlobal("identityManager", identityManager);
if(authenticationEnabled) kieSession.setGlobal("identityManager", identityManager);
kieSession.setGlobal("ruleEngineService", this);
kieSession.execute(stateContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class StateContext {
private JsonPointer pointerFromMetadataNode;
private OwnershipsAttributes ownershipAttribute;
private Boolean loginEnabled;
private boolean authenticationEnabled;

@Builder.Default
private boolean revertSystemFields = false;
Expand Down Expand Up @@ -143,4 +144,12 @@ public Boolean getLoginEnabled() {
public void setLoginEnabled(Boolean loginEnabled) {
this.loginEnabled = loginEnabled;
}

public Boolean isAuthenticationEnabled() {
return this.authenticationEnabled;
}

public void setAuthenticationEnabled(Boolean authenticationEnabled) {
this.authenticationEnabled = authenticationEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end

rule "Create entity owner for newly added owner fields"
when
stateDefinition:StateContext(isOwnershipProperty() && isOwnerNewlyAdded() && isLoginEnabled());
stateDefinition:StateContext(isAuthenticationEnabled() && isOwnershipProperty() && isOwnerNewlyAdded() && isLoginEnabled());
then
CreateUserRequest createUserRequest = new CreateUserRequest(stateDefinition.getEntityName(),
stateDefinition.getUpdated().get("userId").textValue(), stateDefinition.getUpdated().get("email").textValue(),
Expand All @@ -50,7 +50,7 @@ end

rule "Revert if any modification to ownership details"
when
stateDefinition:StateContext(isOwnershipProperty() && !isOwnerNewlyAdded() && isOwnershipDetailsUpdated());
stateDefinition:StateContext(isAuthenticationEnabled() && isOwnershipProperty() && !isOwnerNewlyAdded() && isOwnershipDetailsUpdated());
then
ruleEngineService.revertOwnershipDetails(stateDefinition);
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ public RegistryService registryService() {
// return auditService;
// }

@ConditionalOnProperty(name = "authentication.enabled", havingValue = "true", matchIfMissing = true)
@Bean
public IdentityManager identityManager() {
ServiceLoader<IdentityProvider> loader = ServiceLoader.load(IdentityProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ public class EntityStateHelper {
private Boolean setDefaultPassword;
@Value("${identity.default_password}")
private String defaultPassword;
private final boolean authenticationEnabled;

@Autowired
public EntityStateHelper(IDefinitionsManager definitionsManager, RuleEngineService ruleEngineService,
ConditionResolverService conditionResolverService,@Nullable ClaimRequestClient claimRequestClient) {
ConditionResolverService conditionResolverService,@Nullable ClaimRequestClient claimRequestClient,
@Value("${authentication.enabled:true}") boolean authenticationEnabled) {
this.definitionsManager = definitionsManager;
this.ruleEngineService = ruleEngineService;
this.conditionResolverService = conditionResolverService;
this.claimRequestClient = claimRequestClient;
this.authenticationEnabled = authenticationEnabled;
}

JsonNode applyWorkflowTransitions(JsonNode existing, JsonNode updated, List<AttestationPolicy> attestationPolicies) throws IOException {
Expand Down Expand Up @@ -98,6 +101,7 @@ private void addSystemFieldsStateTransition(JsonNode existing, JsonNode modified
.metadataNode((ObjectNode) modified)
.revertSystemFields(true)
.loginEnabled(definitionsManager.getDefinition(entityName).getOsSchemaConfiguration().getEnableLogin())
.authenticationEnabled(authenticationEnabled)
.build();
allContexts.add(stateContext);
}
Expand All @@ -124,6 +128,7 @@ private void addOwnershipStateTransitions(JsonNode existing, String entityName,
.metadataNode((ObjectNode) modified.get(entityName))
.ownershipAttribute(ownershipAttribute)
.loginEnabled(definitionsManager.getDefinition(entityName).getOsSchemaConfiguration().getEnableLogin())
.authenticationEnabled(authenticationEnabled)
.build();
allContexts.add(stateContext);
}
Expand Down Expand Up @@ -173,6 +178,7 @@ private void addAttestationStateTransitions(JsonNode existing, String entityName
.metadataNode(metadataNodePointer.getFirst())
.pointerFromMetadataNode(metadataNodePointer.getSecond())
.loginEnabled(definitionsManager.getDefinition(entityName).getOsSchemaConfiguration().getEnableLogin())
.authenticationEnabled(authenticationEnabled)
.build();
allContexts.add(stateContext);
}
Expand All @@ -198,6 +204,7 @@ JsonNode manageState(AttestationPolicy policy, JsonNode root, String propertyURL
.metaData(metaData)
.metadataNode(metadataNodePointer.getFirst())
.pointerFromMetadataNode(metadataNodePointer.getSecond())
.authenticationEnabled(authenticationEnabled)
.build();
ruleEngineService.doTransition(stateContext);
return root;
Expand Down
2 changes: 1 addition & 1 deletion java/registry/src/main/resources/public/swagger-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "/api/docs/swagger.json",
url: window.location.pathname.split("/").slice(0, -1).join("/") + "/api/docs/swagger.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void initMocks() throws IOException {
}

private void runTest(JsonNode existing, JsonNode updated, JsonNode expected, List<AttestationPolicy> attestationPolicies) throws IOException {
RuleEngineService ruleEngineService = new RuleEngineService(kieContainer, identityManager);
EntityStateHelper entityStateHelper = new EntityStateHelper(definitionsManager, ruleEngineService, conditionResolverService, claimRequestClient);
RuleEngineService ruleEngineService = new RuleEngineService(kieContainer, identityManager, true);
EntityStateHelper entityStateHelper = new EntityStateHelper(definitionsManager, ruleEngineService, conditionResolverService, claimRequestClient, true);
ReflectionTestUtils.setField(entityStateHelper, "uuidPropertyName", "osid");
ReflectionTestUtils.setField(entityStateHelper, "setDefaultPassword", false);
updated = entityStateHelper.applyWorkflowTransitions(existing, updated, attestationPolicies);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public void initMocks() {
registryHelper.setObjectMapper(objectMapper);
MockitoAnnotations.initMocks(this);
registryHelper.uuidPropertyName = "osid";
RuleEngineService ruleEngineService = new RuleEngineService(kieContainer, identityManager);
registryHelper.entityStateHelper = new EntityStateHelper(definitionsManager, ruleEngineService, conditionResolverService, claimRequestClient);
RuleEngineService ruleEngineService = new RuleEngineService(kieContainer, identityManager, true);
registryHelper.entityStateHelper = new EntityStateHelper(definitionsManager, ruleEngineService, conditionResolverService, claimRequestClient, true);
ReflectionTestUtils.setField(registryHelper.entityStateHelper, "setDefaultPassword", false);
registryHelper.setDefinitionsManager(definitionsManager);
registryHelper.setNotificationEnabled(true);
Expand Down