Skip to content
Snippets Groups Projects
Commit a45aa48a authored by Hamza Remmal's avatar Hamza Remmal :homes:
Browse files

Fix typo in some of the 'shared-secret' classes

parent fb2822b8
No related branches found
No related tags found
1 merge request!319Fix typo in some of the 'shared-secret' classes
Showing
with 19 additions and 18 deletions
...@@ -10,7 +10,7 @@ import java.util.Collection; ...@@ -10,7 +10,7 @@ import java.util.Collection;
* *
* @author Hamza REMMAL (hamza.remmal@epfl.ch) * @author Hamza REMMAL (hamza.remmal@epfl.ch)
*/ */
public final class ShareSecretAuthentication implements Authentication { public final class SharedSecretAuthentication implements Authentication {
/** ??? */ /** ??? */
private boolean authenticated; private boolean authenticated;
...@@ -23,7 +23,7 @@ public final class ShareSecretAuthentication implements Authentication { ...@@ -23,7 +23,7 @@ public final class ShareSecretAuthentication implements Authentication {
* @param key ??? * @param key ???
* @param authenticated ??? * @param authenticated ???
*/ */
public ShareSecretAuthentication(String key, boolean authenticated) { public SharedSecretAuthentication(String key, boolean authenticated) {
this.key = key; this.key = key;
this.authenticated = authenticated; this.authenticated = authenticated;
} }
......
...@@ -8,14 +8,14 @@ import org.springframework.security.web.authentication.AuthenticationConverter; ...@@ -8,14 +8,14 @@ import org.springframework.security.web.authentication.AuthenticationConverter;
public final class SharedSecretAuthenticationConverter implements AuthenticationConverter { public final class SharedSecretAuthenticationConverter implements AuthenticationConverter {
@Override @Override
public ShareSecretAuthentication convert(HttpServletRequest request) { public SharedSecretAuthentication convert(HttpServletRequest request) {
var header = request.getHeader("API-KEY"); var header = request.getHeader("API-KEY");
if (header == null) return null; if (header == null) return null;
header = header.trim(); header = header.trim();
if (header.isEmpty()) { if (header.isEmpty()) {
throw new BadCredentialsException("Empty authentication token"); throw new BadCredentialsException("Empty authentication token");
} }
return new ShareSecretAuthentication(header, false); return new SharedSecretAuthentication(header, false);
} }
} }
......
...@@ -17,7 +17,7 @@ import static java.util.Objects.isNull; ...@@ -17,7 +17,7 @@ import static java.util.Objects.isNull;
*/ */
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class ShareSecretAuthenticationProvider implements AuthenticationProvider { public class SharedSecretAuthenticationProvider implements AuthenticationProvider {
/** ??? */ /** ??? */
private final AutogradeAuthConfig config; private final AutogradeAuthConfig config;
...@@ -30,11 +30,11 @@ public class ShareSecretAuthenticationProvider implements AuthenticationProvider ...@@ -30,11 +30,11 @@ public class ShareSecretAuthenticationProvider implements AuthenticationProvider
*/ */
@Override @Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException { public Authentication authenticate(Authentication authentication) throws AuthenticationException {
var keyAuth = (ShareSecretAuthentication) authentication; var keyAuth = (SharedSecretAuthentication) authentication;
if (isNull(keyAuth.getKey())) if (isNull(keyAuth.getKey()))
return authentication; return authentication;
if (keyAuth.getKey().equals(config.api().key())) if (keyAuth.getKey().equals(config.api().key()))
return new ShareSecretAuthentication(keyAuth.getKey(), true); return new SharedSecretAuthentication(keyAuth.getKey(), true);
else else
throw new BadCredentialsException("API KEY IS NOT CORRECT"); throw new BadCredentialsException("API KEY IS NOT CORRECT");
} }
...@@ -46,7 +46,7 @@ public class ShareSecretAuthenticationProvider implements AuthenticationProvider ...@@ -46,7 +46,7 @@ public class ShareSecretAuthenticationProvider implements AuthenticationProvider
*/ */
@Override @Override
public boolean supports(Class<?> authenticationType) { public boolean supports(Class<?> authenticationType) {
return ShareSecretAuthentication.class.equals(authenticationType); return SharedSecretAuthentication.class.equals(authenticationType);
} }
} }
...@@ -29,7 +29,7 @@ public final class SharedSecretConfigurer<B extends HttpSecurityBuilder<B>> exte ...@@ -29,7 +29,7 @@ public final class SharedSecretConfigurer<B extends HttpSecurityBuilder<B>> exte
@Override @Override
public void configure(B http) { public void configure(B http) {
final var filter = new ShareSecretFilter(manager, this.authenticationEntryPoint); final var filter = new SharedSecretFilter(manager, this.authenticationEntryPoint);
final var rememberMe = http.getSharedObject(RememberMeServices.class); final var rememberMe = http.getSharedObject(RememberMeServices.class);
if (rememberMe != null) if (rememberMe != null)
filter.setRememberMeServices(rememberMe); filter.setRememberMeServices(rememberMe);
......
...@@ -21,7 +21,7 @@ import org.springframework.web.filter.OncePerRequestFilter; ...@@ -21,7 +21,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
import java.io.IOException; import java.io.IOException;
@Slf4j @Slf4j
public final class ShareSecretFilter extends OncePerRequestFilter { public final class SharedSecretFilter extends OncePerRequestFilter {
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy(); .getContextHolderStrategy();
...@@ -42,7 +42,7 @@ public final class ShareSecretFilter extends OncePerRequestFilter { ...@@ -42,7 +42,7 @@ public final class ShareSecretFilter extends OncePerRequestFilter {
* allowing the request to proceed down the filter chain. * allowing the request to proceed down the filter chain.
* @param authenticationManager the bean to submit authentication requests to * @param authenticationManager the bean to submit authentication requests to
*/ */
public ShareSecretFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint entryPoint) { public SharedSecretFilter(AuthenticationManager authenticationManager, AuthenticationEntryPoint entryPoint) {
Assert.notNull(authenticationManager, "authenticationManager cannot be null"); Assert.notNull(authenticationManager, "authenticationManager cannot be null");
this.authenticationManager = authenticationManager; this.authenticationManager = authenticationManager;
this.authenticationEntryPoint = entryPoint; this.authenticationEntryPoint = entryPoint;
......
...@@ -2,7 +2,7 @@ package ch.epfl.autograde.config; ...@@ -2,7 +2,7 @@ package ch.epfl.autograde.config;
import ch.epfl.autograde.auth.AutogradeAuthorities; import ch.epfl.autograde.auth.AutogradeAuthorities;
import ch.epfl.autograde.auth.ldap.EPFLAuthoritiesPopulator; import ch.epfl.autograde.auth.ldap.EPFLAuthoritiesPopulator;
import ch.epfl.autograde.auth.token.ShareSecretAuthenticationProvider; import ch.epfl.autograde.auth.token.SharedSecretAuthenticationProvider;
import ch.epfl.autograde.auth.token.SharedSecretConfigurer; import ch.epfl.autograde.auth.token.SharedSecretConfigurer;
import ch.epfl.autograde.properties.AutogradeAuthConfig; import ch.epfl.autograde.properties.AutogradeAuthConfig;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -47,7 +47,7 @@ public class SecurityConfig { ...@@ -47,7 +47,7 @@ public class SecurityConfig {
@Bean @Bean
@Order(1) @Order(1)
public SecurityFilterChain filterChain(HttpSecurity http, public SecurityFilterChain filterChain(HttpSecurity http,
ShareSecretAuthenticationProvider provider, SharedSecretAuthenticationProvider provider,
@Qualifier("ldapAuthenticationManager") AuthenticationManager manager @Qualifier("ldapAuthenticationManager") AuthenticationManager manager
) throws Exception { ) throws Exception {
return http return http
......
package ch.epfl.autograde.controller.api.v1; package ch.epfl.autograde.controller.api.v1;
import ch.epfl.autograde.auth.token.SharedSecretAuthentication;
import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication; import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -21,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -21,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* and the {@link WithSharedSecretAuthentication} annotation to simulate authenticated requests * and the {@link WithSharedSecretAuthentication} annotation to simulate authenticated requests
* *
* @see ch.epfl.autograde.controller.api.v1.InfoController * @see ch.epfl.autograde.controller.api.v1.InfoController
* @see ch.epfl.autograde.auth.token.ShareSecretAuthentication * @see SharedSecretAuthentication
* @see ch.epfl.autograde.config.SecurityConfig * @see ch.epfl.autograde.config.SecurityConfig
* *
* @author Hamza REMMAL (hamza.remmal@epfl.ch) * @author Hamza REMMAL (hamza.remmal@epfl.ch)
......
package ch.epfl.autograde.controller.api.v1; package ch.epfl.autograde.controller.api.v1;
import ch.epfl.autograde.auth.token.SharedSecretAuthentication;
import ch.epfl.autograde.filters.AssignRequestIdFilter; import ch.epfl.autograde.filters.AssignRequestIdFilter;
import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication; import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
...@@ -26,7 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -26,7 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* with <i>shared secret</i> authentication. * with <i>shared secret</i> authentication.
* *
* @see ch.epfl.autograde.controller.api.v1.PingController * @see ch.epfl.autograde.controller.api.v1.PingController
* @see ch.epfl.autograde.auth.token.ShareSecretAuthentication * @see SharedSecretAuthentication
* @see ch.epfl.autograde.config.SecurityConfig * @see ch.epfl.autograde.config.SecurityConfig
* *
* @author Hamza REMMAL (hamza.remmal@epfl.ch) * @author Hamza REMMAL (hamza.remmal@epfl.ch)
......
package ch.epfl.autograde.utils.context; package ch.epfl.autograde.utils.context;
import ch.epfl.autograde.auth.token.ShareSecretAuthentication; import ch.epfl.autograde.auth.token.SharedSecretAuthentication;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy; import org.springframework.security.core.context.SecurityContextHolderStrategy;
...@@ -19,7 +18,7 @@ public final class WithSharedSecretAuthenticationFactory implements WithSecurity ...@@ -19,7 +18,7 @@ public final class WithSharedSecretAuthenticationFactory implements WithSecurity
@Override @Override
public SecurityContext createSecurityContext(WithSharedSecretAuthentication annotation) { public SecurityContext createSecurityContext(WithSharedSecretAuthentication annotation) {
var authentication = new ShareSecretAuthentication(annotation.secret(), true); var authentication = new SharedSecretAuthentication(annotation.secret(), true);
var context = this.securityContextHolderStrategy.createEmptyContext(); var context = this.securityContextHolderStrategy.createEmptyContext();
context.setAuthentication(authentication); context.setAuthentication(authentication);
return context; return context;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment