org.springframework.security.authentication.AuthenticationDetailsSource类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(132)

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

AuthenticationDetailsSource介绍

[英]Provides a org.springframework.security.core.Authentication#getDetails() object for a given web request.
[中]提供一个组织。springframework。安全果心给定web请求的身份验证#getDetails()对象。

代码示例

代码示例来源:origin: wuyouzhuguli/SpringAll

protected void setDetails(HttpServletRequest request,
             SmsAuthenticationToken authRequest) {
  authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}

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

/**
 * If the incoming request contains user credentials in headers or parameters then extract them here into an
 * Authentication token that can be validated later. This implementation only recognises password grant requests and
 * extracts the username and password.
 * 
 * @param request the incoming request, possibly with user credentials
 * @return an authentication for validation (or null if there is no further authentication)
 */
protected Authentication extractCredentials(HttpServletRequest request) {
  String grantType = request.getParameter("grant_type");
  if (grantType != null && grantType.equals("password")) {
    UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(
        request.getParameter("username"), request.getParameter("password"));
    result.setDetails(authenticationDetailsSource.buildDetails(request));
    return result;
  }
  return null;
}

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

/**
 * If the incoming request contains user credentials in headers or parameters then extract them here into an
 * Authentication token that can be validated later. This implementation only recognises password grant requests and
 * extracts the username and password.
 *
 * @param request the incoming request, possibly with user credentials
 * @return an authentication for validation (or null if there is no further authentication)
 */
protected Authentication extractCredentials(HttpServletRequest request) {
  String username = request.getParameter("username");
  String password = request.getParameter("password");
  UsernamePasswordAuthenticationToken credentials = new UsernamePasswordAuthenticationToken(username, password);
  credentials.setDetails(authenticationDetailsSource.buildDetails(request));
  return credentials;
}

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

public Authentication validateKerberosTicket(HttpServletRequest request) {
  // Only support Kerberos login when running securely
  if (!request.isSecure()) {
    return null;
  }
  String header = request.getHeader(AUTHORIZATION_HEADER_NAME);
  if (isValidKerberosHeader(header)) {
    if (logger.isDebugEnabled()) {
      logger.debug("Received Negotiate Header for request " + request.getRequestURL() + ": " + header);
    }
    byte[] base64Token = header.substring(header.indexOf(" ") + 1).getBytes(StandardCharsets.UTF_8);
    byte[] kerberosTicket = Base64.decode(base64Token);
    KerberosServiceRequestToken authenticationRequest = new KerberosServiceRequestToken(kerberosTicket);
    authenticationRequest.setDetails(authenticationDetailsSource.buildDetails(request));
    return kerberosServiceAuthenticationProvider.authenticate(authenticationRequest);
  } else {
    return null;
  }
}

代码示例来源:origin: geoserver/geoserver

protected Authentication createAuthentication(HttpServletRequest request) {
  GeoServerUser anonymous = GeoServerUser.createAnonymous();
  List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
  roles.addAll(anonymous.getAuthorities());
  AnonymousAuthenticationToken auth =
      new AnonymousAuthenticationToken("geoserver", anonymous.getUsername(), roles);
  auth.setDetails(authenticationDetailsSource.buildDetails(request));
  return auth;
}

代码示例来源:origin: geoserver/geoserver

result.setDetails(authenticationDetailsSource.buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(result);

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

@Override
public Authentication attemptAuthentication(final HttpServletRequest request,
    final HttpServletResponse response) throws AuthenticationException,
    IOException {
  // if the request is a proxy request process it and return null to indicate the
  // request has been processed
  if (proxyReceptorRequest(request)) {
    logger.debug("Responding to proxy receptor request");
    CommonUtils.readAndRespondToProxyReceptorRequest(request, response,
        this.proxyGrantingTicketStorage);
    return null;
  }
  final boolean serviceTicketRequest = serviceTicketRequest(request, response);
  final String username = serviceTicketRequest ? CAS_STATEFUL_IDENTIFIER
      : CAS_STATELESS_IDENTIFIER;
  String password = obtainArtifact(request);
  if (password == null) {
    logger.debug("Failed to obtain an artifact (cas ticket)");
    password = "";
  }
  final UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
      username, password);
  authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
  return this.getAuthenticationManager().authenticate(authRequest);
}

代码示例来源:origin: geoserver/geoserver

@Override
  protected Authentication createSuccessfulAuthentication(
      HttpServletRequest request, UserDetails user) {
    if (user instanceof RememberMeUserDetails)
      user = ((RememberMeUserDetails) user).getWrappedObject();

    Collection<GrantedAuthority> roles = new HashSet<GrantedAuthority>();
    if (user.getAuthorities().contains(GeoServerRole.AUTHENTICATED_ROLE)) {
      roles.addAll(user.getAuthorities());
    } else {
      roles = new HashSet<GrantedAuthority>();
      roles.addAll(user.getAuthorities());
      roles.add(GeoServerRole.AUTHENTICATED_ROLE);
    }
    RememberMeAuthenticationToken auth =
        new RememberMeAuthenticationToken(getKey(), user, roles);
    auth.setDetails(getAuthenticationDetailsSource().buildDetails(request));
    return auth;
  }
}

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

token.setDetails(authenticationDetailsSource.buildDetails(request));

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

if (authentication instanceof AbstractAuthenticationToken) {
  AbstractAuthenticationToken needsDetails = (AbstractAuthenticationToken) authentication;
  needsDetails.setDetails(authenticationDetailsSource.buildDetails(request));

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

authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));

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

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
    throws AuthenticationException, IOException, ServletException {
  OAuth2AccessToken accessToken;
  try {
    accessToken = restTemplate.getAccessToken();
  } catch (OAuth2Exception e) {
    BadCredentialsException bad = new BadCredentialsException("Could not obtain access token", e);
    publish(new OAuth2AuthenticationFailureEvent(bad));
    throw bad;			
  }
  try {
    OAuth2Authentication result = tokenServices.loadAuthentication(accessToken.getValue());
    if (authenticationDetailsSource!=null) {
      request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, accessToken.getValue());
      request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_TYPE, accessToken.getTokenType());
      result.setDetails(authenticationDetailsSource.buildDetails(request));
    }
    publish(new AuthenticationSuccessEvent(result));
    return result;
  }
  catch (InvalidTokenException e) {
    BadCredentialsException bad = new BadCredentialsException("Could not obtain user details from token", e);
    publish(new OAuth2AuthenticationFailureEvent(bad));
    throw bad;			
  }
}

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

/**
 * http/http-basic@authentication-details-source-ref equivalent
 */
@Test
public void basicAuthenticationWhenUsingAuthenticationDetailsSourceRefThenMatchesNamespace() throws Exception {
  this.spring.register(AuthenticationDetailsSourceHttpBasicConfig.class, UserConfig.class).autowire();
  AuthenticationDetailsSource<HttpServletRequest, ?> source =
      this.spring.getContext().getBean(AuthenticationDetailsSource.class);
  this.mvc.perform(get("/")
      .with(httpBasic("user", "password")));
  verify(source).buildDetails(any(HttpServletRequest.class));
}

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

authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));

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

@Test
public void loginWhenUsingCustomAuthenticationDetailsSourceRefThenAuthenticationSourcesDetailsAccordingly()
  throws Exception {
  this.spring.configLocations(xml("CustomAuthenticationDetailsSourceRef")).autowire();
  Object details = mock(Object.class);
  AuthenticationDetailsSource source = this.spring.getContext().getBean(AuthenticationDetailsSource.class);
  when(source.buildDetails(any(Object.class))).thenReturn(details);
  this.mvc.perform(get("/details")
      .with(httpBasic("user", "password")))
      .andExpect(content().string(details.getClass().getName()));
  this.mvc.perform(get("/details")
      .with(x509("classpath:org/springframework/security/config/http/MiscHttpConfigTests-certificate.pem")))
      .andExpect(content().string(details.getClass().getName()));
  MockHttpSession session = (MockHttpSession)
      this.mvc.perform(post("/login")
          .param("username", "user")
          .param("password", "password")
          .with(csrf()))
          .andReturn().getRequest().getSession(false);
  this.mvc.perform(get("/details")
      .session(session))
      .andExpect(content().string(details.getClass().getName()));
  assertThat(getField(getFilter(OpenIDAuthenticationFilter.class), "authenticationDetailsSource"))
      .isEqualTo(source);
}

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

authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));

代码示例来源:origin: pig4cloud/pig

protected void setDetails(HttpServletRequest request,
             MobileAuthenticationToken authRequest) {
  authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}

代码示例来源:origin: codeabovelab/haven-platform

protected Object getDetails(HttpServletRequest request) {
  return authenticationDetailsSource.buildDetails(request);
}

代码示例来源:origin: OpenNMS/opennms

@Override
  protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) {
    authRequest.setDetails(m_authDetailsSource.buildDetails(request));
  }
}

代码示例来源:origin: tigerphz/tgcloud-master

/**
 * Provided so that subclasses may configure what is put into the
 * authentication request's details property.
 *
 * @param request     that an authentication request is being created for
 * @param authRequest the authentication request object that should have its details            set
 */
protected void setDetails(HttpServletRequest request, SmsCodeAuthenticationToken authRequest) {
  authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}

相关文章

微信公众号

最新文章

更多

AuthenticationDetailsSource类方法