通过SAS Base上的程序在SAS Metadata Server中创建内部帐户 [英] Creating Internal Accounts in SAS Metadata Server by programm on SAS Base

查看:198
本文介绍了通过SAS Base上的程序在SAS Metadata Server中创建内部帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用proc metadata以编程方式创建内部帐户. 下面的代码部分使用外部登录"创建人.

I'm trying to create Internal Accounts programmaticaly by using proc metadata. The code section below creates person with External Login.

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>";

要创建ExternalLogin,我们可以设置属性Password,并且在SAS元数据中将自动对其进行加密. 但是要创建InternalLogin类型的对象,必须使密码的 hash 值和 salt 成为必需.我知道标准的sas002加密方法,但是在使用proc pwencode的情况下如何获取salt的值?

To create ExternalLogin we can set attribute Password, and in SAS Metadata it will be encrypted automaticaly. But to create InternalLogin type of object it is necessary to make the hash value of the password and the salt. I know that the standard sas002 encryption method, but in the case of using proc pwencode how to obtain the value of salt?

是否可以使用SAS Base创建InternalLogin?

Is it possible create InternalLogin by using SAS Base?

感谢.

推荐答案

等等.我发现了文章可以告诉我们如何针对此问题创建存储过程.我的回答是对文章的补充.
该方法基于来自sas programm的execute java方法.

So on. I found an article that can tell us how to create Stored Process for this problem. My answer is addition to the article.
The approach is base on execute java methods from sas programm.

我已经修改了文章中的课程.单独的代码连接到元数据服务器并创建InternalLogin

I've modified class from article. Separate code to connect to metadata server and create 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变量.

2. Resolve depends

Pay attention to imports in class. To enable execute the code below necessary set CLASSPATH enironment variable.

在Linux上,您可以在%SASConfig%/Lev1/level_env_usermods.sh中添加下一个命令:

On linux you can add the next command in %SASConfig%/Lev1/level_env_usermods.sh:

export CLASSPATH=$CLASSPATH:%pathToJar%

在Windows上,您可以通过Advanced system settings

On Windows you can add/change environment variable by Advanced system settings

那么您应该在哪里搜索jar文件?它们在文件夹中:

So where should you search jar files? They are in folder:

%SASHome%/SASVersionedJarRepository/eclipse/plugins/

%SASHome%/SASVersionedJarRepository/eclipse/plugins/

我应该在路径中包含哪些文件?

Which files i should include in path?

我已包括OMI中使用的所有内容(打开元数据接口).我还添加了log4j.jar(如果没有该jar,则无法使用.您的提示会有所帮助):

I've include all that used in OMI(Open Metadata Interface).Also I've added log4j.jar (not working without this jar. Your promts will be helpful):

  • 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!)
  • 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 (YOUR JAR FROM THE NEXT STEP!)

从最近的发行版中选择文件.示例:

Choose files from nearest release. Example:

这里是我从v940m3f(修复版本)设置的文件.
其他方式是此处.

Here I'm set file from v940m3f (fix release).
Other ways is here.

我尝试在SAS中使用内部javac.exe,但是无法正常工作.因此,您需要下载JDK来编译jar.我已经创建了蝙蝠文件:

I'm tried use internal javac.exe into SAS, but it's not worked properly. So ou need to download JDK to compile jars. I've create Bat-file:

"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

如果在SAS中使用的JDK版本较高,则

参数-source-target将很有帮助.您可以通过以下方式查看"sas" -java的版本:

Paramethers -source and -target will helpful if your version of JDK is upper, that usses in SAS. Version of "sas"-java you can see by:

PROC javainfo all;
run; 

搜索日志中的下一个字符串:

Search the next string in log:

java.vm.specification.version = 1.7

java.vm.specification.version = 1.7

4.最后. SAS基本呼叫

现在,我们可以通过此方法调用Java代码(所有可用方法

在日志中:

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


现在可以测试了.创建没有密码的新用户.


Now time to test. Create new user with no passwords.

执行代码:

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

现在我们的用户拥有InternalLogin对象.

Now our user has InternalLogin object.

感谢.

这篇关于通过SAS Base上的程序在SAS Metadata Server中创建内部帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