本文整理汇总了C#中System.Security.Principal.SecurityIdentifier.Translate方法的典型用法代码示例。如果您正苦于以下问题:C# SecurityIdentifier.Translate方法的具体用法?C# SecurityIdentifier.Translate怎么用?C# SecurityIdentifier.Translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Principal.SecurityIdentifier
的用法示例。
在下文中一共展示了SecurityIdentifier.Translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddUrlAcl
public static void AddUrlAcl(string address)
{
var everyoneID = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var ntAccount = (NTAccount)everyoneID.Translate(typeof(NTAccount));
AddUrlAcl(address, ntAccount.Value);
}
示例2: TakeOwnership
public static void TakeOwnership(string FD)
{
try
{
var myProcToken = new AccessTokenProcess(Process.GetCurrentProcess().Id, TokenAccessType.TOKEN_ALL_ACCESS | TokenAccessType.TOKEN_ADJUST_PRIVILEGES);
myProcToken.EnablePrivilege(new Microsoft.Win32.Security.TokenPrivilege(Microsoft.Win32.Security.TokenPrivilege.SE_TAKE_OWNERSHIP_NAME, true));
SecurityIdentifier identifier = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
NTAccount identity = (NTAccount)identifier.Translate(typeof(NTAccount));
if (File.Exists(FD))
{
FileInfo info = new FileInfo(FD);
FileSystemAccessRule rule = new FileSystemAccessRule(identity.Value, FileSystemRights.FullControl, AccessControlType.Allow);
FileSecurity accessControl = info.GetAccessControl(AccessControlSections.Owner);
accessControl.SetOwner(new NTAccount(identity.Value));
info.SetAccessControl(accessControl);
accessControl.AddAccessRule(rule);
info.SetAccessControl(accessControl);
}
if (Directory.Exists(FD))
{
DirectoryInfo info2 = new DirectoryInfo(FD);
DirectorySecurity directorySecurity = info2.GetAccessControl(AccessControlSections.All);
directorySecurity.SetOwner(identity);
info2.SetAccessControl(directorySecurity);
directorySecurity.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
info2.SetAccessControl(directorySecurity);
}
Clear(FD);
}
catch (Exception)
{
}
}
示例3: _init
private void _init() {
var physicalApplicationPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
physicalApplicationPath = Utl.NormalizeDir(Directory.GetParent(physicalApplicationPath).FullName);
this.logFileName = physicalApplicationPath + "xlfrpt2_srvc.log";
this.log_msg("*************************************** Инициализация \"Очереди отчетов\"... ***************************************************");
this.log_msg("\tЗагрузка конфигурации...");
this._cfg = CConfigSys.load(physicalApplicationPath, this.logFileName);
this._cfg.msgLogWriter = this.log_msg;
this._cfg.errLogWriter = this.log_err;
this.log_msg("\tКонфигурация загружена.");
this.log_msg("\tИнициализация сервера Ipc...");
// Create the server channel.
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
NTAccount account = sid.Translate(typeof(NTAccount)) as NTAccount;
IDictionary channelProperties = new Hashtable();
channelProperties["portName"] = "Bio.Handlers.XLFRpt2.CQueueRemoteControl.Ipc";
channelProperties["exclusiveAddressUse"] = false;
channelProperties["authorizedGroup"] = account.Value;
channelProperties["typeFilterLevel"] = TypeFilterLevel.Full;
IpcChannel serverChannel = new IpcChannel(channelProperties, null, null);
ChannelServices.RegisterChannel(serverChannel, false);
// Expose an object for remote calls.
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(CQueueRemoteControl), "QueueRemoteControl.rem",
WellKnownObjectMode.Singleton);
this.log_msg("\tСервер Ipc инициализирован.");
this.log_msg("*************************************** Инициализация \"Очереди отчетов\" выполнена. ***************************************************");
}
示例4: GetLoginName
// Gets the login name of the Livelink user that the specified SharePoint user maps to.
public string GetLoginName(SPUser user) {
if (user == null)
throw new ArgumentNullException("user");
// SPUser.LoginName contains domain\user for web applications with the pure Windows
// authentication but if the claim-based authentication is used it returns an encoded
// claim that must be decoded to the actual user login name first.
var claim = SPClaimProviderManager.Local.ConvertSPUserToClaim(user);
string login;
if (SPClaimTypes.Equals(claim.ClaimType, SPClaimTypes.UserLogonName) ||
SPClaimTypes.Equals(claim.ClaimType,
"http://schemas.microsoft.com/sharepoint/2009/08/claims/processidentitylogonname")) {
login = claim.Value;
} else if (SPClaimTypes.Equals(claim.ClaimType, SPClaimTypes.UserIdentifier) ||
SPClaimTypes.Equals(claim.ClaimType,
"http://schemas.microsoft.com/sharepoint/2009/08/claims/processidentitysid") ||
SPClaimTypes.Equals(claim.ClaimType,
"http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid")) {
var identifier = new SecurityIdentifier(claim.Value);
login = identifier.Translate(typeof(NTAccount)).Value;
} else {
throw new ApplicationException(
"No claim with either user name or SID was found to infer the login name from.");
}
// Here we assume either plain user name or a combination with the Windows domain.
var parts = login.Split('\\');
var name = parts.Length > 1 ? parts[1] : login;
var domain = parts.Length > 1 ? parts[0] : "";
return Pattern.ReplaceParameter("login", login).ReplaceParameter("user", name).
ReplaceParameter("domain", domain);
}
示例5: GetFullAccess
public static void GetFullAccess(string path)
{
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
IdentityReference act = sid.Translate(typeof(NTAccount));
FileSecurity sec = File.GetAccessControl(path);
sec.AddAccessRule(new FileSystemAccessRule(act, FileSystemRights.FullControl, AccessControlType.Allow));
File.SetAccessControl(path, sec);
}
示例6: CheckExplicitAccessRulesAndAllowToModify
/// <summary>
/// Remove explicit file rules and leave inherited rules only.
/// Allow built-in users to write and modify file.
/// </summary>
public static bool CheckExplicitAccessRulesAndAllowToModify(string fileName, bool applyFix)
{
var fileInfo = new FileInfo(fileName);
var fileSecurity = fileInfo.GetAccessControl();
fileSecurity.SetAccessRuleProtection(false, false);
var identity = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
// Get explicit file rules of FileSystemAccessRule type.
var rules = fileSecurity.GetAccessRules(true, true, typeof(NTAccount)).OfType<FileSystemAccessRule>();
var referenceValue = ((NTAccount)identity.Translate(typeof(NTAccount))).Value;
// Remove explicit permission.
var allowsWrite = false;
var allowsModify = false;
var rulesChanged = false;
foreach (var rule in rules)
{
if (rule.AccessControlType == AccessControlType.Allow && rule.IdentityReference.Value == referenceValue)
{
if (rule.FileSystemRights.HasFlag(FileSystemRights.Write))
{
allowsWrite = true;
continue;
}
if (rule.FileSystemRights.HasFlag(FileSystemRights.Modify))
{
allowsModify = true;
continue;
}
}
// If rule is not inherited from parent directory then...
if (!rule.IsInherited)
{
// Remove rules.
fileSecurity.RemoveAccessRule(rule);
rulesChanged = true;
}
}
if (applyFix)
{
if (!allowsWrite)
{
fileSecurity.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.Write, AccessControlType.Allow));
rulesChanged = true;
}
if (!allowsModify)
{
fileSecurity.AddAccessRule(new FileSystemAccessRule(identity, FileSystemRights.Modify, AccessControlType.Allow));
rulesChanged = true;
}
if (rulesChanged)
{
fileInfo.SetAccessControl(fileSecurity);
}
}
return rulesChanged;
}
示例7: GetGlobalGroupNames
public static ActionResult GetGlobalGroupNames(Session session)
{
session.Log("Drexyia - GetGlobalGroupNames - Begin");
var sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
var account = (NTAccount)sid.Translate(typeof(NTAccount));
session["UsersAccount"] = account.Value;
session.Log("Drexyia - GetGlobalGroupNames - UserAccount " + account.Value);
return ActionResult.Success;
}
示例8: SidToAccountName
private static string SidToAccountName(string sidString)
{
SecurityIdentifier sid = new SecurityIdentifier(sidString);
try
{
NTAccount account = (NTAccount)sid.Translate(typeof(NTAccount));
return account.ToString();
}
catch (IdentityNotMappedException)
{
return sidString;
}
}
示例9: ResolveUserNameFromSid
internal static string ResolveUserNameFromSid(string userSid)
{
try
{
var userIdentifier = new SecurityIdentifier(userSid);
IdentityReference userLoginReference = userIdentifier.Translate(typeof(NTAccount));
return userLoginReference.ToString();
}
catch
{
return null;
}
}
示例10: SetIpcChannel
private void SetIpcChannel()
{
// Get SID code for the Built in Administrators group
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.LocalSystemSid, null);
// Get the NT account related to the SID
NTAccount account = sid.Translate(typeof(NTAccount)) as NTAccount;
IDictionary sProperties = new Hashtable();
sProperties["portName"] = SvcConfiguration.IpcUriHost;
sProperties["authorizedGroup"] = account.Value;
BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
IpcServerChannel channel = new IpcServerChannel(sProperties, serverProvider);
ChannelServices.RegisterChannel(channel, true);
}
示例11: PipeRemotingServer
public PipeRemotingServer(string channelName, string serviceUri, int port, object remotingObject)
{
IDictionary props = new Hashtable();
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
string usersGroup = sid.Translate(typeof(NTAccount)).ToString();
props["pipe"] = serviceUri;
this.remotingObject = remotingObject;
SecureServerChannelSinkProvider sSink = GetSecureServerSink();
pipeChannel = new PipeServerChannel(props, sSink);
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
RemotingConfiguration.RegisterWellKnownServiceType(remotingObject.GetType(), serviceUri, WellKnownObjectMode.Singleton);
}
示例12: IpcRemotingServer
public IpcRemotingServer(string channelName, string serviceUri, int port, object remotingObject)
{
IDictionary props = new Hashtable();
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
string usersGroup = sid.Translate(typeof(NTAccount)).ToString();
props["authorizedGroup"] = usersGroup;
//props["channelName"] = channelName;
props["portName"] = port.ToString();
props["exclusiveAddressUse"] = false;
this.remotingObject = remotingObject;
SecureServerChannelSinkProvider sSink = GetSecureServerSink();
ipcChannel = new IpcServerChannel(props, sSink);
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
RemotingConfiguration.RegisterWellKnownServiceType(remotingObject.GetType(), serviceUri, WellKnownObjectMode.Singleton);
}
示例13: Main
internal static void Main(string[] args)
{
if (args == null || args.Length != 2)
{
System.Console.WriteLine(
"Get sid for the username. Usage: sid \"domain\\accountName\"");
System.Console.WriteLine(
"Get username for the sid. Usage: un sid");
System.Console.WriteLine(
"Sample: sid \"localPC\\localAccount\"");
System.Console.WriteLine(
"Sample: sid \"domain\\domainAccount\"");
System.Console.WriteLine(
"Sample: un S-1-5-21-589166251-1203392894-1708575535-1118");
return;
}
try
{
if (args.Length == 2 && args[0] == "un")
{
SecurityIdentifier sid = new SecurityIdentifier(args[1]);
System.Console.WriteLine("User: " + sid.Translate(typeof(System.Security.Principal.NTAccount)).Value);
return;
}
if (args.Length == 2 && args[0] == "sid")
{
NTAccount account = new NTAccount(args[0]);
System.Console.WriteLine("SID: " + account.Translate(typeof(System.Security.Principal.SecurityIdentifier)).Value);
}
}
catch (Exception ex)
{
System.Console.WriteLine("Exception happened when trying to map account for " +
args[1] + ". Exception text" + ex.ToString());
}
}
示例14: IdentifyCallback
private void IdentifyCallback(PVOID IdentifyCallbackContext, HRESULT OperationStatus,
WINBIO_UNIT_ID UnitId, WINBIO_IDENTITY Identity, WINBIO_BIOMETRIC_SUBTYPE SubFactor,
WINBIO_REJECT_DETAIL RejectDetail)
{
switch (OperationStatus)
{
case S_OK:
{
var accountSid = Identity.Value.AccountSid[0];
var sid = new SecurityIdentifier(accountSid.Data.ToArray(accountSid.Size), 0);
IdentityReference user = sid.Translate(typeof(NTAccount));
if (user != null)
IdentifySuccess(this, new AuthenticationSuccessEventArgs(user, (WinBioFinger)(int)SubFactor));
else
IdentifyFailed(this, new AuthenticationFailedEventArgs(WinBioError.NoAccount, WinBioRejectDetail.None));
break;
}
case WINBIO_E_UNKNOWN_ID:
{
IdentifyFailed(this, new AuthenticationFailedEventArgs(WinBioError.UnknownId, (WinBioRejectDetail)(int)RejectDetail));
break;
}
case WINBIO_E_BAD_CAPTURE:
{
IdentifyFailed(this, new AuthenticationFailedEventArgs(WinBioError.BadCapture, (WinBioRejectDetail)(int)RejectDetail));
break;
}
case WINBIO_E_CANCELED: break;
default:
{
IdentifyFailed(this, new AuthenticationFailedEventArgs(WinBioError.Failed, (WinBioRejectDetail)(int)RejectDetail));
break;
}
}
}
示例15: AlteraPermissaoPastas
private static void AlteraPermissaoPastas(string pasta)
{
DirectorySecurity oDirSec = Directory.GetAccessControl(pasta);
// Define o usuário Everyone (Todos)
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
//SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
NTAccount oAccount = sid.Translate(typeof(NTAccount)) as NTAccount;
oDirSec.PurgeAccessRules(oAccount);
FileSystemAccessRule fsAR = new FileSystemAccessRule(oAccount,
FileSystemRights.Modify,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow);
// Atribui a regra de acesso alterada
oDirSec.SetAccessRule(fsAR);
Directory.SetAccessControl(pasta, oDirSec);
}