All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xlrit.gears.server.security.internal.InternalAuthenticationProvider Maven / Gradle / Ivy

The newest version!
package com.xlrit.gears.server.security.internal;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthenticationToken;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
class InternalAuthenticationProvider implements AuthenticationProvider {

	private final BearerConverter converter;

	@Override
	public Authentication authenticate(Authentication authentication) throws AuthenticationException {
		BearerTokenAuthenticationToken bearer = (BearerTokenAuthenticationToken) authentication;
		try {
			String token = bearer.getToken();
			return converter.convert(token);
		}
		catch (Exception e) {
			throw new BadCredentialsException("Invalid JWT token", e);
		}
	}

	@Override
	public boolean supports(Class cls) {
		return BearerTokenAuthenticationToken.class.isAssignableFrom(cls);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy