Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-9.0.0' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rbioteau committed Oct 17, 2023
2 parents 547e4d3 + 50b4c1b commit 71ebe0f
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 29 deletions.
2 changes: 2 additions & 0 deletions bonita-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ dependencyManagement {
dependency "com.bonitasoft.engine:bonita-client-sp:${project.version}"

// Web extensions dependencies:
dependency "org.bonitasoft.console:bonita-web-server:${project.version}"
dependency "org.bonitasoft.console:bonita-web-server-sp:${project.version}"
dependency "org.bonitasoft.web:bonita-web-extensions:${project.version}"
dependency "com.bonitasoft.web:bonita-web-extensions-sp:${project.version}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ ProcessDefinition deployAndEnableProcess(BusinessArchive businessArchive)
* @throws UpdateException
* If an exception occurs when updating the process deployment information.
* @since 6.0
* @deprecated as of 9.0.0, Process should be updated at startup.
*/
@Deprecated(since = "9.0.0")
void updateProcessDeploymentInfo(long processDefinitionId,
ProcessDeploymentInfoUpdater processDeploymentInfoUpdater)
throws ProcessDefinitionNotFoundException, UpdateException;
Expand Down Expand Up @@ -423,7 +425,9 @@ List<ProcessDeploymentInfo> getProcessDeploymentInfos(int startIndex, int maxRes
* @throws UpdateException
* If an exception occurs when updating the actor.
* @since 6.0
* @deprecated as of 9.0.0, Actor should be updated at startup.
*/
@Deprecated(since = "9.0.0")
ActorInstance updateActor(long actorId, ActorUpdater actorUpdater) throws ActorNotFoundException, UpdateException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ public void modifyTechnicalUser(long tenantId, String userName, String password)
Properties properties = new Properties();
properties.load(new ByteArrayInputStream(bonitaConfiguration.getResourceContent()));
if (userName != null) {
properties.setProperty("userName", userName);
properties.setProperty("bonita.runtime.admin.username", userName);
}
if (password != null) {
properties.setProperty("userPassword", password);
properties.setProperty("bonita.runtime.admin.password", password);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
properties.store(out, "");
Expand Down
3 changes: 3 additions & 0 deletions bpm/bonita-core/bonita-login/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ dependencies {
testImplementation "org.mockito:mockito-core:${Deps.mockitoVersion}"
testImplementation "org.assertj:assertj-core:${Deps.assertjVersion}"
testImplementation "ch.qos.logback:logback-classic:${Deps.logbackVersion}"

compileOnly "org.projectlombok:lombok:${Deps.lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${Deps.lombokVersion}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,25 @@
**/
package org.bonitasoft.engine.core.login;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
* @author Matthieu Chaffotte
*/
@lombok.Data
@Component
public class TechnicalUser {

private String userName;

private String password;

public TechnicalUser(final String userName, final String password) {
public TechnicalUser(
@Value("${bonita.runtime.admin.username}") final String userName,
@Value("${bonita.runtime.admin.password}") final String password) {
super();
this.userName = userName;
this.password = password;
}

public String getUserName() {
return userName;
}

public String getPassword() {
return password;
}

public void setUserName(String userName) {
this.userName = userName;
}

public void setPassword(String password) {
this.password = password;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,11 @@ public long getNumberOfMembershipsOfActor(final long actorId) {
return getNumber.getResult();
}

/**
* {@inheritDoc}
*/
@Override
@Deprecated(since = "9.0.0")
public ActorInstance updateActor(final long actorId, final ActorUpdater descriptor)
throws ActorNotFoundException, UpdateException {
if (descriptor == null || descriptor.getFields().isEmpty()) {
Expand Down Expand Up @@ -2748,7 +2752,11 @@ public void releaseUserTask(final long userTaskId) throws ActivityInstanceNotFou
}
}

/**
* {@inheritDoc}
*/
@Override
@Deprecated(since = "9.0.0")
public void updateProcessDeploymentInfo(final long processDefinitionId,
final ProcessDeploymentInfoUpdater processDeploymentInfoUpdater)
throws ProcessDefinitionNotFoundException, UpdateException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.StandardEnvironment;

/**
* Spring bean accessor that get its configuration from configuration file in classpath and in database
Expand Down Expand Up @@ -89,7 +90,20 @@ private void configureContext(BonitaSpringContext context) throws IOException {
}

MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
propertySources.addFirst(new PropertiesPropertySource("contextProperties", getProperties()));
final boolean legacyMode = context.getEnvironment().getProperty("bonita.runtime.properties.order.legacy-mode",
boolean.class, false);
if (legacyMode) {
// continue to have properties files from database with the higher priority order.
propertySources.addFirst(new PropertiesPropertySource("contextProperties", getProperties()));
} else {
// Make values from database be easily overridable with default Spring mechanism.
// This is achieved by adding Bonita properties from database with a priority just AFTER
// OS environment variables and Java System properties.
// For default Spring property order, see
// https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config
propertySources.addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
new PropertiesPropertySource("contextProperties", getProperties()));
}
}

protected BonitaSpringContext createContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1954,11 +1954,6 @@
<constructor-arg name="pageMappingService" ref="pageMappingService" />
</bean>

<bean id="technicalUser" class="org.bonitasoft.engine.core.login.TechnicalUser">
<constructor-arg name="userName" value="${userName}" />
<constructor-arg name="password" value="${userPassword}" />
</bean>

<bean id="genericAuthenticationServiceAccessor"
class="org.bonitasoft.engine.authentication.GenericAuthenticationServiceAccessor">
<constructor-arg ref="${authentication.service.ref.name:authenticationService}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bonita Tenant server core configuration
userName=install
userPassword=install
bonita.runtime.admin.username=install
bonita.runtime.admin.password=install

# Business data configuration
bdm.db.vendor=${sysprop.bonita.bdm.db.vendor:h2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,44 @@ public void should_populate_environment_with_properties() {
}

@Test
public void should_create_context_with_properties_from_database_that_override_env() {
public void should_create_context_with_properties_from_env_that_override_database() {
contextProperties.setProperty("myProperty", "databaseValue");
envVar.set("myProperty", "envValue");
createSpringContext();

ApplicationContext context = springBeanAccessor.getContext();

assertThat(context.getEnvironment().getProperty("myProperty")).isEqualTo("envValue");
}

@Test
public void should_create_context_with_properties_from_system_properties_that_override_database() {
contextProperties.setProperty("myProperty", "databaseValue");
System.setProperty("myProperty", "sysPropValue");
createSpringContext();

ApplicationContext context = springBeanAccessor.getContext();

assertThat(context.getEnvironment().getProperty("myProperty")).isEqualTo("sysPropValue");
}

@Test
public void should_property_from_database_take_precedence_on_env_if_legacy_mode() {
contextProperties.setProperty("myProperty", "databaseValue");
envVar.set("myProperty", "envValue");
envVar.set("BONITA_RUNTIME_PROPERTIES_ORDER_LEGACY_MODE", "true");
createSpringContext();

ApplicationContext context = springBeanAccessor.getContext();

assertThat(context.getEnvironment().getProperty("myProperty")).isEqualTo("databaseValue");
}

@Test
public void should_create_context_with_properties_from_database_that_override_system_properties() {
public void should_property_from_database_take_precedence_on_sysProp_if_legacy_mode() {
contextProperties.setProperty("myProperty", "databaseValue");
System.setProperty("myProperty", "sysPropValue");
System.setProperty("bonita.runtime.properties.order.legacy-mode", "true");
createSpringContext();

ApplicationContext context = springBeanAccessor.getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public BusinessDataModelResource(final TenantAdministrationAPI tenantAdministrat
this.tenantAdministrationAPI = tenantAdministrationAPI;
}

/**
* @deprecated as of 9.0.0. The BDM should only be updated at startup.
*/
@Post("json")
@Deprecated(since = "9.0.0")
public TenantResourceItem addBDM(final BusinessDataModelItem businessDataModelItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ public PageItem get(final APIID id) {
return getPageDatastore().get(id);
}

/**
* @deprecated as of 9.0.0, a page should be created at startup.
*/
@Override
@Deprecated(since = "9.0.0")
public PageItem add(final PageItem item) {
return getPageDatastore().add(item);
}

/**
* @deprecated as of 9.0.0, a page should be updated at startup.
*/
@Override
@Deprecated(since = "9.0.0")
public PageItem update(final APIID id, final Map<String, String> attributes) {
return getPageDatastore().update(id, attributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bonitasoft.console.common.server.utils.SessionUtil;
import org.bonitasoft.engine.bpm.contract.ContractViolationException;
import org.bonitasoft.engine.exception.NotFoundException;
import org.bonitasoft.engine.exception.TenantStatusException;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.session.APISession;
Expand Down Expand Up @@ -195,6 +196,9 @@ protected void doCatch(final Throwable throwable) {
} else if (t instanceof InvalidSessionException) {
status = Status.CLIENT_ERROR_UNAUTHORIZED;
SessionUtil.sessionLogout(getHttpSession());
} else if (t instanceof TenantStatusException) {
status = Status.SERVER_ERROR_SERVICE_UNAVAILABLE;
errorMessage.setMessage("Platform is under maintenance");
} else {
super.doCatch(t);
status = getStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public PageDatastore(final APISession engineSession, final WebBonitaConstantsUti
this.pageContentValidator = new CustomPageContentValidator();
}

/**
* @deprecated as of 9.0.0, a page should be created at startup.
*/
@Override
@Deprecated(since = "9.0.0")
public PageItem add(final PageItem pageItem) {
Expand Down Expand Up @@ -290,6 +293,9 @@ protected SearchResult<Page> runSearch(final SearchOptionsCreator creator)
return pageAPI.searchPages(creator.create());
}

/**
* @deprecated as of 9.0.0, a page should be updated at startup.
*/
@Override
@Deprecated(since = "9.0.0")
public PageItem update(final APIID id, final Map<String, String> attributes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.servlet.http.HttpSession;

import org.bonitasoft.engine.exception.TenantStatusException;
import org.bonitasoft.engine.session.InvalidSessionException;
import org.bonitasoft.web.rest.server.framework.APIServletCall;
import org.bonitasoft.web.rest.server.utils.FakeResource;
Expand Down Expand Up @@ -292,6 +293,17 @@ public void should_respond_400_bad_request_if_IllegalArgumentException_occurs()
"{\"exception\":\"class java.lang.IllegalArgumentException\",\"message\":\"an error message\"}'");
}

@Test
public void should_respond_503_service_unavailable_if_TenantStatusException_occurs() throws Exception {
when(fakeService.saySomething()).thenThrow(new TenantStatusException("an error message"));

final Response response = request("/test").get();

assertThat(response).hasStatus(Status.SERVER_ERROR_SERVICE_UNAVAILABLE);
assertThat(response).hasJsonEntityEqualTo(
"{\"exception\":\"class org.bonitasoft.engine.exception.TenantStatusException\",\"message\":\"Platform is under maintenance\"}'");
}

@Test
public void should_respond_401_unauthorized_if_InvalidSessionException_occurs() throws Exception {
when(fakeService.saySomething()).thenThrow(new InvalidSessionException("an error message"));
Expand Down

0 comments on commit 71ebe0f

Please sign in to comment.