Refactor Api Auth for AAF
[dmaap/dbcapi.git] / src / main / java / org / onap / dmaap / dbcapi / aaf / AafService.java
index 727ec19..68fca79 100644 (file)
 
 package org.onap.dmaap.dbcapi.aaf;
 
-import java.io.IOException;
-
-import org.apache.log4j.Logger;
 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
 import org.onap.dmaap.dbcapi.util.DmaapConfig;
 
+/*
+ * this service uses the AAF REST API endpoints to provision values in AAF
+ */
 public class AafService extends BaseLoggingClass {
        public enum ServiceType {
                AAF_Admin,
@@ -36,6 +36,8 @@ public class AafService extends BaseLoggingClass {
        private AafConnection aaf;
        private ServiceType ctype;
        private String aafURL ;
+       private boolean useAAF = false;
+       
        
        private String getCred( boolean wPwd ) {
                String mechIdProperty = null;
@@ -54,21 +56,10 @@ public class AafService extends BaseLoggingClass {
                        return null;
                }
                String user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" );
-               //String dClass = p.getProperty( "AafDecryption.Class", "org.openecomp.dmaapbc.aaf.ClearDecrypt");
+
                String pwd = "";
                String encPwd = p.getProperty( pwdProperty, "notSet" );
-               //DecryptionInterface dec = null;
-               //try {
-               //      dec = (DecryptionInterface) (Class.forName(dClass).newInstance());      
-               //      dec.init( p.getProperty("CredentialCodecKeyfile", "LocalKey"));
-               //} catch (Exception ee ) {
-               //      errorLogger.error(DmaapbcLogMessageEnum.UNEXPECTED_CONDITION, "attempting to use " + dClass + " to decrypt " + encPwd );                
-               //}     
-               //try {         
-               //      pwd = dec.decrypt( encPwd );
-               //} catch( IOException io ) {
-               //      errorLogger.error(DmaapbcLogMessageEnum.DECRYPT_IO_ERROR, dClass, encPwd );
-               //} 
+
                
                pwd = decryptor.decrypt(encPwd);
                
@@ -92,6 +83,9 @@ public class AafService extends BaseLoggingClass {
        }
                
        private void initAafService( ServiceType t ) {
+               DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+               useAAF= "true".equalsIgnoreCase(p.getProperty("UseAAF", "true"));
+               
                ctype = t;
                aaf = new AafConnection( getCred( true ) );
        }
@@ -101,7 +95,11 @@ public class AafService extends BaseLoggingClass {
                int rc = -1;
                logger.info( "entry: addPerm() "  );
                String pURL = aafURL + "authz/perm";
-               rc = aaf.postAaf( perm, pURL );
+               if ( useAAF ) {
+                       rc = aaf.postAaf( perm, pURL );
+               } else {
+                       rc = 201;
+               }
         switch( rc ) {
        case 401:
        case 403:
@@ -112,7 +110,7 @@ public class AafService extends BaseLoggingClass {
                break;
                
        case 201:
-               logger.info( "expected response);
+               logger.info( "expected response: " + rc);
                break;
                default :
                logger.error( "Unexpected response: " + rc );
@@ -127,7 +125,12 @@ public class AafService extends BaseLoggingClass {
                logger.info( "entry: addGrant() "  );
 
                String pURL = aafURL + "authz/role/perm";
-               rc = aaf.postAaf( grant, pURL );
+               if ( useAAF ) {
+                       rc = aaf.postAaf( grant, pURL );
+               } else {
+                       rc = 201;
+               }
+               
         switch( rc ) {
        case 401:
        case 403:
@@ -155,7 +158,12 @@ public class AafService extends BaseLoggingClass {
                logger.info( "entry: delGrant() "  );
 
                String pURL = aafURL + "authz/role/:" + grant.getRole() + "/perm";
-               rc = aaf.delAaf( grant, pURL );
+               
+               if ( useAAF ) {
+                       rc = aaf.delAaf( grant, pURL );
+               } else {
+                       rc = 200;
+               }
         switch( rc ) {
        case 401:
                case 403:
@@ -177,4 +185,6 @@ public class AafService extends BaseLoggingClass {
                
                return rc;
        }
+
+
 }