Groovyを使用したデータベース・アプリケーション表(Oracle)のカスタム・スクリプトの開発
データベース・アプリケーション表(Oracle)のカスタム・スクリプトの概要
データベース・アプリケーション表の統合を使用してOracle Access Governanceからアカウントをプロビジョニングすると、作成、更新、削除などの操作が、指定されたデフォルト・コードを使用して実装されます。デフォルトで提供される操作を変更する場合は、オプションで、独自の特定のプロビジョニング操作要件を実装する独自のカスタム・スクリプトを指定できます。このステップは完全にオプションであり、デフォルトの操作で必要なものが提供される場合は、カスタム・スクリプトを作成する必要はありません。サポートされている任意の操作にカスタム・スクリプトを追加できます。カスタム・スクリプトを選択した場合は、デフォルトの操作を変更する必要がある場合にのみ追加する必要があります。ただし、サポートされている操作にはカスタム・スクリプトとデフォルト・スクリプトを組み合せて使用できますが、特定の操作ごとに1つのオプションのみを指定できます。たとえば、create操作は、組織に固有の機能を追加するカスタムスクリプトで実装できますが、delete操作は変更されず、デフォルトの機能が使用されます。
カスタム・スクリプトは、Groovy形式を使用して実装する必要があります。その他のスクリプト形式はサポートされていません。
- 作成
- 更新
- 削除
- データロード
- 関係データの追加
- リレーションシップ・データの削除
/app/<custom script> など)のエージェント・ホストに配置する必要があります。オーケストレート済システムの統合設定で、スクリプトの場所を使用してエージェントを構成します。エージェントを実行しているオペレーティング・システム・ユーザーに、カスタム・スクリプトに対する読取り/書込み権限があることを確認する必要があります。- カスタム表更新の実行
- カスタム監査
- カスタム通知の送信
- Database Application Tablesコネクタに用意されているデフォルト・ロジックを使用します。
- スクリプトに実装されたカスタム・ロジックの使用
また、すべてのカスタム・スクリプト・タイプは、管理対象システム・モード用に構成されたオーケストレート済システムでサポートされていることにも注意してください。認可ソース・モードでサポートされているスクリプト・タイプは、両方のモードでサポートされているデータロード・タイプのみです。
サンプル・データベース・スキーマ
次の項で説明するサンプルは、この項で説明するデータベース表に基づいています。
MYDBAT_PERSON
CREATE TABLE MYDBAT_PERSON
(USERID VARCHAR2(50BYTE) NOT NULL ENABLE,
USERNAME VARCHAR2(50BYTE) NOT NULL ENABLE,
FIRSTNAME VARCHAR2(50BYTE),
LASTNAME VARCHAR2(50BYTE),
EMAIL VARCHAR2(50BYTE) NOT NULL ENABLE,
COUNTRYCODE VARCHAR2(20BYTE),
DESCRIPTION VARCHAR2(50BYTE),
SALARY NUMBER,
JOININGDATE DATE,
STATUS VARCHAR2(50BYTE),
LASTUPDATED TIMESTAMP (6),
PASSWORD VARCHAR2(50BYTE),
CONSTRAINT MYDBATPERSON_PK PRIMARY KEY (USERID));
MYDBAT_GROUPS
CREATE TABLE MYDBAT_GROUPS
(GROUPID VARCHAR2(20BYTE) NOT NULL ENABLE,
GROUPNAME VARCHAR2(20BYTE) NOT NULL ENABLE,
CONSTRAINT MYDBATGROUPS_PK PRIMARY KEY (GROUPID));
MYDBAT_ROLES
CREATE TABLE MYDBAT_ROLES
(ROLEID VARCHAR2(50BYTE) NOT NULL ENABLE,
ROLENAME VARCHAR2(50BYTE) NOT NULL ENABLE,
CONSTRAINT MYDBATROLES_PK PRIMARY KEY (ROLEID));
MYDBAT_PERSON_GROUP
CREATE TABLE MYDBAT_PERSON_GROUP
(USERID VARCHAR2(20BYTE) NOT NULL ENABLE,
GROUPID VARCHAR2(20BYTE) NOT NULL ENABLE,
CONSTRAINT "MYDBATPERSONGROUP_PK"PRIMARY KEY (USERID, GROUPID));
MYDBAT_PERSON_ROLE
CREATE TABLE MYDBAT_PERSON_ROLE
(USERID VARCHAR2(20BYTE) NOT NULL ENABLE,
ROLEID VARCHAR2(20BYTE) NOT NULL ENABLE,
FROMDATE DATE,
TODATE DATE,
CONSTRAINT "MYDBATPERSONROLE_PK"PRIMARY KEY (USERID, ROLEID));
MYDBAT_COUNTRY
CREATE TABLE MYDBAT_COUNTRY
(COUNTRYCODE VARCHAR2(20BYTE) NOT NULL ENABLE,
COUNTRYNAME VARCHAR2(200BYTE) NOT NULL ENABLE,
CONSTRAINT MYDBAT_COUNTRY_PK PRIMARY KEY (COUNTRYCODE));
mydbat_roles、mydbat_groups、mydbat_countryなどの子表には、主キー制約が定義されている必要があります。子表に主キーが定義されていない場合、検証操作は失敗し、「表<tablename>のキーが定義されていません」というエラーが表示されます。自動インクリメントのトリガーとシーケンス
CREATE SEQUENCE MYDBAT_PERSON_SEQ MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT
BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE;
create or replace TRIGGER DBAT_PERSON_TRG
BEFORE INSERT ON MYDBAT_PERSON
FOR EACH ROW
BEGIN
<<COLUMN_SEQUENCES>>
BEGIN IF INSERTING AND :NEW.USERID IS NULL THEN
SELECT MYDBAT_PERSON_SEQ.NEXTVAL INTO :NEW.USERID FROM SYS.DUAL;
END IF;
END COLUMN_SEQUENCES;END;
Groovyスクリプト引数
Groovyスクリプトでは、次の引数を使用できます:
| 引数 | 説明 |
|---|---|
| コネクター | Database Application Tablesコネクタ・オブジェクト。 |
| タイミング |
Groovyスクリプトが呼び出されるタイミング。また、timing属性は、実行される操作のタイプも説明します。たとえば、検索操作の場合、検索対象のオブジェクト・クラスも返されます。 次に、参照フィールド同期のtiming引数の書式を示します。
この書式で、OBJECT_CLASSは、リコンサイルされるオブジェクトのタイプに置き換えられます。たとえば、オブジェクト・タイプRoleを含む参照フィールド同期のスケジュール済ジョブの場合は、timing引数の値は次のようになります。
|
| 属性 | すべての属性 |
| トレース | アプリケーションへのスクリプト・トレース・ブリッジとしてのロガー。 |
| 内容 | 問合せの実行の条件の文字列、またはnull。 |
| ハンドラ | 問合せの実行、同期操作、またはNULLの返却により生成されるコネクタ・オブジェクトのresultSetHandlerまたはSyncResultsHandler。 |
| 引用 | SQLで使用される表名の引用符のタイプ。デフォルト値が空の文字列です。この引数の値は、統合設定から取得されます。 |
| nativeTimestamps | スクリプトによって、データベース表からjava.sql.Timestampタイプとして列のタイムスタンプ・データを取得するかどうかを指定します。この情報は、統合設定から取得されます。 |
| allNative | スクリプトによって、データベース表からネイティブ形式で列のデータ型を取得するかどうかを指定します。この引数の値は、統合設定から取得されます。この引数の値によって、ゼロ(0x00)のエラー・コードが出現したときに、スクリプトで例外をスローするかどうかを指定します。 |
| enableEmptyString | NULL値のかわりに空の文字列の書込みのサポートを有効化するかどうかを指定します。この引数の値は、統合設定から取得されます。 |
| filterString | 問合せの実行の文字列フィルタ条件、またはnull。 |
| filterParams | フィルタ・パラメータのリスト。各パラメータは、COLUMN_NAME:VALUEの形式で存在します。たとえば、FIRSTNAME:testです。 |
| 同期属性 | 増分リコンシリエーション用に構成されたデータベース列の名前。この引数は、増分リコンシリエーションの実行中に呼び出される同期スクリプトで使用できます。 |
| シンクトークン | 同期属性の値。この引数は、同期スクリプトで使用できます。 |
サンプルデータロードスクリプト
データ・ロード・スクリプトは、すべての定義済エンティティのすべての表からデータを読み取ります。このシナリオでは、データ・ロードという用語は、完全なデータ・ロードと参照データ・ロードを指します。
このサンプル・スクリプトは、MYDBAT_PERSON表からユーザー・データを読み取り、MYDABAT_PERSON_ROLE表およびMYDBAT_PERSON_GROUP表からユーザーの関係データを読み取ります。権限データはMYDBAT_GROUPS表から読み取られ、参照データはMYDBAT_COUNTRY表から読み取られます。また、MYDBAT_PERSON表での基本的なフィルタ検索もサポートされています。これらのすべてのデータ読取りは、ストアド・プロシージャを使用して行われます。
データロード・スクリプト
import java.sql.CallableStatement;
import java.sql.Connection;
import java.math.*;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.identityconnectors.framework.common.objects.*;
import java.lang.reflect.*;
import java.lang.String;
import org.identityconnectors.common.security.GuardedString;
import java.text.*;
ResultSet rs = null;
CallableStatement st = null;
String ocName ;
try {
if( timing != "")
{
trace.info("[Execute Query] timing attribute value : "+ timing);
ocName = timing.split(":")[1]
}
trace.info("[Execute Query] for objectClass : "+ ocName);
if(ocName.equals("ACCOUNT") || ocName.equals("TARGETACCOUNT")){
if( filterString != "")
{
trace.info("[Execute Query] Performing Recon with Filter. Filter is::"+ filterString+" And Filer Params are::"+filterParams);
//[Execute Query] Performing Recon with Filter. Filter is::MYDBAT_PERSON.USERID = ? And Filer Params are::[MYDBAT_PERSON.USERID:21]
String[] filter = filterParams.get(0).split(":");
st = conn.prepareCall("{call EXECUTE_QUERY_WITH_FILTER(?,?,?)}");
st.setString(2, filter[0]);
st.setString(3, filter[1]);
}
else
{
trace.info("[Execute Query] Performing Full Recon.");
st = conn.prepareCall("{call EXECUTE_QUERY_PERSON(?)}");
}
st.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
st.execute();
rs = (ResultSet) st.getObject(1);
SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
while (rs.next()) {
ConnectorObjectBuilder cob = new ConnectorObjectBuilder();
cob.setObjectClass(ObjectClass.ACCOUNT);
Attribute fname= AttributeBuilder.build(new String("FIRSTNAME"),rs.getString(2));
Attribute lname= AttributeBuilder.build(new String("LASTNAME"),rs.getString(3));
Attribute uid= AttributeBuilder.build(new String("__UID__"),rs.getString(1));
Attribute name= AttributeBuilder.build(new String("__NAME__"),rs.getString(10));
Attribute email= AttributeBuilder.build(new String("EMAIL"),rs.getString(4));
//Attribute salary= AttributeBuilder.build(new String("SALARY"),rs.getBigDecimal(6));
Attribute description= AttributeBuilder.build(new String("DESCRIPTION"),rs.getString(5));
Date dbDate = rs.getDate(7);
String joinDateStr = null;
Long joinDate = null;
if( null != dbDate)
{
java.util.Date date= df.parse(dbDate.toString());
joinDateStr = targetFormat.format(date);
joinDate = date.getTime()
trace.info("date : " +date +" ---- joinDate : "+ joinDate);
}
//Attribute joindate= AttributeBuilder.build(new String("JOININGDATE"),joinDateStr);
if(null != joinDate) {
trace.info("Setting joinDate : "+ joinDate);
Attribute joindate= AttributeBuilder.build(new String("JOININGDATE"),joinDate);
cob.addAttribute(joindate);
}
Attribute status= AttributeBuilder.build(new String("STATUS"),rs.getString(8));
Attribute countryCode= AttributeBuilder.build(new String("COUNTRYCODE"),rs.getString(9));
cob.addAttribute(fname);
cob.addAttribute(lname);
cob.addAttribute(uid);
cob.addAttribute(name);
cob.addAttribute(email);
//cob.addAttribute(salary);
cob.addAttribute(description);
cob.addAttribute(status);
cob.addAttribute(countryCode);
if(ocName.equals("TARGETACCOUNT")){
CallableStatement roleStmt = conn.prepareCall("{call GET_USERROLE(?,?)}");
roleStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
roleStmt.setString(2, rs.getString(1));
roleStmt.execute();
ResultSet roleResultSet = (ResultSet) roleStmt.getObject(1);
java.util.List<EmbeddedObject> eoList = new ArrayList<EmbeddedObject>();
while (roleResultSet.next()) {
Attribute roleId= AttributeBuilder.build(new String("ROLEID"),roleResultSet.getString(2));
dbDate = roleResultSet.getDate(3);
String fromDateStr = null;
Long fromDate = null;
if( null != dbDate)
{
java.util.Date date= df.parse(dbDate.toString());
fromDateStr = targetFormat.format(date);
fromDate = date.getTime()
}
dbDate = roleResultSet.getDate(4);
String toDateStr = null;
Long toDate = null;
if( null != dbDate)
{
java.util.Date date= df.parse(dbDate.toString());
toDateStr = targetFormat.format(date);
toDate = date.getTime()
}
EmbeddedObjectBuilder roleEA = new EmbeddedObjectBuilder();
roleEA.addAttribute(roleId);
if(null != fromDate) {
trace.info("Setting roles fromDate : "+ fromDate);
Attribute fromdate= AttributeBuilder.build(new String("FROMDATE"),fromDate);
roleEA.addAttribute(fromdate);
}
if(null != toDate) {
trace.info("Setting roles toDate : "+ toDate);
Attribute todate= AttributeBuilder.build(new String("TODATE"),toDate);
roleEA.addAttribute(todate);
}
roleEA.setObjectClass(new ObjectClass("MYDBAT_ROLES"));
eoList.add(roleEA.build());
}
roleResultSet.close();
roleStmt.close();
EmbeddedObject[] roleEm = eoList.toArray(new EmbeddedObject[eoList.size()]);
cob.addAttribute(AttributeBuilder.build("MYDBAT_PERSON_ROLE", (Object[]) roleEm));
CallableStatement groupStmt = conn.prepareCall("{call GET_USERGROUP(?,?)}");
groupStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
groupStmt.setString(2, rs.getString(1));
groupStmt.execute();
ResultSet groupResultSet = (ResultSet) groupStmt.getObject(1);
java.util.List<EmbeddedObject> geoList = new ArrayList<EmbeddedObject>();
while (groupResultSet.next()) {
Attribute groupId= AttributeBuilder.build(new String("GROUPID"),groupResultSet.getString(2));
EmbeddedObjectBuilder groupEA = new EmbeddedObjectBuilder();
groupEA.addAttribute(groupId);
groupEA.setObjectClass(new ObjectClass("MYDBAT_GROUPS"));
geoList.add(groupEA.build());
}
groupResultSet.close();
groupStmt.close();
EmbeddedObject[] groupEm = geoList.toArray(new EmbeddedObject[geoList.size()]);
cob.addAttribute(AttributeBuilder.build("MYDBAT_PERSON_GROUP", (Object[]) groupEm));
}
if(!handler.handle(cob.build())) return;
}
}else if(ocName.equals("MYDBAT_COUNTRY")){
trace.info("[Execute Query] for Lookup : "+ ocName);
CallableStatement groupStmt = conn.prepareCall("{call GET_COUNTRIES(?)}");
groupStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
groupStmt.execute();
ResultSet groupResultSet = (ResultSet) groupStmt.getObject(1);
while (groupResultSet.next()) {
ConnectorObjectBuilder cob = new ConnectorObjectBuilder();
cob.setObjectClass(new ObjectClass("MYDBAT_COUNTRY"));
Attribute groupId= AttributeBuilder.build(new String("__UID__"),groupResultSet.getString(1));
Attribute groupName= AttributeBuilder.build(new String("__NAME__"),groupResultSet.getString(2));
cob.addAttribute(groupId);
cob.addAttribute(groupName);
if(!handler.handle(cob.build())) return;
}
groupResultSet.close();
groupStmt.close();
}else if(ocName.equals("MYDBAT_GROUPS")){
trace.info("[Execute Query] for Entitlement : "+ ocName);
CallableStatement groupStmt = conn.prepareCall("{call GET_GROUPS(?)}");
groupStmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
groupStmt.execute();
ResultSet groupResultSet = (ResultSet) groupStmt.getObject(1);
while (groupResultSet.next()) {
ConnectorObjectBuilder cob = new ConnectorObjectBuilder();
cob.setObjectClass(new ObjectClass("MYDBAT_GROUPS"));
Attribute groupId= AttributeBuilder.build(new String("__UID__"),groupResultSet.getString(1));
Attribute groupName= AttributeBuilder.build(new String("__NAME__"),groupResultSet.getString(2));
cob.addAttribute(groupId);
cob.addAttribute(groupName);
if(!handler.handle(cob.build())) return;
}
groupResultSet.close();
groupStmt.close();
}
} finally {
if( null != rs)
rs.close();
if( null != st)
st.close();
}
ストアド・プロシージャ: ユーザーのロード
create or replace PROCEDURE EXECUTE_QUERY_PERSON
(user_cursor OUT SYS_REFCURSOR) AS
BEGIN
OPEN user_cursor FOR
SELECT USERID,
FIRSTNAME,
LASTNAME,
EMAIL,
DESCRIPTION,
SALARY,
JOININGDATE,
STATUS,
COUNTRYCODE,
USERNAME
FROM MYDBAT_PERSON;
END EXECUTE_QUERY_PERSON;
ストアド・プロシージャ: フィルタ済ユーザー検索
create or replace PROCEDURE EXECUTE_QUERY_WITH_FILTER
(user_cursor OUT SYS_REFCURSOR,
filter IN VARCHAR2,
filterValue IN VARCHAR2) AS
BEGIN
OPEN user_cursor FOR
SELECT USERID,
FIRSTNAME,
LASTNAME,
EMAIL,
DESCRIPTION,
SALARY,
JOININGDATE,
STATUS,
COUNTRYCODE,
USERNAME
FROM MYDBAT_PERSON
WHERE filter=filterValue;
END EXECUTE_QUERY_WITH_FILTER;これは、MYDBAT_PERSON.USERID:21のように、フィルタ条件が1つのみのフィルタ検索の非常に基本的な例です。これは、作成操作後のwriteBack処理に特に使用されます。ストアド・プロシージャ: ロールの取得
create or replace PROCEDURE GET_ROLES
(user_cursor OUT SYS_REFCURSOR) AS
BEGIN
OPEN user_cursor FOR
SELECT ROLEID,
ROLENAME
FROM MYDBAT_ROLES;
END GET_ROLES;
ストアド・プロシージャ: ユーザー・ロールの取得
create or replace PROCEDURE GET_USERROLE
(user_cursor OUT SYS_REFCURSOR,
userin IN VARCHAR2) AS
BEGIN
OPEN user_cursor FOR
SELECT USERID,
ROLEID,
FROMDATE,
TODATE
FROM MYDBAT_PERSON_ROLE
WHERE USERID=userin;
END GET_USERROLE;
ストアド・プロシージャ: グループの取得
create or replace PROCEDURE GET_GROUPS
(user_cursor OUT SYS_REFCURSOR) AS
BEGIN
OPEN user_cursor FOR
SELECT GROUPID,
GROUPNAME
FROM MYDBAT_GROUPS;
END GET_GROUPS;
ストアド・プロシージャ: ユーザー・グループの取得
create or replace PROCEDURE GET_USERGROUP
(user_cursor OUT SYS_REFCURSOR,
userin IN VARCHAR2) AS
BEGIN
OPEN user_cursor FOR
SELECT USERID,
GROUPID
FROM MYDBAT_PERSON_GROUP
WHERE USERID=userin;
END GET_USERGROUP;
ストアド・プロシージャ: 参照の取得(国)
create or replace PROCEDURE GET_COUNTRIES
(user_cursor OUT SYS_REFCURSOR) AS
BEGIN
OPEN user_cursor FOR
SELECT COUNTRYCODE,
COUNTRYNAME
FROM MYDBAT_COUNTRY;
END GET_COUNTRIES;
サンプル作成スクリプト
このスクリプトは、Oracle Access Governanceからの新規アカウントのプロビジョニング中に起動されます。ここでは、MYDBAT_PERSON表にデータを挿入します。
スクリプトの作成
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.*;
import java.util.Date.*;
import org.identityconnectors.common.security.GuardedString;
import org.identityconnectors.framework.common.objects.*;
import java.text.*;
// START HERE
trace.info("[Create-Groovy] Attributes::"+attributes);
//USERID,PASSWORD,USERNAME,STATUS,EMAIL,FIRSTNAME,LASTNAME,ORGANIZATION,CITY,EMPLOYEE_NUMBER,joiningdate,ENDDATE,LONGVALUE,FLOATVALUE,CHARVALUE
//Get all the attributes from script argument
// This shows how to read arrtibures
String uid = attributes.get("__NAME__")!=null? attributes.get("__NAME__").getValue().get(0):null;
GuardedString pass = attributes.get("__PASSWORD__")!=null? attributes.get("__PASSWORD__").getValue().get(0):null;
String uname = attributes.get("__NAME__")!=null? attributes.get("__NAME__").getValue().get(0):null;
enableValue = attributes.get("__ENABLE__")!=null? attributes.get("__ENABLE__").getValue().get(0):true;
String email=attributes.get("EMAIL")!=null? attributes.get("EMAIL").getValue().get(0):null;
String first=attributes.get("FIRSTNAME")!=null? attributes.get("FIRSTNAME").getValue().get(0):null;
String last=attributes.get("LASTNAME")!=null? attributes.get("LASTNAME").getValue().get(0):null;
String org=attributes.get("ORGANIZATION")!=null? attributes.get("ORGANIZATION").getValue().get(0):null;
String countryCode=attributes.get("COUNTRYCODE")!=null? attributes.get("COUNTRYCODE").getValue().get(0):null;
joiningdate = attributes.get("JOININGDATE")!=null? attributes.get("JOININGDATE").getValue().get(0):null;
PreparedStatement createStmt = null;
String ret =null;
try {
//Call Target API to create a user
createStmt = conn.prepareStatement("INSERT INTO MYDBAT_PERSON(USERID,PASSWORD,USERNAME,STATUS,EMAIL,FIRSTNAME,LASTNAME,COUNTRYCODE,JOININGDATE) VALUES(?,?,?,?,?,?,?,?,?)");
createStmt.setString(1, uid);
if(pass!=null)
{
pass.access(new GuardedString.Accessor(){
public void access(char[] clearChars) { createStmt.setString(2, new String(clearChars));}
});
}
else
createStmt.setString(2,null);
createStmt.setString(3, uname);
if(enableValue)
createStmt.setString(4,"Enabled");
else
createStmt.setString(4,"Disabled");
createStmt.setString(5, email);
createStmt.setString(6, first);
createStmt.setString(7, last);
createStmt.setString(8, countryCode);
DateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
if (joiningdate!=null)
{
if (joiningdate == 0){
createStmt.setString(9,null);
}
else
{
Date da=new Date(joiningdate);
st=formatter.format(da);
createStmt.setString(9,st);
}
}
createStmt.executeUpdate();
} finally{
//close the sql statements
if (createStmt != null)
createStmt.close();
}
trace.info("[Create] Created User::"+uid);
//Return Uid from the script
return new Uid(uid);
子スクリプトの追加のサンプル
このスクリプトは、Oracle Access Governanceからユーザーへの権限/権限のプロビジョニング中に起動されます。ここでは、MYDBAT_PERSON_GROUP表およびMYDBAT_PERSON_ROLE表にデータを挿入します。
子スクリプトの追加
import org.identityconnectors.framework.common.objects.*;
import java.text.*;
trace.info("[addMultiValuedAttributeScript-Groovy] Adding Child data::"+ attributes);
childst =null;
try {
//Adding Group data
childDataEOSet = null;
//The child attributes are returned as a set of embedded objects. Each Embedded object
// will provide a row of data in the child table.
// Logic for handling simple multi valued attributes
if(attributes.get("MYDBAT_PERSON_GROUP")!=null)
{
childDataEOSet=attributes.get("MYDBAT_PERSON_GROUP").getValue();
childst=conn.prepareStatement("INSERT INTO MYDBAT_PERSON_GROUP VALUES (?,?)");
String id = attributes.get("__UID__").getValue().get(0);
if(childDataEOSet !=null){
//Iterate through child data and insert into table
trace.info("[addMultiValuedAttributeScript] Adding Group data.");
for( iterator = childDataEOSet.iterator(); iterator.hasNext(); )
{
eo = iterator.next();
attrsSet=eo.getAttributes();
grpattr=AttributeUtil.find("GROUPID",attrsSet);
if(grpattr!=null){
// You are iterating simple multi valued attributes here, Call target APIs here
//conn object is available here
groupid=grpattr.getValue().get(0);
childst.setString(1, id);
childst.setString(2, groupid);
childst.executeUpdate();
childst.clearParameters();
}
};
}
}
} finally {
if (childst != null)
childst.close();
};
try {
childDataEOSet = null;
// Logic for handling Complex multi valued attributes
if(attributes.get("MYDBAT_PERSON_ROLE")!=null)
{
childDataEOSet=attributes.get("MYDBAT_PERSON_ROLE").getValue();
childst=conn.prepareStatement("INSERT INTO MYDBAT_PERSON_ROLE VALUES (?,?,?,?)");
String id = attributes.get("__UID__").getValue().get(0);
if(childDataEOSet !=null)
{
trace.info("[addMultiValuedAttributeScript] Adding Role data.");
for( iterator = childDataEOSet.iterator(); iterator.hasNext(); )
{
eo = iterator.next();
attrsSet = eo.getAttributes(); // Get all the attributes of child object
roleattr=AttributeUtil.find("ROLEID",attrsSet);
// You are iterating complex multi valued attributes here, Call target APIs here
//conn object is available here
if(roleattr!=null){
// You are iterating simple multi valued attributes here, Call target APIs here
//conn object is available here
roleid=roleattr.getValue().get(0);
fromDate=AttributeUtil.find("FROMDATE",attrsSet).getValue().get(0);
toDate=AttributeUtil.find("TODATE",attrsSet).getValue().get(0);
childst.setString(1, id);
childst.setString(2, roleid);
Date from_date=new Date(fromDate);
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yy");
String from_date_st=formatter.format(from_date);
childst.setString(3, from_date_st);
Date to_date=new Date(toDate);
String to_date_st=formatter.format(to_date);
childst.setString(4, to_date_st);
childst.executeUpdate();
childst.clearParameters();
}
};
}
}
} finally {
if (childst != null)
childst.close();
};
子スクリプトの削除のサンプル
このスクリプトは、Oracle Access Governanceからユーザーからの権限/権限のプロビジョニング解除時に起動されます。ここでは、ストアド・プロシージャを使用してMYDBAT_PERSON_GROUP表およびMYDBAT_PERSON_ROLE表からデータを削除します。
子スクリプトの削除
import org.identityconnectors.framework.common.objects.*;
trace.info("[removeMultiValuedAttributeScript] Removing Child data::"+ attributes);
try {
childDataEOSet = null;
delSt = null;
//Get UID
String id = attributes.get("__UID__").getValue().get(0);
if(attributes.get("MYDBAT_PERSON_GROUP")!=null)
{
childDataEOSet=attributes.get("MYDBAT_PERSON_GROUP").getValue();
//Delete child data using stored procedure
delSt= conn.prepareCall("{call DELETE_USERGROUP(?,?)}");
if(childDataEOSet !=null){
trace.info("[removeMultiValuedAttributeScript] Removing Group data.");
//Iterate through child data and delete
for( iterator = childDataEOSet.iterator(); iterator.hasNext(); )
{
eo = iterator.next();
attrsSet = eo.getAttributes();
grpattr=AttributeUtil.find("GROUPID",attrsSet);
if(grpattr!=null){
groupid=grpattr.getValue().get(0);
delSt.setString(1, id);
delSt.setString(2, groupid);
delSt.executeUpdate();
trace.info("[removeMultiValuedAttributeScript] Deleted Group::"+ grpattr);
}
};
}
}
} finally {
if (delSt != null)
delSt.close();
};
try {
childDataEOSet = null;
delSt = null;
String id = attributes.get("__UID__").getValue().get(0);
if(attributes.get("MYDBAT_PERSON_ROLE")!=null)
{
childDataEOSet=attributes.get("MYDBAT_PERSON_ROLE").getValue();
delSt= conn.prepareCall("{call DELETE_USERROLE(?,?)}");
if(childDataEOSet !=null){
trace.info("[removeMultiValuedAttributeScript] Removing Role data.");
for( iterator = childDataEOSet.iterator(); iterator.hasNext(); )
{
eo = iterator.next();
attrsSet = eo.getAttributes();
roleattr=AttributeUtil.find("ROLEID",attrsSet);
if(roleattr!=null){
rolename=roleattr.getValue().get(0);
delSt.setString(1, id);
delSt.setString(2, rolename);
delSt.executeUpdate();
trace.info("[removeMultiValuedAttributeScript] Deleted Role::"+ rolename);
}
};
}
}
} finally {
if (delSt != null)
delSt.close();
};
ストアド・プロシージャ: 子の削除
create or replace PROCEDURE DELETE_USERGROUP
(user_id MYDBAT_PERSON_group.USERID%TYPE,
group_id MYDBAT_PERSON_group.GROUPID%TYPE ) AS
BEGIN
DELETE FROM MYDBAT_PERSON_group
WHERE groupid=group_id
AND userid=user_id;
END DELETE_USERGROUP;
create or replace PROCEDURE DELETE_USERROLE
(user_id MYDBAT_PERSON_ROLE.USERID%TYPE,
role_id MYDBAT_PERSON_ROLE.ROLEID%TYPE) AS
BEGIN
DELETE FROM MYDBAT_PERSON_ROLE
WHERE userid=user_id and roleid=role_id;
END DELETE_USERROLE;
サンプル削除スクリプト
このスクリプトは、Oracle Access Governanceからのアカウントの失効時に起動されます。ここでは、データ・ユーザー関係表MYDBAT_PERSON_ROLEおよびMYDBAT_PERSON_GROUPと、MYDBAT_PERSON表からのデータを削除します。
スクリプトの削除
import java.sql.PreparedStatement;
import org.identityconnectors.framework.common.objects.*;
//Get the UID from the input map 'attributes'
String uid = attributes.get("__UID__").getValue().get(0);
trace.info("[Delete-Groovy] Deleting user:: "+ uid);
try {
//Delete data from child tables and then, main table
//Delete user roles
st = conn.prepareStatement("DELETE FROM MYDBAT_PERSON_ROLE WHERE USERID=?");
st.setString(1, uid);
st.executeUpdate();
st.close();
//Delete user groups
st = conn.prepareStatement("DELETE FROM MYDBAT_PERSON_GROUP WHERE USERID=?");
st.setString(1, uid);
st.executeUpdate();
st.close();
//Delete user account
st = conn.prepareStatement("DELETE FROM MYDBAT_PERSON WHERE USERID=?");
st.setString(1, uid);
st.executeUpdate();
} finally {
if (st != null)
st.close(); };
trace.info("Deleted user:: "+ uid);
サンプル更新スクリプト
このスクリプトは、アカウントがOracle Access Governanceから更新されたときにプロビジョニング操作中に起動されます。ここでは、MYDBAT_PERSON表のデータを更新します。
スクリプトの更新
import org.identityconnectors.framework.common.objects.*;
import java.text.*;
import org.identityconnectors.framework.common.exceptions.*;
trace.info("[Update-Groovy] Atrributes::"+ attributes);
/** During an Update operation,AGCS sends the UID attribute along with updated attributes.
Get all the values of attributes **/
String id = attributes.get("__UID__")!=null? attributes.get("__UID__").getValue().get(0):null;
String firstName=attributes.get("FIRSTNAME")!=null? attributes.get("FIRSTNAME").getValue().get(0):null;
String lastName=attributes.get("LASTNAME")!=null? attributes.get("LASTNAME").getValue().get(0):null;
String email=attributes.get("EMAIL")!=null? attributes.get("EMAIL").getValue().get(0):null;
String description=attributes.get("DESCRIPTION")!=null? attributes.get("DESCRIPTION").getValue().get(0):null;
salary=attributes.get("SALARY")!=null? attributes.get("SALARY").getValue().get(0):null;
joindate = attributes.get("JOININGDATE")!=null? attributes.get("JOININGDATE").getValue().get(0):null;
enableValue = attributes.get("__ENABLE__")!=null? attributes.get("__ENABLE__").getValue().get(0):true;
//Throw exception if uid is null
if(id==null) throw new ConnectorException("UID Cannot be Null");
stmt = null;
try {
//Create prepared statement to update the MYDBAT_PERSON table
stmt = conn.prepareStatement("UPDATE MYDBAT_PERSON SET FIRSTNAME=COALESCE(?, FIRSTNAME),LASTNAME =COALESCE(?, LASTNAME), EMAIL= COALESCE(?, EMAIL),SALARY=COALESCE(?, SALARY),JOININGDATE=COALESCE(to_date(?,'dd-Mon-yy'), JOININGDATE),STATUS=COALESCE(?, STATUS) WHERE USERID =?");
//Set sql input parameters
stmt.setString(1, firstName);
stmt.setString(2, lastName);
stmt.setString(3, email);
stmt.setBigDecimal(4, new BigDecimal(salary));
dateStr = null;
//Convert the joindate into oracle date format
if( joindate != null) {
Date date=new Date(joindate);
DateFormat targetFormat = new SimpleDateFormat("dd-MMM-yy");
dateStr = targetFormat.format(date);
}
stmt.setString(5,dateStr);
if(enableValue)
stmt.setString(6,"Enabled");
else
stmt.setString(6,"Disabled");
stmt.setString(7, id);
stmt.executeUpdate();
} finally {
if (stmt != null)
stmt.close();
};
trace.info("[Update] Updated user::"+ id);
return new Uid(id);