Java Code Examples for org.springframework.security.authentication.AbstractAuthenticationToken#setDetails()

The following examples show how to use org.springframework.security.authentication.AbstractAuthenticationToken#setDetails() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAuthenticationFilter.java    From WeBASE-Node-Manager with Apache License 2.0 5 votes vote down vote up
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
    final String header = request.getHeader(TOKEN_HEADER_NAME);

    if (header == null || !header.startsWith(getHeaderPrefix())) {
        chain.doFilter(request, response);
        return;
    }

    AbstractAuthenticationToken authRequest = buildAuthentication(header);
    authRequest.setDetails(authenticationDetailsSource.buildDetails(request));

    final Authentication authResult;
    try {
        authResult = authenticationManager.authenticate(authRequest);
    } catch (AuthenticationException failed) {
        String errorMessage = failed.getMessage();
        SecurityContextHolder.clearContext();
        //response exception
        NodeMgrTools.responseString(response, errorMessage);
        return;
    }

    SecurityContextHolder.getContext().setAuthentication(authResult);

    chain.doFilter(request, response);
}
 
Example 2
Source File: DefaultAuthenticationResponseService.java    From hygieia-core with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(HttpServletResponse response, Authentication authentication) {

       AuthType authType = (AuthType)authentication.getDetails();
       if (authType == AuthType.APIKEY) {
           Collection<UserRole> roles = new ArrayList<>();
           roles.add(UserRole.ROLE_API);

           AbstractAuthenticationToken authenticationWithAuthorities = new ApiTokenAuthenticationToken(authentication.getPrincipal(),
                   authentication.getCredentials(), createAuthorities(roles));
           authenticationWithAuthorities.setDetails(authentication.getDetails());
       }
       
}
 
Example 3
Source File: PrincipalServiceImpl.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
/**
 * details复制
 */
private void copyDetails(Authentication source, Authentication dest) {
    if ((dest instanceof AbstractAuthenticationToken) && (dest.getDetails() == null)) {
        AbstractAuthenticationToken token = (AbstractAuthenticationToken) dest;
        token.setDetails(source.getDetails());
    }
}
 
Example 4
Source File: LogsearchTrustedProxyFilter.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
  String doAsUserName = request.getParameter("doAs");
  final List<GrantedAuthority> authorities = RoleDao.createDefaultAuthorities();
  final UserDetails principal = new User(doAsUserName, "", authorities);
  final AbstractAuthenticationToken finalAuthentication = new UsernamePasswordAuthenticationToken(principal, "", authorities);
  WebAuthenticationDetails webDetails = new WebAuthenticationDetails(request);
  finalAuthentication.setDetails(webDetails);
  SecurityContextHolder.getContext().setAuthentication(finalAuthentication);
  logger.info("Logged into Log Search User as doAsUser = {}", doAsUserName);
  return finalAuthentication;
}
 
Example 5
Source File: OidcUserManagementAutoConfiguration.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
        final Authentication authentication) throws ServletException, IOException {
    if (authentication instanceof AbstractAuthenticationToken) {
        final String defaultTenant = "DEFAULT";

        final AbstractAuthenticationToken token = (AbstractAuthenticationToken) authentication;
        token.setDetails(new TenantAwareAuthenticationDetails(defaultTenant, false));

        systemSecurityContext.runAsSystemAsTenant(systemManagement::getTenantMetadata, defaultTenant);
    }

    super.onAuthenticationSuccess(request, response, authentication);
}
 
Example 6
Source File: WebAuthnProcessingFilter.java    From webauthn4j-spring-security with Apache License 2.0 4 votes vote down vote up
private void setDetails(HttpServletRequest request,
                        AbstractAuthenticationToken authRequest) {
    authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}
 
Example 7
Source File: MobileTokenAuthenticationFilter.java    From Taroco with Apache License 2.0 4 votes vote down vote up
protected void setDetails(HttpServletRequest request,
                          AbstractAuthenticationToken authRequest) {
    authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
}