@Test public void testAuthenticate() { Collection<GrantedAuthority> authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("testrole")); User user = new User("test", "pass", authorities); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("test", "pass", authorities); when(userDetailsService.loadUserByUsername("test")) .thenReturn(user); assertThat(basicAuthenticationProvider.authenticate(authentication)).isNotNull(); }
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); UserDetails userDetails = userDetailsService.loadUserByUsername(name); boolean authenticated = userDetails.getPassword().equals(password) && userDetails.isAccountNonExpired() && userDetails.isEnabled() && userDetails.isCredentialsNonExpired(); if (authenticated) { org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(name); return new UsernamePasswordAuthenticationToken(name, password, userDetails.getAuthorities()); } else { throw new BadCredentialsException("Authentication failed for this username and password"); } }
BasicAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); UserDetails userDetails = userDetailsService.loadUserByUsername(name); boolean authenticated = userDetails.getPassword().equals(password) && userDetails.isAccountNonExpired() && userDetails.isEnabled() && userDetails.isCredentialsNonExpired(); if (authenticated) { org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(name); return new UsernamePasswordAuthenticationToken(name, password, userDetails.getAuthorities()); } else { throw new BadCredentialsException("Authentication failed for this username and password"); } } }
BasicAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); UserDetails userDetails = userDetailsService.loadUserByUsername(name); boolean authenticated = userDetails.getPassword().equals(password) && userDetails.isAccountNonExpired() && userDetails.isEnabled() && userDetails.isCredentialsNonExpired(); if (authenticated) { org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(name); return new UsernamePasswordAuthenticationToken(name, password, userDetails.getAuthorities()); } else { throw new BadCredentialsException("Authentication failed for this username and password"); } } @Autowired  BasicAuthenticationProvider(UserDetailsService userDetailsService); }
BasicAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); UserDetails userDetails = userDetailsService.loadUserByUsername(name); boolean authenticated = userDetails.getPassword().equals(password) && userDetails.isAccountNonExpired() && userDetails.isEnabled() && userDetails.isCredentialsNonExpired(); if (authenticated) { org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(name); return new UsernamePasswordAuthenticationToken(name, password, userDetails.getAuthorities()); } else { throw new BadCredentialsException("Authentication failed for this username and password"); } } @Autowired  BasicAuthenticationProvider(UserDetailsService userDetailsService); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication); }
BasicAuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); UserDetails userDetails = userDetailsService.loadUserByUsername(name); boolean authenticated = userDetails.getPassword().equals(password) && userDetails.isAccountNonExpired() && userDetails.isEnabled() && userDetails.isCredentialsNonExpired(); if (authenticated) { org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(name); return new UsernamePasswordAuthenticationToken(name, password, userDetails.getAuthorities()); } else { throw new BadCredentialsException("Authentication failed for this username and password"); } } @Autowired  BasicAuthenticationProvider(UserDetailsService userDetailsService); @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication);  }