[prev in list] [next in list] [prev in thread] [next in thread] 

List:       forgerock-openam-commit
Subject:    [CommitOpenAM] [10823] branches/AME-4609/openam: AME-4609 Add skeletal structure for code changes
From:       noreply () forgerock ! org
Date:       2014-09-30 16:29:11
Message-ID: 20140930162911.AAF5640934 () sources ! internal ! forgerock ! com
[Download RAW message or body]

[Attachment #2 (text/html)]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[10823] branches/AME-4609/openam: AME-4609 Add skeletal structure for code \
changes</title> </head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: \
verdana,arial,helvetica,sans-serif; font-size: 10pt;  } #msg dl a { font-weight: \
bold} #msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: \
bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: \
6px; } #logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em \
0; } #logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg \
h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; } \
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; \
} #logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: \
-1.5em; padding-left: 1.5em; } #logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em \
1em 0 1em; background: white;} #logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid \
#fa0; border-bottom: 1px solid #fa0; background: #fff; } #logmsg table th { \
text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted \
#fa0; } #logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: \
0.2em 0.5em; } #logmsg table thead th { text-align: center; border-bottom: 1px solid \
#fa0; } #logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: \
6px; } #patch { width: 100%; }
#patch h4 {font-family: \
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
 #patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, \
#patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins \
{background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del \
{background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, \
                .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a \
href="http://sources.forgerock.org/changelog/openam/?cs=10823">10823</a></dd> \
<dt>Author</dt> <dd>craig.mcdonnell</dd> <dt>Date</dt> <dd>2014-09-30 17:29:11 +0100 \
(Tue, 30 Sep 2014)</dd> </dl>

<h3>Log Message</h3>
<pre>AME-4609 Add skeletal structure for code changes</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesAME4609openamopenamcliopenamcliimplsrcmainjavacomsunidentityclie \
ntitlementCreateXACMLjava">branches/AME-4609/openam/openam-cli/openam-cli-impl/src/main/java/com/sun/identity/cli/entitlement/CreateXACML.java</a></li>
 <li><a href="#branchesAME4609openamopenamcoresrcmainjavacomsunidentityentitlementxacm \
l3XACMLImportExportjava">branches/AME-4609/openam/openam-core/src/main/java/com/sun/identity/entitlement/xacml3/XACMLImportExport.java</a></li>
 </ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesAME4609openamopenamcliopenamcliimplsrcmainjavacomsunidentityclientitlementCreateXACMLjava"></a>
 <div class="modfile"><h4>Modified: \
branches/AME-4609/openam/openam-cli/openam-cli-impl/src/main/java/com/sun/identity/cli/entitlement/CreateXACML.java \
(10822 => 10823)</h4> <pre class="diff"><span>
<span class="info">--- \
branches/AME-4609/openam/openam-cli/openam-cli-impl/src/main/java/com/sun/identity/cli/entitlement/CreateXACML.java	2014-09-30 \
                15:44:43 UTC (rev 10822)
+++ branches/AME-4609/openam/openam-cli/openam-cli-impl/src/main/java/com/sun/identity/cli/entitlement/CreateXACML.java	2014-09-30 \
16:29:11 UTC (rev 10823) </span><span class="lines">@@ -32,20 +32,20 @@
</span><span class="cx">  */
</span><span class="cx"> package com.sun.identity.cli.entitlement;
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> import com.iplanet.sso.SSOToken;
</span><span class="cx"> import com.sun.identity.cli.AuthenticatedCommand;
</span><span class="cx"> import com.sun.identity.cli.CLIException;
</span><span class="cx"> import com.sun.identity.cli.CommandManager;
</span><span class="cx"> import com.sun.identity.cli.ExitCodes;
</span><span class="cx"> import com.sun.identity.cli.IArgument;
</span><del>-import com.sun.identity.cli.IOutput;
</del><span class="cx"> import com.sun.identity.cli.LogWriter;
</span><span class="cx"> import com.sun.identity.cli.RequestContext;
</span><span class="cx"> import \
com.sun.identity.entitlement.EntitlementConfiguration; </span><span class="cx"> \
import com.sun.identity.entitlement.EntitlementException; </span><ins>+import \
com.sun.identity.entitlement.IPrivilege; </ins><span class="cx"> import \
com.sun.identity.entitlement.opensso.SubjectUtils; </span><span class="cx"> import \
com.sun.identity.entitlement.xacml3.XACMLImportExport; </span><ins>+import \
com.sun.identity.entitlement.xacml3.XACMLImportExport.DiffResult; </ins><span \
class="cx">  </span><span class="cx"> import javax.security.auth.Subject;
</span><span class="cx"> import java.io.ByteArrayInputStream;
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx"> import java.io.FileNotFoundException;
</span><span class="cx"> import java.io.InputStream;
</span><span class="cx"> import java.text.MessageFormat;
</span><ins>+import java.util.List;
</ins><span class="cx"> import java.util.logging.Level;
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -72,48 +73,89 @@
</span><span class="cx">      * @param rc Request Context.
</span><span class="cx">      * @throws CLIException if the request cannot serviced.
</span><span class="cx">      */
</span><del>-    public void handleRequest(RequestContext rc)
-            throws CLIException {
</del><ins>+    public void handleRequest(RequestContext rc) throws CLIException {
</ins><span class="cx">         super.handleRequest(rc);
</span><span class="cx">         ldapLogin();
</span><span class="cx"> 
</span><span class="cx">         SSOToken adminSSOToken = getAdminSSOToken();
</span><span class="cx">         Subject adminSubject = \
SubjectUtils.createSubject(adminSSOToken); </span><span class="cx">         String \
realm = getStringOptionValue(IArgument.REALM_NAME); </span><ins>+        String[] \
logMsgData = {realm}; </ins><span class="cx"> 
</span><ins>+        ensureEntitlementServiceActive(adminSubject, realm);
+
+        InputStream xacmlInputStream = getXacmlInputStream(realm);
+
+        if (isDryRun()) {
+
+            // TODO: Log ATTEMPT_TO_GET_POLICIES_FOR_REALM ?
+//            writeLog(LogWriter.LOG_ACCESS, Level.INFO, \
&quot;ATTEMPT_GET_POLICY_IN_REALM&quot;, logMsgData); +
+            try {
+                List&lt;DiffResult&lt;IPrivilege&gt;&gt; diffResults = \
xacmlImportExport.importXacmlDryRun(realm, xacmlInputStream, adminSubject); +
+                // TODO: Log SUCCEED_GET_POLICIES_FOR_REALM ?
+//                writeLog(LogWriter.LOG_ACCESS, Level.INFO, \
&quot;SUCCEED_GET_POLICY_IN_REALM&quot;, logMsgData); +
+                outputDiffResults(diffResults);
+
+            } catch (EntitlementException e) {
+                String[] args = {realm, e.getMessage()};
+                debugError(&quot;CreateXACML.handleRequest&quot;, e);
+                // TODO: Log FAILED_GET_POLICIES_FOR_REALM ?
+//                writeLog(LogWriter.LOG_ERROR, Level.INFO, \
&quot;FAILED_GET_POLICY_IN_REALM&quot;, args); +                throw new \
CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); +            }
+
+        } else {
+
+            writeLog(LogWriter.LOG_ACCESS, Level.INFO, \
&quot;ATTEMPT_CREATE_POLICY_IN_REALM&quot;, logMsgData); +
+            try {
+                if (xacmlImportExport.importXacml(realm, xacmlInputStream, \
adminSubject)) { +                    writeLog(LogWriter.LOG_ACCESS, Level.INFO, \
&quot;SUCCEED_CREATE_POLICY_IN_REALM&quot;, logMsgData); +                    \
getOutputWriter().printlnMessage(MessageFormat.format( +                            \
getResourceString(&quot;create-policy-in-realm-succeed&quot;), (Object[]) \
logMsgData)); +                } else {
+                    String[] args = {realm, &quot;ANY&quot;, &quot;create-xacml \
input policy set is null&quot;}; +                    writeLog(LogWriter.LOG_ERROR, \
Level.INFO, &quot;FAILED_CREATE_POLICY_IN_REALM&quot;, args); +                    \
getOutputWriter().printlnMessage(&quot;policy set is null&quot;); +                }
+            } catch (EntitlementException e) {
+                String[] args = {realm, e.getMessage()};
+                debugError(&quot;CreateXACML.handleRequest&quot;, e);
+                writeLog(LogWriter.LOG_ERROR, Level.INFO, \
&quot;FAILED_CREATE_POLICY_IN_REALM&quot;, args); +                throw new \
CLIException(e, ExitCodes.REQUEST_CANNOT_BE_PROCESSED); +            }
+        }
+
+    }
+
+    private void ensureEntitlementServiceActive(Subject adminSubject, String realm) \
throws CLIException { </ins><span class="cx">         // FIXME: change to use \
entitlementService.xacmlPrivilegEnabled() </span><del>-        \
                EntitlementConfiguration ec = EntitlementConfiguration.getInstance(
-            adminSubject, &quot;/&quot;);
-        if(!ec.migratedToEntitlementService()) {
-            String[] args = {realm, &quot;ANY&quot;, 
-                    &quot;create-xacml not supported in  legacy policy mode&quot;};
-            debugError(&quot;CreateXACML.handleRequest(): &quot;
-                    + &quot;create-xacml not supported in  legacy policy \
                mode&quot;);
-            writeLog(LogWriter.LOG_ERROR, Level.INFO,
-                &quot;FAILED_CREATE_POLICY_IN_REALM&quot;, 
-                args);
-            throw new CLIException(
-                getResourceString( 
-                    &quot;create-xacml-not-supported-in-legacy-policy-mode&quot;), 
-                ExitCodes.REQUEST_CANNOT_BE_PROCESSED,
-                &quot;create-xacml&quot;);
</del><ins>+        EntitlementConfiguration ec = \
EntitlementConfiguration.getInstance(adminSubject, &quot;/&quot;); +        if \
(!ec.migratedToEntitlementService()) { +            String[] args = {realm, \
&quot;ANY&quot;, &quot;create-xacml not supported in  legacy policy mode&quot;}; +    \
debugError(&quot;CreateXACML.handleRequest(): create-xacml not supported in  legacy \
policy mode&quot;); +            writeLog(LogWriter.LOG_ERROR, Level.INFO, \
&quot;FAILED_CREATE_POLICY_IN_REALM&quot;, args); +            throw new \
CLIException(getResourceString(&quot;create-xacml-not-supported-in-legacy-policy-mode&quot;),
 +                    ExitCodes.REQUEST_CANNOT_BE_PROCESSED,
+                    &quot;create-xacml&quot;);
</ins><span class="cx">         }
</span><ins>+    }
</ins><span class="cx"> 
</span><ins>+    private InputStream getXacmlInputStream(String realm) throws \
CLIException { +        InputStream inputStream;
+
</ins><span class="cx">         String datafile = \
getStringOptionValue(IArgument.XML_FILE); </span><del>-        IOutput outputWriter = \
                getOutputWriter();
-
</del><span class="cx">         CommandManager mgr = getCommandManager();
</span><span class="cx">         String url = mgr.getWebEnabledURL();
</span><del>-        String[] params = {realm};
-        writeLog(LogWriter.LOG_ACCESS, Level.INFO,
-            &quot;ATTEMPT_CREATE_POLICY_IN_REALM&quot;, params);
</del><span class="cx"> 
</span><del>-        InputStream xacmlSource;
</del><span class="cx">         if ((url != null) &amp;&amp; (url.length() &gt; 0)) {
</span><del>-            xacmlSource = new ByteArrayInputStream(datafile.getBytes());
</del><ins>+            inputStream = new ByteArrayInputStream(datafile.getBytes());
</ins><span class="cx">         } else {
</span><span class="cx">             try {
</span><del>-                xacmlSource = new FileInputStream(datafile);
</del><ins>+                inputStream = new FileInputStream(datafile);
</ins><span class="cx">             } catch (FileNotFoundException e) {
</span><span class="cx">                 String[] args = {realm, e.getMessage()};
</span><span class="cx">                 \
debugError(&quot;CreateXACML.handleRequest&quot;, e); </span><span class="lines">@@ \
-122,26 +164,10 @@ </span><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        try {
-            if (xacmlImportExport.importXacml(realm, xacmlSource, adminSubject)) {
-                writeLog(LogWriter.LOG_ACCESS, Level.INFO, \
                &quot;SUCCEED_CREATE_POLICY_IN_REALM&quot;, params);
-                outputWriter.printlnMessage(MessageFormat.format(
-                        \
                getResourceString(&quot;create-policy-in-realm-succeed&quot;),
-                        (Object[])params));
-            } else {
-                String[] args = {realm, &quot;ANY&quot;, &quot;create-xacml input \
                poliy set is null&quot;};
-                writeLog(LogWriter.LOG_ERROR, Level.INFO, \
                &quot;FAILED_CREATE_POLICY_IN_REALM&quot;, args);
-                outputWriter.printlnMessage(&quot;policy set is null&quot;);
-            }
-        } catch (EntitlementException e) {
-            String[] args = {realm, e.getMessage()};
-            debugError(&quot;CreateXACML.handleRequest&quot;, e);
-            writeLog(LogWriter.LOG_ERROR, Level.INFO, \
                &quot;FAILED_CREATE_POLICY_IN_REALM&quot;, args);
-            throw new CLIException(e ,ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
-        }
</del><ins>+        return inputStream;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    private void outputDiff() {
</del><ins>+    private void \
outputDiffResults(List&lt;DiffResult&lt;IPrivilege&gt;&gt; diffResults) { </ins><span \
class="cx">         //TODO Once unblocked. </span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchesAME4609openamopenamcoresrcmainjavacomsunidentityentitlementxacml3XACMLImportExportjava"></a>
 <div class="modfile"><h4>Modified: \
branches/AME-4609/openam/openam-core/src/main/java/com/sun/identity/entitlement/xacml3/XACMLImportExport.java \
(10822 => 10823)</h4> <pre class="diff"><span>
<span class="info">--- \
branches/AME-4609/openam/openam-core/src/main/java/com/sun/identity/entitlement/xacml3/XACMLImportExport.java	2014-09-30 \
                15:44:43 UTC (rev 10822)
+++ branches/AME-4609/openam/openam-core/src/main/java/com/sun/identity/entitlement/xacml3/XACMLImportExport.java	2014-09-30 \
16:29:11 UTC (rev 10823) </span><span class="lines">@@ -18,6 +18,7 @@
</span><span class="cx"> 
</span><span class="cx"> import com.google.inject.Inject;
</span><span class="cx"> import com.sun.identity.entitlement.EntitlementException;
</span><ins>+import com.sun.identity.entitlement.IPrivilege;
</ins><span class="cx"> import com.sun.identity.entitlement.Privilege;
</span><span class="cx"> import com.sun.identity.entitlement.PrivilegeManager;
</span><span class="cx"> import com.sun.identity.entitlement.ReferralPrivilege;
</span><span class="lines">@@ -33,6 +34,7 @@
</span><span class="cx"> import javax.xml.bind.JAXBException;
</span><span class="cx"> import java.io.InputStream;
</span><span class="cx"> import java.text.MessageFormat;
</span><ins>+import java.util.Collections;
</ins><span class="cx"> import java.util.HashSet;
</span><span class="cx"> import java.util.List;
</span><span class="cx"> import java.util.Set;
</span><span class="lines">@@ -135,6 +137,54 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    public List&lt;DiffResult&lt;IPrivilege&gt;&gt; \
importXacmlDryRun(String realm, InputStream xacmlInputStream, +            Subject \
adminSubject) throws EntitlementException { +
+        // TODO
+        return Collections.emptyList();
+    }
+
+    public static enum DiffStatus {
+
+        ADDED(&quot;A&quot;), UPDATED(&quot;U&quot;);
+
+        private final String code;
+
+        private DiffStatus(String code) {
+            this.code = code;
+        }
+
+        public String getCode() {
+            return code;
+        }
+    }
+
+    public static class DiffResult&lt;T&gt; {
+
+        private final DiffStatus status;
+        private final T oldState;
+        private final T newState;
+
+        public DiffResult(DiffStatus status, T oldState, T newState) {
+            this.status = status;
+            this.oldState = oldState;
+            this.newState = newState;
+        }
+
+        public DiffStatus getStatus() {
+            return status;
+        }
+
+        public T getOldState() {
+            return oldState;
+        }
+
+        public T getNewState() {
+            return newState;
+        }
+
+    }
+
</ins><span class="cx">     /**
</span><span class="cx">      * Performs an export of all Policies found in the \
Privilege Manager that match the </span><span class="cx">      * provided filters.
</span><span class="lines">@@ -195,4 +245,5 @@
</span><span class="cx">             debug.message(MessageFormat.format(PREFIX + \
format, args)); </span><span class="cx">         }
</span><span class="cx">     }
</span><ins>+
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">Copyright (c) by ForgeRock. All rights reserved.</div>

</body>
</html>



_______________________________________________
CommitOpenAM mailing list
CommitOpenAM@forgerock.org
https://lists.forgerock.org/mailman/listinfo/commitopenam


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic