waffle.servlet.WindowsPrincipal类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中waffle.servlet.WindowsPrincipal类的一些代码示例,展示了WindowsPrincipal类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WindowsPrincipal类的具体详情如下:
包路径:waffle.servlet.WindowsPrincipal
类名称:WindowsPrincipal

WindowsPrincipal介绍

[英]A Windows Principal.
[中]一位Windows校长。

代码示例

代码示例来源:origin: Waffle/waffle

/**
 * Remote username.
 *
 * @return the remote user
 */
@Override
public String getRemoteUser() {
  return this.principal.getName();
}

代码示例来源:origin: Waffle/waffle

/**
 * Gets the roles.
 *
 * @param windowsIdentity
 *            the windows identity
 * @param principalFormat
 *            the principal format
 * @param roleFormat
 *            the role format
 * @return the roles
 */
private static List<String> getRoles(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
    final PrincipalFormat roleFormat) {
  final List<String> roles = new ArrayList<>();
  roles.addAll(WindowsPrincipal.getPrincipalNames(windowsIdentity, principalFormat));
  for (final IWindowsAccount group : windowsIdentity.getGroups()) {
    roles.addAll(WindowsPrincipal.getRoleNames(group, roleFormat));
  }
  return roles;
}

代码示例来源:origin: com.github.dblock.waffle/waffle-spring-security4

@Override
public Authentication authenticate(final Authentication authentication) {
  final UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
  final IWindowsIdentity windowsIdentity = this.authProvider.logonUser(auth.getName(), auth.getCredentials()
      .toString());
  WindowsAuthenticationProvider.LOGGER.debug("logged in user: {} ({})", windowsIdentity.getFqn(),
      windowsIdentity.getSidString());
  if (!this.allowGuestLogin && windowsIdentity.isGuest()) {
    WindowsAuthenticationProvider.LOGGER.warn("guest login disabled: {}", windowsIdentity.getFqn());
    throw new GuestLoginDisabledAuthenticationException(windowsIdentity.getFqn());
  }
  final WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity, this.principalFormat,
      this.roleFormat);
  WindowsAuthenticationProvider.LOGGER.debug("roles: {}", windowsPrincipal.getRolesString());
  final WindowsAuthenticationToken token = new WindowsAuthenticationToken(windowsPrincipal,
      this.grantedAuthorityFactory, this.defaultGrantedAuthority);
  WindowsAuthenticationProvider.LOGGER.info("successfully logged in user: {}", windowsIdentity.getFqn());
  return token;
}

代码示例来源:origin: salyh/elasticsearch-security-plugin

public List<String> getUserRoles() {
  if (request.getUserPrincipal() instanceof GenericPrincipal) {
    final GenericPrincipal wp = (GenericPrincipal) request
        .getUserPrincipal();
    if (wp.getRoles() != null) {
      final List<String> roles = Arrays.asList(wp.getRoles());
      log.debug("GenericPrincipal roles: " + roles);
      return roles;
    }
  }
  if (request.getUserPrincipal() instanceof WindowsPrincipal) {
    final WindowsPrincipal wp = (WindowsPrincipal) request
        .getUserPrincipal();
    log.debug("WindowsPrincipal roles: " + wp.getRolesString());
    log.debug("WindowsPrincipal groups: " + wp.getGroups());
    if (wp.getRolesString() != null) {
      return Arrays.asList(wp.getRolesString().split(","));
    }
  }
  /*if (this.request.getUserPrincipal() instanceof ActiveDirectoryPrincipal) {
    final ActiveDirectoryPrincipal ap = (ActiveDirectoryPrincipal) this.request
        .getUserPrincipal();
    log.debug("ActiveDirectoryPrincipal roles: " + ap.getRoles());
    return ap.getRoles();
  }*/
  return null;
}

代码示例来源:origin: Waffle/waffle

/**
 * A windows principal.
 *
 * @param windowsIdentity
 *            Windows identity.
 * @param principalFormat
 *            Principal format.
 * @param roleFormat
 *            Role format.
 */
public WindowsPrincipal(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
    final PrincipalFormat roleFormat) {
  this.identity = windowsIdentity;
  this.fqn = windowsIdentity.getFqn();
  this.sid = windowsIdentity.getSid();
  this.sidString = windowsIdentity.getSidString();
  this.groups = WindowsPrincipal.getGroups(windowsIdentity.getGroups());
  this.roles = WindowsPrincipal.getRoles(windowsIdentity, principalFormat, roleFormat);
}

代码示例来源:origin: Waffle/waffle

