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
Branches
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;
*
* @author Hamza REMMAL (hamza.remmal@epfl.ch)
*/
public final class ShareSecretAuthentication implements Authentication {
public final class SharedSecretAuthentication implements Authentication {
/** ??? */
private boolean authenticated;
......@@ -23,7 +23,7 @@ public final class ShareSecretAuthentication implements Authentication {
* @param key ???
* @param authenticated ???
*/
public ShareSecretAuthentication(String key, boolean authenticated) {
public SharedSecretAuthentication(String key, boolean authenticated) {
this.key = key;
this.authenticated = authenticated;
}
......
......@@ -8,14 +8,14 @@ import org.springframework.security.web.authentication.AuthenticationConverter;
public final class SharedSecretAuthenticationConverter implements AuthenticationConverter {
@Override
public ShareSecretAuthentication convert(HttpServletRequest request) {
public SharedSecretAuthentication convert(HttpServletRequest request) {
var header = request.getHeader("API-KEY");
if (header == null) return null;
header = header.trim();
if (header.isEmpty()) {
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;
*/
@Component
@RequiredArgsConstructor
public class ShareSecretAuthenticationProvider implements AuthenticationProvider {
public class SharedSecretAuthenticationProvider implements AuthenticationProvider {
/** ??? */
private final AutogradeAuthConfig config;
......@@ -30,11 +30,11 @@ public class ShareSecretAuthenticationProvider implements AuthenticationProvider
*/
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
var keyAuth = (ShareSecretAuthentication) authentication;
var keyAuth = (SharedSecretAuthentication) authentication;
if (isNull(keyAuth.getKey()))
return authentication;
if (keyAuth.getKey().equals(config.api().key()))
return new ShareSecretAuthentication(keyAuth.getKey(), true);
return new SharedSecretAuthentication(keyAuth.getKey(), true);
else
throw new BadCredentialsException("API KEY IS NOT CORRECT");
}
......@@ -46,7 +46,7 @@ public class ShareSecretAuthenticationProvider implements AuthenticationProvider
*/
@Override
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
@Override
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);
if (rememberMe != null)
filter.setRememberMeServices(rememberMe);
......
......@@ -21,7 +21,7 @@ import org.springframework.web.filter.OncePerRequestFilter;
import java.io.IOException;
@Slf4j
public final class ShareSecretFilter extends OncePerRequestFilter {
public final class SharedSecretFilter extends OncePerRequestFilter {
private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
.getContextHolderStrategy();
......@@ -42,7 +42,7 @@ public final class ShareSecretFilter extends OncePerRequestFilter {
* allowing the request to proceed down the filter chain.
* @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");
this.authenticationManager = authenticationManager;
this.authenticationEntryPoint = entryPoint;
......
......@@ -2,7 +2,7 @@ package ch.epfl.autograde.config;
import ch.epfl.autograde.auth.AutogradeAuthorities;
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.properties.AutogradeAuthConfig;
import lombok.RequiredArgsConstructor;
......@@ -47,7 +47,7 @@ public class SecurityConfig {
@Bean
@Order(1)
public SecurityFilterChain filterChain(HttpSecurity http,
ShareSecretAuthenticationProvider provider,
SharedSecretAuthenticationProvider provider,
@Qualifier("ldapAuthenticationManager") AuthenticationManager manager
) throws Exception {
return http
......
package ch.epfl.autograde.controller.api.v1;
import ch.epfl.autograde.auth.token.SharedSecretAuthentication;
import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* and the {@link WithSharedSecretAuthentication} annotation to simulate authenticated requests
*
* @see ch.epfl.autograde.controller.api.v1.InfoController
* @see ch.epfl.autograde.auth.token.ShareSecretAuthentication
* @see SharedSecretAuthentication
* @see ch.epfl.autograde.config.SecurityConfig
*
* @author Hamza REMMAL (hamza.remmal@epfl.ch)
......
package ch.epfl.autograde.controller.api.v1;
import ch.epfl.autograde.auth.token.SharedSecretAuthentication;
import ch.epfl.autograde.filters.AssignRequestIdFilter;
import ch.epfl.autograde.utils.context.WithSharedSecretAuthentication;
import org.junit.jupiter.api.DisplayName;
......@@ -26,7 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* with <i>shared secret</i> authentication.
*
* @see ch.epfl.autograde.controller.api.v1.PingController
* @see ch.epfl.autograde.auth.token.ShareSecretAuthentication
* @see SharedSecretAuthentication
* @see ch.epfl.autograde.config.SecurityConfig
*
* @author Hamza REMMAL (hamza.remmal@epfl.ch)
......
package ch.epfl.autograde.utils.context;
import ch.epfl.autograde.auth.token.ShareSecretAuthentication;
import org.springframework.beans.factory.annotation.Value;
import ch.epfl.autograde.auth.token.SharedSecretAuthentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextHolderStrategy;
......@@ -19,7 +18,7 @@ public final class WithSharedSecretAuthenticationFactory implements WithSecurity
@Override
public SecurityContext createSecurityContext(WithSharedSecretAuthentication annotation) {
var authentication = new ShareSecretAuthentication(annotation.secret(), true);
var authentication = new SharedSecretAuthentication(annotation.secret(), true);
var context = this.securityContextHolderStrategy.createEmptyContext();
context.setAuthentication(authentication);
return context;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment