protected void setDetails(HttpServletRequest request, SmsAuthenticationToken authRequest) { authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); }
/** * 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; }
/** * 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; }
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; } }
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; }
result.setDetails(authenticationDetailsSource.buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(result);
@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); }
@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; } }
token.setDetails(authenticationDetailsSource.buildDetails(request));
if (authentication instanceof AbstractAuthenticationToken) { AbstractAuthenticationToken needsDetails = (AbstractAuthenticationToken) authentication; needsDetails.setDetails(authenticationDetailsSource.buildDetails(request));
authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));
@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; } }
/** * 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)); }
authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));
@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); }
authenticationRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));
protected void setDetails(HttpServletRequest request, MobileAuthenticationToken authRequest) { authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); }
protected Object getDetails(HttpServletRequest request) { return authenticationDetailsSource.buildDetails(request); }
@Override protected void setDetails(HttpServletRequest request, UsernamePasswordAuthenticationToken authRequest) { authRequest.setDetails(m_authDetailsSource.buildDetails(request)); } }
/** * 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)); }