/**
 * Instantiates a new windows authentication token.
 *
 * @param identity
 *            The {@link WindowsPrincipal} for which this token exists.
 * @param grantedAuthorityFactory
 *            used to construct {@link GrantedAuthority}s for each of the groups to which the
 *            {@link WindowsPrincipal} belongs
 * @param defaultGrantedAuthority
 *            if not null, this {@link GrantedAuthority} will always be added to the granted authorities list
 */
public WindowsAuthenticationToken(final WindowsPrincipal identity,
    final GrantedAuthorityFactory grantedAuthorityFactory, final GrantedAuthority defaultGrantedAuthority) {
  this.principal = identity;
  this.authorities = new ArrayList<>();
  if (defaultGrantedAuthority != null) {
    this.authorities.add(defaultGrantedAuthority);
  }
  for (final WindowsAccount group : this.principal.getGroups().values()) {
    this.authorities.add(grantedAuthorityFactory.createGrantedAuthority(group));
  }
}

代码示例来源:origin: com.github.waffle/waffle-shiro

代码示例来源:origin: Waffle/waffle

final WindowsPrincipal windowsPrincipal = (WindowsPrincipal) principal;
if (this.impersonate && windowsPrincipal.getIdentity() == null) {
if (this.impersonate) {
  NegotiateSecurityFilter.LOGGER.debug("re-impersonating user");
  ctx = windowsPrincipal.getIdentity().impersonate();

代码示例来源:origin: Waffle/waffle

@Override
public Authentication authenticate(final Authentication authentication) {
  final UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
  IWindowsIdentity windowsIdentity;
  try {
    windowsIdentity = this.authProvider.logonUser(auth.getName(), auth.getCredentials().toString());
  } catch (final Win32Exception e) {
    throw new AuthenticationServiceException(e.getMessage(), e);
  }
  WindowsAuthenticationProvider.LOGGER.debug("logged in user: {} ({})", windowsIdentity.getFqn(),
      windowsIdentity.getSidString());
  if (!this.allowGuestLogin && windowsIdentity.isGuest()) {
    WindowsAuthenticationProvider.LOGGER.warn("guest login disabled: {}", windowsIdentity.getFqn());
    throw new GuestLoginDisabledAuthenticationException(windowsIdentity.getFqn());
  }
  final WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity, this.principalFormat,
      this.roleFormat);
  WindowsAuthenticationProvider.LOGGER.debug("roles: {}", windowsPrincipal.getRolesString());
  final WindowsAuthenticationToken token = new WindowsAuthenticationToken(windowsPrincipal,
      this.grantedAuthorityFactory, this.defaultGrantedAuthority);
  WindowsAuthenticationProvider.LOGGER.info("successfully logged in user: {}", windowsIdentity.getFqn());
  return token;
}

代码示例来源:origin: com.github.waffle/waffle-jna

/**
 * A windows principal.
 *
 * @param windowsIdentity
 *            Windows identity.
 * @param principalFormat
 *            Principal format.
 * @param roleFormat
 *            Role format.
 */
public WindowsPrincipal(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
    final PrincipalFormat roleFormat) {
  this.identity = windowsIdentity;
  this.fqn = windowsIdentity.getFqn();
  this.sid = windowsIdentity.getSid();
  this.sidString = windowsIdentity.getSidString();
  this.groups = WindowsPrincipal.getGroups(windowsIdentity.getGroups());
  this.roles = WindowsPrincipal.getRoles(windowsIdentity, principalFormat, roleFormat);
}

代码示例来源:origin: Waffle/waffle

/**
 * Instantiates a new windows authentication token.
 *
 * @param identity
 *            The {@link WindowsPrincipal} for which this token exists.
 * @param grantedAuthorityFactory
 *            used to construct {@link GrantedAuthority}s for each of the groups to which the
 *            {@link WindowsPrincipal} belongs
 * @param defaultGrantedAuthority
 *            if not null, this {@link GrantedAuthority} will always be added to the granted authorities list
 */
public WindowsAuthenticationToken(final WindowsPrincipal identity,
    final GrantedAuthorityFactory grantedAuthorityFactory, final GrantedAuthority defaultGrantedAuthority) {
  this.principal = identity;
  this.authorities = new ArrayList<>();
  if (defaultGrantedAuthority != null) {
    this.authorities.add(defaultGrantedAuthority);
  }
  for (final WindowsAccount group : this.principal.getGroups().values()) {
    this.authorities.add(grantedAuthorityFactory.createGrantedAuthority(group));
  }
}

代码示例来源:origin: Waffle/waffle

windowsIdentity.getSidString());
final Principal principal = new WindowsPrincipal(windowsIdentity);
token.setPrincipal(principal);

