@Test public void testAuthenticationDisabled() { expect(mockAuthPropsConfig.isAuthExternalEnabled()).andReturn(false); replay(mockAuthPropsConfig); Authentication authentication = new TestingAuthenticationToken("principal", "credentials"); assertSame(provider.authenticate(authentication), authentication); verify(mockAuthPropsConfig); }
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!authPropsConfig.isAuthExternalEnabled()) { logger.debug("external server auth is disabled."); return authentication; } String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (StringUtils.isBlank(username)) { throw new BadCredentialsException("Username can't be null or empty."); } if (StringUtils.isBlank(password)) { throw new BadCredentialsException("Password can't be null or empty."); } password = StringEscapeUtils.unescapeHtml(password); username = StringEscapeUtils.unescapeHtml(username); try { String finalLoginUrl = authPropsConfig.getExternalAuthLoginUrl().replace("$USERNAME", username); String responseObj = (String) externalServerClient.sendGETRequest(finalLoginUrl, String.class, username, password); if (!isAllowedRole(responseObj)) { logger.error(username + " doesn't have permission"); throw new BadCredentialsException("Invalid User"); } } catch (Exception e) { logger.error("Login failed for username :" + username + " Error :" + e.getLocalizedMessage()); throw new BadCredentialsException("Bad credentials"); } authentication = new UsernamePasswordAuthenticationToken(username, password, getAuthorities()); return authentication; }
LogsearchExternalServerAuthenticationProvider extends LogsearchAbstractAuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!authPropsConfig.isAuthExternalEnabled()) { logger.debug("external server auth is disabled."); return authentication; } String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (StringUtils.isBlank(username)) { throw new BadCredentialsException("Username can't be null or empty."); } if (StringUtils.isBlank(password)) { throw new BadCredentialsException("Password can't be null or empty."); } password = StringEscapeUtils.unescapeHtml(password); username = StringEscapeUtils.unescapeHtml(username); try { String finalLoginUrl = authPropsConfig.getExternalAuthLoginUrl().replace("$USERNAME", username); String responseObj = (String) externalServerClient.sendGETRequest(finalLoginUrl, String.class, username, password); if (!isAllowedRole(responseObj)) { logger.error(username + " doesn't have permission"); throw new BadCredentialsException("Invalid User"); } } catch (Exception e) { logger.error("Login failed for username :" + username + " Error :" + e.getLocalizedMessage()); throw new BadCredentialsException("Bad credentials"); } authentication = new UsernamePasswordAuthenticationToken(username, password, getAuthorities()); return authentication; } }
LogsearchExternalServerAuthenticationProvider extends LogsearchAbstractAuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!authPropsConfig.isAuthExternalEnabled()) { logger.debug("external server auth is disabled."); return authentication; } String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (StringUtils.isBlank(username)) { throw new BadCredentialsException("Username can't be null or empty."); } if (StringUtils.isBlank(password)) { throw new BadCredentialsException("Password can't be null or empty."); } password = StringEscapeUtils.unescapeHtml(password); username = StringEscapeUtils.unescapeHtml(username); try { String finalLoginUrl = authPropsConfig.getExternalAuthLoginUrl().replace("$USERNAME", username); String responseObj = (String) externalServerClient.sendGETRequest(finalLoginUrl, String.class, username, password); if (!isAllowedRole(responseObj)) { logger.error(username + " doesn't have permission"); throw new BadCredentialsException("Invalid User"); } } catch (Exception e) { logger.error("Login failed for username :" + username + " Error :" + e.getLocalizedMessage()); throw new BadCredentialsException("Bad credentials"); } authentication = new UsernamePasswordAuthenticationToken(username, password, getAuthorities()); return authentication; }  }
LogsearchExternalServerAuthenticationProvider extends LogsearchAbstractAuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!authPropsConfig.isAuthExternalEnabled()) { logger.debug("external server auth is disabled."); return authentication; } String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (StringUtils.isBlank(username)) { throw new BadCredentialsException("Username can't be null or empty."); } if (StringUtils.isBlank(password)) { throw new BadCredentialsException("Password can't be null or empty."); } password = StringEscapeUtils.unescapeHtml(password); username = StringEscapeUtils.unescapeHtml(username); try { String finalLoginUrl = authPropsConfig.getExternalAuthLoginUrl().replace("$USERNAME", username); String responseObj = (String) externalServerClient.sendGETRequest(finalLoginUrl, String.class, username, password); if (!isAllowedRole(responseObj)) { logger.error(username + " doesn't have permission"); throw new BadCredentialsException("Invalid User"); } } catch (Exception e) { logger.error("Login failed for username :" + username + " Error :" + e.getLocalizedMessage()); throw new BadCredentialsException("Bad credentials"); } authentication = new UsernamePasswordAuthenticationToken(username, password, getAuthorities()); return authentication; }  @Override Authentication authenticate(Authentication authentication); }
LogsearchExternalServerAuthenticationProvider extends LogsearchAbstractAuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!authPropsConfig.isAuthExternalEnabled()) { logger.debug("external server auth is disabled."); return authentication; } String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (StringUtils.isBlank(username)) { throw new BadCredentialsException("Username can't be null or empty."); } if (StringUtils.isBlank(password)) { throw new BadCredentialsException("Password can't be null or empty."); } password = StringEscapeUtils.unescapeHtml(password); username = StringEscapeUtils.unescapeHtml(username); try { String finalLoginUrl = authPropsConfig.getExternalAuthLoginUrl().replace("$USERNAME", username); String responseObj = (String) externalServerClient.sendGETRequest(finalLoginUrl, String.class, username, password); if (!isAllowedRole(responseObj)) { logger.error(username + " doesn't have permission"); throw new BadCredentialsException("Invalid User"); } } catch (Exception e) { logger.error("Login failed for username :" + username + " Error :" + e.getLocalizedMessage()); throw new BadCredentialsException("Bad credentials"); } authentication = new UsernamePasswordAuthenticationToken(username, password, getAuthorities()); return authentication; }  @Override Authentication authenticate(Authentication authentication);  }