spring security custom authentication provider

Solutions on MaxInterview for spring security custom authentication provider by the best coders in the world

showing results for - "spring security custom authentication provider"
Kinley
27 Sep 2016
1package com.frugalis;
2 
3import java.util.ArrayList;
4import java.util.List;
5 
6import org.springframework.security.authentication.AuthenticationProvider;
7import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
8import org.springframework.security.core.Authentication;
9import org.springframework.security.core.AuthenticationException;
10import org.springframework.security.core.GrantedAuthority;
11import org.springframework.security.core.authority.SimpleGrantedAuthority;
12import org.springframework.security.core.userdetails.UserDetails;
13import org.springframework.security.core.userdetails.User;
14import org.springframework.stereotype.Component;
15 
16@Component
17public class CustomAuthenticationProvider implements AuthenticationProvider {
18 
19	boolean shouldAuthenticateAgainstThirdPartySystem = true;
20 
21	@Override
22	public Authentication authenticate(Authentication authentication) throws AuthenticationException {
23		String name = authentication.getName();
24		String password = authentication.getCredentials().toString();
25 
26		if (name.equals("admin") && password.equals("password")) {
27			final List<GrantedAuthority> grantedAuths = new ArrayList<>();
28			grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
29			final UserDetails principal = new User(name, password, grantedAuths);
30			final Authentication auth = new UsernamePasswordAuthenticationToken(principal, password, grantedAuths);
31			return auth;
32		} else {
33			return null;
34		}
35 
36	}
37 
38	@Override
39	public boolean supports(Class<?> authentication) {
40 
41		return authentication.equals(UsernamePasswordAuthenticationToken.class);
42	}
43 
44}
45 
46
Cheri
01 Nov 2018
1package com.frugalis;
2 
3import org.springframework.beans.factory.annotation.Autowired;
4import org.springframework.context.annotation.ComponentScan;
5import org.springframework.context.annotation.Configuration;
6import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10 
11@Configuration
12@EnableWebSecurity
13@ComponentScan("com.frugalis")
14public class CustAuthProviderConfig extends WebSecurityConfigurerAdapter {
15  
16    @Autowired
17    private CustomAuthenticationProvider authProvider;
18 
19    @Override
20    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
21        auth.authenticationProvider(authProvider);
22    }
23 
24    @Override
25    protected void configure(HttpSecurity http) throws Exception {
26        http.authorizeRequests().anyRequest().authenticated()
27            .and().httpBasic();
28    }
29}
30 
31 
32
queries leading to this page
simple spring security rest custom login formspring security java custom authentication providerspring boot custom authenticationspring security custom authentication userdetailscustom auth providers spring securityspring boot security rest api basic authenticationcreate custom authentication springspring security custom authentication providerspring security with custom authenticationcustom authentication method for spring securitygrails spring security custom authentication providerspring security custom authentication managercustom authentication manager in spring securityspring security use custom authentication providercustom authentication provider spring securityspring boot security custom authenticationproviderspring security register authentication providerspring boot security custom authentication managercustom authentication spring bootjava spring set authentication customauthentication with spring bootspring security custom authentication filterspring security custom authentication provider not calledbasic authentication spring bootspring custom authenticationspring security custom authentication tokencustom login page in spring boot security with rest apicustom authentication object in spring securityspring security authentication providerspring boot custom authentication providercustom authentication provider in spring securityspring security oauth2 custom authentication providerspring security custom authenticationauthentication custom springspring security custom authentication provider