代码示例来源:origin: com.github.waffle/waffle-jna

final WindowsPrincipal windowsPrincipal = (WindowsPrincipal) principal;
if (this.impersonate && windowsPrincipal.getIdentity() == null) {
if (this.impersonate) {
  NegotiateSecurityFilter.LOGGER.debug("re-impersonating user");
  ctx = windowsPrincipal.getIdentity().impersonate();

代码示例来源:origin: Waffle/waffle

this.roleFormat);
} else {
  windowsPrincipal = new WindowsPrincipal(windowsIdentity, this.principalFormat, this.roleFormat);
NegotiateSecurityFilter.LOGGER.debug("roles: {}", windowsPrincipal.getRolesString());
subject.getPrincipals().add(windowsPrincipal);
request.getSession(false).setAttribute("javax.security.auth.subject", subject);

代码示例来源:origin: Waffle/waffle

@Override
public String toString() {
  return this.getName();
}

代码示例来源:origin: com.github.dblock.waffle/waffle-jna

/**
 * A windows principal.
 * 
 * @param windowsIdentity
 *            Windows identity.
 * @param principalFormat
 *            Principal format.
 * @param roleFormat
 *            Role format.
 */
public WindowsPrincipal(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
    final PrincipalFormat roleFormat) {
  this.identity = windowsIdentity;
  this.fqn = windowsIdentity.getFqn();
  this.sid = windowsIdentity.getSid();
  this.sidString = windowsIdentity.getSidString();
  this.groups = WindowsPrincipal.getGroups(windowsIdentity.getGroups());
  this.roles = WindowsPrincipal.getRoles(windowsIdentity, principalFormat, roleFormat);
}

代码示例来源:origin: com.github.waffle/waffle-spring-security3

/**
 * Instantiates a new windows authentication token.
 *
 * @param identity
 *            The {@link WindowsPrincipal} for which this token exists.
 * @param grantedAuthorityFactory
 *            used to construct {@link GrantedAuthority}s for each of the groups to which the
 *            {@link WindowsPrincipal} belongs
 * @param defaultGrantedAuthority
 *            if not null, this {@link GrantedAuthority} will always be added to the granted authorities list
 */
public WindowsAuthenticationToken(final WindowsPrincipal identity,
    final GrantedAuthorityFactory grantedAuthorityFactory, final GrantedAuthority defaultGrantedAuthority) {
  this.principal = identity;
  this.authorities = new ArrayList<>();
  if (defaultGrantedAuthority != null) {
    this.authorities.add(defaultGrantedAuthority);
  }
  for (final WindowsAccount group : this.principal.getGroups().values()) {
    this.authorities.add(grantedAuthorityFactory.createGrantedAuthority(group));
  }
}

代码示例来源:origin: com.github.dblock.waffle/waffle-jna

final WindowsPrincipal windowsPrincipal = (WindowsPrincipal) principal;
if (this.impersonate && windowsPrincipal.getIdentity() == null) {
if (this.impersonate) {
  NegotiateSecurityFilter.LOGGER.debug("re-impersonating user");
  ctx = windowsPrincipal.getIdentity().impersonate();

代码示例来源:origin: com.github.dblock.waffle/waffle-jna

/**
 * Gets the roles.
 *
 * @param windowsIdentity
 *            the windows identity
 * @param principalFormat
 *            the principal format
 * @param roleFormat
 *            the role format
 * @return the roles
 */
private static List<String> getRoles(final IWindowsIdentity windowsIdentity, final PrincipalFormat principalFormat,
    final PrincipalFormat roleFormat) {
  final List<String> roles = new ArrayList<>();
  roles.addAll(WindowsPrincipal.getPrincipalNames(windowsIdentity, principalFormat));
  for (final IWindowsAccount group : windowsIdentity.getGroups()) {
    roles.addAll(WindowsPrincipal.getRoleNames(group, roleFormat));
  }
  return roles;
}

代码示例来源:origin: com.github.dblock.waffle/waffle-jna

this.roleFormat);
} else {
  windowsPrincipal = new WindowsPrincipal(windowsIdentity, this.principalFormat, this.roleFormat);
NegotiateSecurityFilter.LOGGER.debug("roles: {}", windowsPrincipal.getRolesString());
subject.getPrincipals().add(windowsPrincipal);
session.setAttribute("javax.security.auth.subject", subject);

相关文章