Creating internal accounts in a SAS metadata server using a SAS-based program

I am trying to create an internal programmaticaly account using proc metadata. In the code section below, a person with an external input is created.

put"<Person Name=%str(%')&&PersonName&i.%str(%')>";
   put"<Logins>";
      put"<Login Name=%str(%')Login.&&PersonName&i.%str(%')  Password=%str(%')&&word&i.%str(%')/>";
   put"</Logins>";
put"</Person>";

To create an ExternalLogin, we can set the attribute Password, and in the SAS metadata it will be automatically encrypted. But to create the type of the InternalLogin object, you need to have the hash value of the password and salt . I know that the standard encryption method sas002, but in case of use proc pwencode, how to get the salt value?

Is it possible to create InternalLogin using the SAS base?

Thanx.

+4
1

. article, , . - .
java- sas-.

1. Prerare setPasswd.java

. InternalLogin

import java.rmi.RemoteException;
import com.sas.metadata.remote.AssociationList;
import com.sas.metadata.remote.CMetadata;
import com.sas.metadata.remote.Person;
import com.sas.metadata.remote.MdException;
import com.sas.metadata.remote.MdFactory;
import com.sas.metadata.remote.MdFactoryImpl;
import com.sas.metadata.remote.MdOMIUtil;
import com.sas.metadata.remote.MdOMRConnection;
import com.sas.metadata.remote.MdObjectStore;
import com.sas.metadata.remote.MetadataObjects;
import com.sas.metadata.remote.PrimaryType;
import com.sas.metadata.remote.Tree;
import com.sas.meta.SASOMI.ISecurity_1_1;
import com.sas.iom.SASIOMDefs.VariableArray2dOfStringHolder;

public class setPasswd {
  String serverName = null;
  String serverPort = null;
  String serverUser = null;
  String serverPass = null;
  MdOMRConnection connection = null;
  MdFactoryImpl _factory = null;
  ISecurity_1_1 iSecurity = null;
  MdObjectStore objectStore = null;
  Person person = null;

    public int connectToMetadata(String name, String port, String user, String pass){
    try {
            serverName = name;
          serverPort = port;
          serverUser = user;
          serverPass = pass;
      _factory = new MdFactoryImpl(false);
      connection = _factory.getConnection();
      connection.makeOMRConnection(serverName, serverPort, serverUser, serverPass);
      iSecurity = connection.MakeISecurityConnection();
      return 0;

    }catch(Exception e){
      return 1;
    }
    }

    public setPasswd(){};

    public int changePasswd(String IdentityName, String IdentityPassword) {
        try
        {
            //
            // This block obtains the person metadata ID that is needed to change the password
            //
            // Defines the GetIdentityInfo 'ReturnUnrestrictedSource' option.
            final String[][] options ={{"ReturnUnrestrictedSource",""}};
            // Defines a stringholder for the info output parameter.
            VariableArray2dOfStringHolder info = new VariableArray2dOfStringHolder();
            // Issues the GetInfo method for the provided iSecurity connection user.
            iSecurity.GetInfo("GetIdentityInfo","Person:"+IdentityName, options, info);
            String[][] returnArray = info.value;
            String personMetaID = new String();
            for (int i=0; i< returnArray.length; i++ )
            {
                System.out.println(returnArray[i][0] + "=" + returnArray[i][1]);
                if (returnArray[i][0].compareTo("IdentityObjectID") == 0) {
                    personMetaID = returnArray[i][1];
                }
            }
            objectStore = _factory.createObjectStore();
            person = (Person) _factory.createComplexMetadataObject(objectStore, IdentityName, MetadataObjects.PERSON, personMetaID);
            iSecurity.SetInternalPassword(IdentityName, IdentityPassword);
            person.updateMetadataAll();
            System.out.println("Password has been changed.");
            return 0; // success
        }
        catch (MdException e)
        {
            Throwable t = e.getCause();
            if (t != null)
            {
                String ErrorType = e.getSASMessageSeverity();
                String ErrorMsg = e.getSASMessage();
                if (ErrorType == null)
                {
                    // If there is no SAS server message, write a Java/CORBA message.
                }
                else
                {
                    // If there is a message from the server:
                    System.out.println(ErrorType + ": " + ErrorMsg);
                }
                if (t instanceof org.omg.CORBA.COMM_FAILURE)
                {
                    // If there is an invalid port number or host name:
                    System.out.println(e.getLocalizedMessage());
                }
                else if (t instanceof org.omg.CORBA.NO_PERMISSION)
                {
                    // If there is an invalid user ID or password:
                    System.out.println(e.getLocalizedMessage());
                }
            }
            else
            {
                // If we cannot find a nested exception, get message and print.
                System.out.println(e.getLocalizedMessage());
            }
            // If there is an error, print the entire stack trace.
            e.printStackTrace();
        }
        catch (RemoteException e)
        {
            // Unknown exception.
            e.printStackTrace();
        }
        catch (Exception e)
        {
            // Unknown exception.
            e.printStackTrace();
        }
        System.out.println("Failure: Password has NOT been changed.");
        return 1; // failure
    }
}

2.

. , CLASSPATH enironment.

linux %SASConfig%/Lev1/level_env_usermods.sh:

export CLASSPATH=$CLASSPATH:%pathToJar%

Windows / Advanced system settings


, jar? :

% SASHome%/SASVersionedJarRepository/eclipse/plugins/

?

, OMI ( ). log4j.jar ( . ):

  • sas.oma.joma.jar
  • sas.oma.joma.rmt.jar
  • sas.oma.omi.jar
  • sas.svc.connection.jar
  • sas.core.jar
  • sas.entities.jar
  • sas.security.sspi.jar
  • log4j.jar
  • setPasswd.jar ( JAR !)

. :

enter image description here

v940m3f ().
.

3. setPasswd.jar

javac.exe SAS, . JDK . Bat :

"C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe" -source 1.7  -target 1.7 setPasswd.java
"C:\Program Files\Java\jdk1.8.0_121\bin\jar" -cf setPasswd.jar setPasswd.class

-source -target , JDK - , SAS. "sas" -java :

PROC javainfo all;
run; 

:

java.vm.specification.version = 1.7

4. . SAS

Java ( ):

data test;
      dcl javaobj j ("setPasswd");
      j.callIntMethod("connectToMetadata", "%SERVER%", "%PORT%", "%ADMIN%", "%{SAS002}HASHPASSORPASS%", rc1);
      j.callIntMethod("changePasswd", "testPassLogin", "pass1", rc2);
      j.delete();
run;

:

UserClass=Normal  
AuthenticatedUserid=Unknown  
IdentityName=testPass  
IdentityType=Person  
IdentityObjectID=A56RQPC2.AP00000I  
Password has been changed.  

. .

enter image description here

:

data test;
      dcl javaobj j ("setPasswd");
      j.callIntMethod("connectToMetadata", "&server.", "&port.", "&adm", "&pass", rc1);
      j.callIntMethod("changePasswd", "TestUserForStack", "Overflow", rc2);
      j.delete();
run;

InternalLogin.

enter image description here

Thanx.

+2

Source: https://habr.com/ru/post/1668360/


All Articles