Post

Spring Redirect and Fowrward

Not Sure Work Or Not

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@Component
public class LdapAuthProvider implements AuthenticationProvider {

	private final ObjectProvider<HttpServletRequest> requestProvider;

	public LdapAuthProvider(ObjectProvider<HttpServletRequest> requestProvider) {
		this.requestProvider = requestProvider;
	}

	@Override
	public Authentication authenticate(Authentication authentication) throws AuthenticationException {

		HttpServletRequest request = requestProvider.getIfAvailable();
		var login_id = ntnu.auth.Auth.loginByLDAPWebService(requestProvider.getObject());
		login_id = "chiahao";
		if (login_id == null || login_id.isEmpty()) {
			throw new BadCredentialsException("Invalid credentials");
		}

		// 認証成功トークンを返す(資格情報は null にしても良い)
		return new UsernamePasswordAuthenticationToken(login_id, null, new ArrayList<>());
	}

	@Override
	public boolean supports(Class<?> auth) {
		return UsernamePasswordAuthenticationToken.class.isAssignableFrom(auth);
	}
}
This post is licensed under CC BY 4.0 by the author.