はじめに
このチュートリアルでは、認証ルールのマッピングをカスタマイズする方法について説明します。
認証ルールは、 getId と isAllowed メソッドを実装する必要がある Java bean です。
認証ルールのマッピングは、接続しているユーザーがページやフォームをアクセスできるようにするために使用される一連のルールです。空のリストは、ユーザーのアクセスを許可します。非空のリストは、すべてのルールが isAllowed メソッドに true を返す場合にアクセスを許可します。次の3つのルールが接続しているユーザのアクセスを許可または拒否をコントロールします。
- プロセスを開始するためのページまたはフォームを使用する
- プロセスの概況を表示する
- タスクを実行するためのページまたはフォームを使用する
チュートリアルでは、Bonita BPM Community エディションを使用し、すべてのエディションで利用できる機能を使用することができます。
以下の要素は、拡張ポイントとして使用することができますが、バージョン間で変更されるかもしれません。変更の予定はありませんが、私たちはすべての将来のバージョンで互換性のない変更を加える権利を留保しています。
カスタム認証ルールを作成してデプロイ
カスタム認証ルールのJavaプロジェクトを作成
このサンプルは、カスタム認証ルールが bonita-server のMaven アーティファクトに maven の依存性を必要とする Maven ベースのJava プロジェクトです。
- pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.bonitasoft.example</groupId>
<artifactId>authorization-tutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.bonitasoft.engine</groupId>
<artifactId>bonita-server</artifactId>
<version>${bonita-server.version}</version>
</dependency>
</dependencies>
<properties>
<bonita-server.version>[7.5.0,)</bonita-server.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
- org.bonitasoft.engine.page.AuthorizationRule を実装する CustomRule クラスを作成します
package org.bonitasoft.example.authorization;
import java.io.Serializable;
import java.util.Map;
import org.bonitasoft.engine.commons.exceptions.SExecutionException;
import org.bonitasoft.engine.core.process.instance.api.ProcessInstanceService;
import org.bonitasoft.engine.page.AuthorizationRule;
import org.bonitasoft.engine.page.AuthorizationRuleWithParameters;
import org.bonitasoft.engine.session.SessionService;
import org.bonitasoft.engine.sessionaccessor.SessionAccessor;
public class CustomRule extends AuthorizationRuleWithParameters implements AuthorizationRule {
private ProcessInstanceService processInstanceService;
private SessionService sessionService;
private SessionAccessor sessionAccessor;
public CustomRule(ProcessInstanceService processInstanceService, SessionService sessionService, SessionAccessor sessionAccessor) {
// some services autowired by spring
this.processInstanceService = processInstanceService;
this.sessionAccessor = sessionAccessor;
this.sessionService = sessionService;
}
@Override
public boolean isAllowed(String key, Map<String, Serializable> context) throws SExecutionException {
//add business logic here
return true;
}
@Override
public String getId() {
return "CUSTOM_RULE_UNIQUE_ID";
}
}
- org.bonitasoft.engine.core.form.AuthorizationRuleMapping を実装する CustomAuthorizationRuleMapping クラスを作成します
package org.bonitasoft.example.authorization;
import java.util.Arrays;
import java.util.List;
import org.bonitasoft.engine.core.form.AuthorizationRuleMapping;
public class CustomAuthorizationRuleMapping implements AuthorizationRuleMapping {
@Override
public List<String> getProcessStartRuleKeys() {
return Arrays.asList("CUSTOM_RULE_UNIQUE_ID");
}
@Override
public List<String> getProcessOverviewRuleKeys() {
return Arrays.asList("CUSTOM_RULE_UNIQUE_ID");
}
@Override
public List<String> getTaskRuleKeys() {
return Arrays.asList("CUSTOM_RULE_UNIQUE_ID");
}
}
- Maven の jar ファイルをビルドします
mvn clean install
新しいルールでエンジンを設定
- webapps/bonita/WEB-INF/lib/ のフォルダ(デフォルトの Tomcat バンドル用)に jar ファイルをコピーします
- プラットフォームのセットアップツールを使用して、現在のエンジン構成を pull します
./setup/setup.sh pull
- platform_conf/current/tenants/TENANT_ID/tenant_engine/bonita-tenant-custom.xml に customRule bean の登録を追加します
<bean id="customRule" class="org.bonitasoft.example.authorization.CustomRule">
<constructor-arg name="processInstanceService" ref="processInstanceService" />
<constructor-arg name="sessionService" ref="sessionService" />
<constructor-arg name="sessionAccessor" ref="sessionAccessor" />
</bean>
- platform_conf/current/tenants/TENANT_ID/tenant_engine/bonita-tenant-custom.xml に customAuthorizationRuleMapping bean の登録を追加します
<bean id="customAuthorizationRuleMapping"
class="org.bonitasoft.example.authorization.CustomAuthorizationRuleMapping"/>
- platform_conf/current/tenants/TENANT_ID/tenant_engine/bonita-tenant-community-custom.properties 内で customAuthorizationRuleMapping を宣言するコメントを解除します
bonita.tenant.authorization.rule.mapping=customAuthorizationRuleMapping
- プラットフォームのセットアップツールを使用して、現在のエンジン構成設定を push します
./setup/setup.sh push
- サーバーを再起動します
./stop-bonita.sh
./start-bonita.sh