Nun kam dieser Kunde neulich auf mich und fragte, wie man ca. 1.000 Mitarbeiter direkt einem IRM Context mit einer bestimmten Rollen zu weisen kann.
Meine Antwort: "Ganz einfach, nutzen Sie ihren zentralen LDAP-Server und weisen Sie die LDAP-Gruppe, welche die 1000 Mitarbeiter beherbergt, direkt dem Context mit einer entsprechenden Rolle zu. Aufwand ca. 1 Minute."
Leider ist es bei dem Kunden nicht möglich LDAP-Gruppen zu nutzen, so dass eine manuelle Zuweisung jedes einzelnen Mitarbeiters notwendig wäre. Aber man kann das Problem natürlich besser lösen.
Oracle Information Rights Management stellt eine API zur Verfügung, die wesentliche Funktionen beinhaltet, um schnell und einfach Utilities zu schreiben. Das habe ich dann auch gemacht.
Im Developer Guide findet man ein nettes Beispiel dazu: Assign a Role to a User.
Wir brauchten natürlich etwas mehr Dynamik:
- Wir wollen die 1.000 Mitarbeiter direkt aus einer Datei lesen
- Alle Parameter werden über eine property-Datei gelesen.
Beispiel-Code für das Utility kann wie folgt aussehen (PS: Ich bin Java Newbie):
package irmwebservice; import java.net.PasswordAuthentication; import static oracle.irm.j2ee.jws.rights.context.DocumentRightOperations.getDocumentRightOperationsEndpoint; import java.io.*; import java.util.*; import java.net.URLEncoder; import java.util.UUID; import java.net.Authenticator; import java.net.PasswordAuthentication; import oracle.irm.engine.types.core.account.AccountRef; import oracle.irm.engine.types.rights.context.ContextInstanceRef; import oracle.irm.engine.types.rights.context.DocumentRoleRef; import oracle.irm.engine.types.rights.context.DomainRef; import oracle.irm.j2ee.jws.rights.context.DocumentRightOperationsEndpoint; public class AssignRole { public static void main(String[] args) throws Exception { String str; String sdomainUUID = ""; String sroleUUID = ""; String scontextUUID = ""; String shostPort = "http://demoIRM:16100"; String susername = "weblogic"; String spassword = "oracle"; try { int check = 0; while (check == 0) { check = 1; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter file name which has properties extension :"); str = "utility"; File f = new File(str + ".properties"); if (f.exists()) { Properties pro = new Properties(); FileInputStream in = new FileInputStream(f); pro.load(in); System.out.println("All key are given: " + pro.keySet()); shostPort = pro.getProperty("hostport"); System.out.println("hostport" + " = " + shostPort); susername = pro.getProperty("username"); System.out.println("username" + " = " + susername); spassword = pro.getProperty("password"); System.out.println("password" + " = " + spassword); sdomainUUID = pro.getProperty("domainUUID"); System.out.println("domainUUID" + " = " + sdomainUUID); sroleUUID = pro.getProperty("roleUUID"); System.out.println("roleUUID" + " = " + sroleUUID); scontextUUID = pro.getProperty("contextUUID"); System.out.println("contextUUID" + " = " + scontextUUID); } else { check = 0; System.out.println("Property-File "+ str+ ".properties" + " not found!"); } } } catch (IOException e) { System.out.println(e.getMessage()); } final String hostPort = shostPort; final String username = susername; final String password = spassword; Authenticator.setDefault(new Authenticator(){ @Override protected PasswordAuthentication getPasswordAuthentication(){ return new PasswordAuthentication(username,password.toCharArray()); } }); // Domain UUID is read from property file UUID domainUUID = UUID.fromString(sdomainUUID); DomainRef domainRef = new DomainRef(domainUUID); // Document Role UUID is read from property file UUID documentRoleUUID = UUID.fromString(sroleUUID); DocumentRoleRef roleRef = new DocumentRoleRef(documentRoleUUID, domainRef); // Context UUID is read from property file UUID contextUUID = UUID.fromString(scontextUUID); ContextInstanceRef contextInstanceRef = new ContextInstanceRef(contextUUID); // Get the document right operations endpoint DocumentRightOperationsEndpoint rightOperations = getDocumentRightOperationsEndpoint(hostPort); //Read user accounts from File try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("mitarbeiter.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println ("Read-Account from File: "+strLine); // Reference the account by user name AccountRef accountRef = new AccountRef("urn:user:" + URLEncoder.encode(strLine, "utf-8")); // Assign the role to the account rightOperations.assignRole( contextInstanceRef, roleRef, new AccountRef[] { accountRef }, null); // no item constraints System.out.println (strLine+" was assign to Role!"); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
Keine Kommentare:
Kommentar veröffentlichen