Custom Authentication Manager with Spring Security and Java Configuration

前端 未结 4 1309
渐次进展
渐次进展 2020-12-01 01:31

I am using Spring Security with SpringMVC to create a web application (I will refer to this as the WebApp for clarity) that speaks to an existing application (I will refer t

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 01:59

    In its most simplest:

    @Override
        public Authentication authenticate(Authentication auth) throws AuthenticationException {
            String username = auth.getName();
            String password = auth.getCredentials().toString();
            // to add more logic
            List grantedAuths = new ArrayList<>();
            grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
            return new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
        }
    

提交回复
热议问题