Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将登录的用户更改为其他临时用户?_Java_Login Control - Fatal编程技术网

Java 如何将登录的用户更改为其他临时用户?

Java 如何将登录的用户更改为其他临时用户?,java,login-control,Java,Login Control,在我的系统中,我希望只有管理员帐户才能访问特定文件夹 因此,当客户端以自己的身份登录时,单击打开文件链接,我希望它切换到管理员帐户临时打开文件。关闭打开文件后,帐户将返回到客户端的原始帐户 我发现可以通过以下链接在ASP.NET的C#中完成: 想知道我们是否可以在Java中实现这一点吗?您可以通过Runetim.exec()调用RUNAS,以不同的用户身份执行任务 RUNAS用法: 运行方式[[/noprofile |/profile][/env][/savecred |/netonly]]

在我的系统中,我希望只有管理员帐户才能访问特定文件夹

因此,当客户端以自己的身份登录时,单击打开文件链接,我希望它切换到管理员帐户临时打开文件。关闭打开文件后,帐户将返回到客户端的原始帐户

我发现可以通过以下链接在ASP.NET的C#中完成:


想知道我们是否可以在Java中实现这一点吗?

您可以通过Runetim.exec()调用RUNAS,以不同的用户身份执行任务

RUNAS用法:
运行方式[[/noprofile |/profile][/env][/savecred |/netonly]]
/用户:程序
RUNAS[[/noprofile |/profile][/env][/savecred]]
/智能卡[/user:]程序
运行方式/信任级别:程序
/noprofile指定不应加载用户的配置文件。
这会使应用程序加载更快,但是
可能导致某些应用程序出现故障。
/配置文件指定应加载用户的配置文件。
这是默认设置。
/env使用当前环境而不是用户的环境。
/仅当指定的凭据用于远程登录时使用
仅限访问。
/savecred使用用户以前保存的凭据。
此选项在Windows 7 Home或Windows 7 Starter版本上不可用
并将被忽略。
/如果凭据是由供应商提供的,则使用智能卡
智能卡。
/用户应该在表单中USER@DOMAIN或域\用户
/ShowTrustLevel显示可以用作参数的信任级别
到信任级别。
/信任级别应为枚举的级别之一
in/ShowTrustLevel。
EXE的程序命令行。参见下面的示例
示例:
>runas/noprofile/user:mymachine\administrator cmd
>runas/profile/env/user:mydomain\admin“mmc%windir%\system32\dsa.msc”
>运行方式/环境/用户:user@domain.microsoft.com“记事本\“我的文件.txt\”

如果您使用的是Java EE,我认为您可以使用@RunAs注释(但我没有尝试):

编辑:

这里有一个关于JAAS“doAs”的链接,但我还没有研究它:

如果你能,我会非常惊讶。如果有必要,我建议通过Runtime.exec()从Java运行.NET中的代码。如果客户端用户必须打开文件,为什么不授予他访问权限?因为整个系统都是Java。我无法使用.NET进行此操作。客户不希望客户端具有该文件夹的访问权限。他们只想让他对特定文件拥有只读访问权限。这肯定是Windows特定的。我想知道OP在为什么平台寻求解决方案…@TheBlastOne“管理员帐户”和“临时切换到管理员帐户”是windows特有的术语。啊。我认为它也是UNIX世界中超级用户或根用户的同义词。@TheBlastOne您可能是对的,在这种情况下,您需要在UNIX上运行
sudo命令。好吧,这完全是平台特有的。嗨,彼得,谢谢你的回复。我对符文做了一些研究。似乎只能打开或执行其他应用程序或命令。例如,当我在服务器中运行“runas”命令以通过excel打开文件时。它将在服务器上打开excel,而不是在客户端计算机上。我说得对吗?我不知道如何让客户在本地机器上打开文件。嗨,Puce,谢谢你的回复。我浏览了您提供的链接中的JAAS文档。这似乎很复杂。我将尝试使用您首先提到的@RunAs注释方法。谢谢。
RUNAS USAGE:

RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
        /user:<UserName> program

RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
        /smartcard [/user:<UserName>] program

RUNAS /trustlevel:<TrustLevel> program

   /noprofile        specifies that the user's profile should not be loaded.
                     This causes the application to load more quickly, but
                     can cause some applications to malfunction.
   /profile          specifies that the user's profile should be loaded.
                     This is the default.
   /env              to use current environment instead of user's.
   /netonly          use if the credentials specified are for remote
                     access only.
   /savecred         to use credentials previously saved by the user.
                     This option is not available on Windows 7 Home or Windows 7 Starter Editions
                     and will be ignored.
   /smartcard        use if the credentials are to be supplied from a
                     smartcard.
   /user             <UserName> should be in form USER@DOMAIN or DOMAIN\USER
   /showtrustlevels  displays the trust levels that can be used as arguments
                     to /trustlevel.
   /trustlevel       <Level> should be one of levels enumerated
                     in /showtrustlevels.
   program         command line for EXE.  See below for examples

Examples:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""