Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Apr 1, 2024
1 parent 600acd3 commit 496df2f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
public class SecurityConfig {

private static final String[] AUTH_WHITELIST = {
"/auth/refresh",
"/auth/save",
"/auth/login",
"/member/duplicate/**",
"/location/**",
"/actuator/**"};
"/auth/refresh",
"/auth/save",
"/auth/login",
"/member/duplicate/**",
"/location/**",
"/actuator/**"
};
private final JwtFilter jwtFilter;
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class JwtFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(
final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain)
final HttpServletRequest request,
final HttpServletResponse response,
final FilterChain filterChain)
throws ServletException, IOException {
Optional<String> jwt = resolveToken(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import com.twtw.backend.domain.member.entity.Member;
import com.twtw.backend.domain.member.entity.Role;
import com.twtw.backend.global.exception.AuthorityException;

import io.jsonwebtoken.*;

import lombok.RequiredArgsConstructor;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
Expand Down Expand Up @@ -63,9 +66,9 @@ public Optional<Authentication> getAuthentication(String accessToken) {

addRole(role, authorities);

return new UsernamePasswordAuthenticationToken(claims.getSubject(), "", authorities);
}
);
return new UsernamePasswordAuthenticationToken(
claims.getSubject(), "", authorities);
});
}

private void addRole(final String role, final Collection<GrantedAuthority> authorities) {
Expand Down Expand Up @@ -93,17 +96,18 @@ public boolean validateToken(String token) {
private Claims parseClaims(String accessToken) {
try {
return Jwts.parserBuilder()
.setSigningKey(key)
.build()
.parseClaimsJws(accessToken)
.getBody();
.setSigningKey(key)
.build()
.parseClaimsJws(accessToken)
.getBody();
} catch (ExpiredJwtException e) {
throw new AuthorityException();
}
}

public UsernamePasswordAuthenticationToken makeCredit(Member member) {
List<GrantedAuthority> role = List.of(new SimpleGrantedAuthority(member.getRole().toString()));
List<GrantedAuthority> role =
List.of(new SimpleGrantedAuthority(member.getRole().toString()));

return new UsernamePasswordAuthenticationToken(member.getId().toString(), "", role);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@AllArgsConstructor
public class AfterLoginResponse {

private static final AfterLoginResponse SIGNUP = AfterLoginResponse.builder()
.status(AuthStatus.SIGNUP).build();
private static final AfterLoginResponse SIGNUP =
AfterLoginResponse.builder().status(AuthStatus.SIGNUP).build();
private AuthStatus status;
private TokenDto tokenDto;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public AfterLoginResponse getTokenByOAuth(OAuthRequest request) {
Optional<Member> member =
memberRepository.findByOAuthIdAndAuthType(clientId, request.getAuthType());

return member.map(this::getAfterLoginResponse)
.orElseGet(AfterLoginResponse::ofSignup);
return member.map(this::getAfterLoginResponse).orElseGet(AfterLoginResponse::ofSignup);
}

private AfterLoginResponse getAfterLoginResponse(final Member member) {
Expand All @@ -113,7 +112,8 @@ public TokenDto refreshToken(TokenRequest tokenRequest) {
Optional<Authentication> authentication =
tokenProvider.getAuthentication(tokenRequest.getAccessToken());

return authentication.map(auth -> getTokenDto(auth, refreshToken))
return authentication
.map(auth -> getTokenDto(auth, refreshToken))
.orElseThrow(AuthorityException::new);
}

Expand Down

0 comments on commit 496df2f

Please sign in to comment.