org.springframework.security.core.Authentication.getName()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(291)

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

Authentication.getName介绍

暂无

代码示例

Official Spring framework guide

代码示例来源:origin: spring-guides/tut-react-and-spring-data-rest

@HandleBeforeCreate
  @HandleBeforeSave
  public void applyUserInformationUsingSecurityContext(Employee employee) {

    String name = SecurityContextHolder.getContext().getAuthentication().getName();
    Manager manager = this.managerRepository.findByName(name);
    if (manager == null) {
      Manager newManager = new Manager();
      newManager.setName(name);
      newManager.setRoles(new String[]{"ROLE_MANAGER"});
      manager = this.managerRepository.save(newManager);
    }
    employee.setManager(manager);
  }
}

代码示例来源:origin: apache/kylin

private String getUserName() {
  String username = SecurityContextHolder.getContext().getAuthentication().getName();
  if (StringUtils.isEmpty(username)) {
    username = "";
  }
  return username;
}

代码示例来源:origin: spring-projects/spring-session

/**
 * Tries to determine the principal's name from the given Session.
 *
 * @param session the session
 * @return the principal's name, or empty String if it couldn't be determined
 */
private static String resolvePrincipal(Session session) {
  String principalName = session
      .getAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME);
  if (principalName != null) {
    return principalName;
  }
  SecurityContext securityContext = session
      .getAttribute(SPRING_SECURITY_CONTEXT);
  if (securityContext != null
      && securityContext.getAuthentication() != null) {
    return securityContext.getAuthentication().getName();
  }
  return "";
}

代码示例来源:origin: apache/kylin

