Learn how to approach your first ticket in the Labs project and understand the development workflow.
View your first ticket details and requirements on GitHub:
First Ticket DocumentationLearn how to implement the core domain objects and security configuration for the Bloom Coder Assignment App.
// Example User entity implementation @Entity @Table(name = "users") public class User implements UserDetails { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private LocalDate cohortStartDate; private String username; private String password; @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) private Listauthorities; // Constructors public User() {} public User(LocalDate cohortStartDate, String username, String password) { this.cohortStartDate = cohortStartDate; this.username = username; this.password = password; } // UserDetails overrides @Override public Collection extends GrantedAuthority> getAuthorities() { return authorities; } @Override public boolean isAccountNonExpired() { return true; } // ... other overrides }
Review essential Spring Boot concepts and JWT authentication implementation for the project.
// Example JWT Utils class @Component public class JwtUtils { @Value("${jwt.secret}") private String jwtSecret; @Value("${jwt.expiration}") private int jwtExpirationMs; public String generateJwtToken(Authentication authentication) { UserDetailsImpl userPrincipal = (UserDetailsImpl) authentication.getPrincipal(); return Jwts.builder() .setSubject((userPrincipal.getUsername())) .setIssuedAt(new Date()) .setExpiration(new Date((new Date()).getTime() + jwtExpirationMs)) .signWith(SignatureAlgorithm.HS512, jwtSecret) .compact(); } public String getUserNameFromJwtToken(String token) { return Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(token).getBody().getSubject(); } public boolean validateJwtToken(String authToken) { try { Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(authToken); return true; } catch (SignatureException e) { // Handle invalid JWT signature } catch (MalformedJwtException e) { // Handle invalid JWT token } catch (ExpiredJwtException e) { // Handle expired JWT token } catch (UnsupportedJwtException e) { // Handle unsupported JWT token } catch (IllegalArgumentException e) { // Handle JWT claims string is empty } return false; } }
// Example Repository interface @Repository public interface UserRepository extends JpaRepository{ Optional findByUsername(String username); Boolean existsByUsername(String username); Boolean existsByEmail(String email); } // Example Service implementation @Service public class UserService { @Autowired private UserRepository userRepository; @Autowired private PasswordEncoder passwordEncoder; public User createUser(User user) { user.setPassword(passwordEncoder.encode(user.getPassword())); return userRepository.save(user); } public Optional findByUsername(String username) { return userRepository.findByUsername(username); } }