Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
* run mvn spotless:apply
  • Loading branch information
Leandro13Silva13 committed Mar 4, 2024
1 parent 7193793 commit e072d34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.filter.OncePerRequestFilter;

public class ApiTokenFilter extends OncePerRequestFilter {
public class ApiTokenFilter extends OncePerRequestFilter {

@Value("${external.user.create.tenant.api.token}")
private String externalUserCreateTenantApiToken;

public ApiTokenFilter() {
//Empty constructor
// Empty constructor
}

@Override
Expand All @@ -33,16 +33,21 @@ protected boolean shouldNotFilter(HttpServletRequest request) {
}

@Override
protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response,
@NonNull FilterChain filterChain) throws ServletException, IOException {
protected void doFilterInternal(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain filterChain)
throws ServletException, IOException {

String token = request.getHeader("api-token");

if (validateExternalUserCreateTenantApiToken(token)){
if (validateExternalUserCreateTenantApiToken(token)) {
// Create an authentication token
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(
"ExternalTechnicalAdmin", null,
Collections.singletonList(new SimpleGrantedAuthority(AuthorityValue.TENANT_ADMIN)));
UsernamePasswordAuthenticationToken auth =
new UsernamePasswordAuthenticationToken(
"ExternalTechnicalAdmin",
null,
Collections.singletonList(new SimpleGrantedAuthority(AuthorityValue.TENANT_ADMIN)));
// Set the authentication in the SecurityContext
SecurityContextHolder.getContext().setAuthentication(auth);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ void createNewTenantAdmin_Should_returnOk_When_requiredCreateTenantAdminIsGiven(
}

@Test
void createNewTenantAdmin_Should_returnOk_When_calledWithValidTenantCreateParamsAndValidExternalUserCreateTenantApiToken()
throws Exception {
void
createNewTenantAdmin_Should_returnOk_When_calledWithValidTenantCreateParamsAndValidExternalUserCreateTenantApiToken()
throws Exception {
// given
CreateAdminDTO createAdminDTO = new EasyRandom().nextObject(CreateAdminDTO.class);
createAdminDTO.setEmail("[email protected]");
Expand All @@ -350,8 +351,9 @@ void createNewTenantAdmin_Should_returnOk_When_calledWithValidTenantCreateParams
}

@Test
void createNewTenantAdmin_Should_returnStatusUnauthorized_When_calledWithValidTenantCreateParamsAndInvalidExternalUserCreateTenantApiToken()
throws Exception {
void
createNewTenantAdmin_Should_returnStatusUnauthorized_When_calledWithValidTenantCreateParamsAndInvalidExternalUserCreateTenantApiToken()
throws Exception {
// given
CreateAdminDTO createAdminDTO = new EasyRandom().nextObject(CreateAdminDTO.class);
createAdminDTO.setEmail("[email protected]");
Expand Down

0 comments on commit e072d34

Please sign in to comment.