@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN)
public ProjectInstance createProject(ProjectInstance newProject) throws IOException {
  Message msg = MsgPicker.getMsg();
  String projectName = newProject.getName();
  String description = newProject.getDescription();
  LinkedHashMap<String, String> overrideProps = newProject.getOverrideKylinProps();
  ProjectInstance currentProject = getProjectManager().getProject(projectName);
  if (currentProject != null) {
    throw new BadRequestException(String.format(Locale.ROOT, msg.getPROJECT_ALREADY_EXIST(), projectName));
  }
  String owner = SecurityContextHolder.getContext().getAuthentication().getName();
  ProjectInstance createdProject = getProjectManager().createProject(projectName, owner, description,
      overrideProps);
  accessService.init(createdProject, AclPermission.ADMINISTRATION);
  logger.debug("New project created.");
  return createdProject;
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

logger.debug("Invalid id token hint", e);
} catch (InvalidClientException e) {
  logger.debug("Invalid client", e);
UserInfo ui = userInfoService.getByUsername(auth.getName());

代码示例来源:origin: apache/kylin

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  byte[] hashKey = hf.hashString(authentication.getName() + authentication.getCredentials()).asBytes();
  String userKey = Arrays.toString(hashKey);
    SecurityContextHolder.getContext().setAuthentication(authed);
  } else {
    try {
            details.getAuthorities());
      } else {
        user = new ManagedUser(authentication.getName(), "skippped-ldap", false, authed.getAuthorities());
      logger.debug("User {} authorities : {}", username, user.getAuthorities());
      if (!userService.userExists(username)) {
        userService.createUser(user);
      logger.error("Failed to auth user: " + authentication.getName(), e);
      throw e;
    logger.debug("Authenticated user " + authed.toString());

代码示例来源:origin: cloudfoundry/uaa

when(clientAuth.getName()).thenReturn("clientid");
SecurityContextHolder.getContext().setAuthentication(clientAuth);
clientDetails = mock(ClientDetails.class);
when(clientDetails.getAdditionalInformation()).thenReturn(mock(Map.class));

代码示例来源:origin: apache/nifi

return new AuthenticationResponse(userDetails.getDn(), credentials.getUsername(), expiration, issuer);
} else {
  logger.warn(String.format("Unable to determine user DN for %s, using username.", authentication.getName()));
  return new AuthenticationResponse(authentication.getName(), credentials.getUsername(), expiration, issuer);
return new AuthenticationResponse(authentication.getName(), credentials.getUsername(), expiration, issuer);
logger.debug(StringUtils.EMPTY, e);

代码示例来源:origin: apache/kylin

String userInfo = SecurityContextHolder.getContext().getAuthentication().getName();
QueryContext context = QueryContextFacade.current();
context.setUsername(userInfo);
context.setGroups(AclPermissionUtil.getCurrentUserGroups());
final Collection<? extends GrantedAuthority> grantedAuthorities = SecurityContextHolder.getContext()
    .getAuthentication().getAuthorities();
for (GrantedAuthority grantedAuthority : grantedAuthorities) {
  userInfo += ",";
  logger.debug("Return fake response, is exception? " + fakeResponse.getIsException());
  return fakeResponse;

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

Authentication authentication = this.grpcAuthenticationReader.readAuthentication(call, headers);
if (authentication == null) {
  log.debug("No credentials found: Continuing unauthenticated");
  try {
    return next.startCall(call, headers);
log.debug("Credentials found: Authenticating...");
authentication = this.authenticationManager.authenticate(authentication);
SecurityContextHolder.getContext().setAuthentication(authentication);
log.debug("Authentication successful: Continuing as {} ({})", authentication.getName(),
    authentication.getAuthorities());
try {

代码示例来源:origin: apache/kylin

String getCurrentUserName() {
  return SecurityContextHolder.getContext().getAuthentication().getName();
}

代码示例来源:origin: apache/nifi

@Override
public final AuthenticationResponse authenticate(final LoginCredentials credentials) throws InvalidLoginCredentialsException, IdentityAccessException {
  if (provider == null) {
    throw new IdentityAccessException("The Kerberos authentication provider is not initialized.");
  }
  try {
    // Perform the authentication
    final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(credentials.getUsername(), credentials.getPassword());
    logger.debug("Created authentication token for principal {} with name {} and is authenticated {}", token.getPrincipal(), token.getName(), token.isAuthenticated());
    final Authentication authentication = provider.authenticate(token);
    logger.debug("Ran provider.authenticate() and returned authentication for " +
        "principal {} with name {} and is authenticated {}", authentication.getPrincipal(), authentication.getName(), authentication.isAuthenticated());
    return new AuthenticationResponse(authentication.getName(), credentials.getUsername(), expiration, issuer);
  } catch (final AuthenticationException e) {
    throw new InvalidLoginCredentialsException(e.getMessage(), e);
  }
}

代码示例来源:origin: psi-probe/psi-probe

&& getContainerWrapper().getTomcatContainer().findContext(contextName) != null) {
logger.debug("updating {}: removing the old copy", contextName);
getContainerWrapper().getTomcatContainer().remove(contextName);
 request.setAttribute("success", Boolean.TRUE);
 Authentication auth = SecurityContextHolder.getContext().getAuthentication();
 String name = auth.getName();
 logger.info(getMessageSourceAccessor().getMessage("probe.src.log.deploywar"), name,
   contextName);

代码示例来源:origin: cloudfoundry/uaa

@Override
public String getUserName() {
  Authentication a = SecurityContextHolder.getContext().getAuthentication();
  return a == null ? null : a.getName();
}

代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

String ownerId = o2a.getUserAuthentication().getName();
String authClientId = auth.getName(); // direct authentication puts the client_id into the authentication's name field
authClient = clientService.loadClientByClientId(authClientId);
logger.debug("Client " + authClient.getClientId() + " revoked access token " + tokenValue);
  logger.debug("Client " + authClient.getClientId() + " revoked access token " + tokenValue);
  logger.debug("Failed to revoke token " + tokenValue);

代码示例来源:origin: apache/kylin

@RequestMapping(value = "/query/{queryId}/stop", method = RequestMethod.PUT)
@ResponseBody
public void stopQuery(@PathVariable String queryId) {
  final String user = SecurityContextHolder.getContext().getAuthentication().getName();
  logger.info("{} tries to stop the query: {}, but not guaranteed to succeed.", user, queryId);
  QueryContextFacade.stopQuery(queryId, "stopped by " + user);
}

代码示例来源:origin: yidongnan/grpc-spring-boot-starter

protected Authentication assertAuthenticated(final String method, final Authentication actual) {
  assertNotNull(actual, "No user authentication");
  assertTrue(actual.isAuthenticated(), "User not authenticated!");
  log.debug("{}: {}", method, actual.getName());
  return actual;
}

代码示例来源:origin: apache/kylin

@RequestMapping(value = "/saved_queries/{id}", method = RequestMethod.DELETE, produces = { "application/json" })
@ResponseBody
public void removeQuery(@PathVariable String id) throws IOException {
  String creator = SecurityContextHolder.getContext().getAuthentication().getName();
  queryService.removeQuery(creator, id);
}

代码示例来源:origin: metatron-app/metatron-discovery

private boolean checkRoleSetPermission(Authentication authentication, RoleSet roleSet, Object permission) {
 Preconditions.checkNotNull(roleSet, "dataSource resource is null.");
 LOGGER.debug("Check Role Permission : UserId({}), Id({}), Name({})"
   , authentication.getName(), roleSet.getId(), roleSet.getName());
 // TODO: 워크스페이스일 경우 처리 확인 필요
 return authentication.getAuthorities().contains(permission);
}

代码示例来源:origin: apache/kylin

@RequestMapping(value = "/saved_queries", method = RequestMethod.GET, produces = { "application/json" })
@ResponseBody
public List<Query> getQueries(@RequestParam(value = "project", required = false) String project)
    throws IOException {
  String creator = SecurityContextHolder.getContext().getAuthentication().getName();
  return queryService.getQueries(creator, project);
}

相关文章