• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torresj / infosas-api / 87

12 Jan 2026 02:35PM UTC coverage: 76.32% (-15.3%) from 91.648%
87

push

circleci

torresj
Auth API added

70 of 170 new or added lines in 20 files covered. (41.18%)

477 of 625 relevant lines covered (76.32%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.85
/src/main/java/com/torresj/infosas/services/impl/JwtServiceImpl.java
1
package com.torresj.infosas.services.impl;
2

3
import com.torresj.infosas.services.JwtService;
4
import io.jsonwebtoken.ExpiredJwtException;
5
import io.jsonwebtoken.Jwts;
6
import io.jsonwebtoken.MalformedJwtException;
7
import io.jsonwebtoken.UnsupportedJwtException;
8
import io.jsonwebtoken.security.Keys;
9
import lombok.RequiredArgsConstructor;
10
import lombok.extern.slf4j.Slf4j;
11
import org.springframework.beans.factory.annotation.Value;
12
import org.springframework.stereotype.Service;
13

14
import java.nio.charset.StandardCharsets;
15
import java.util.Date;
16

17
@Service
18
@Slf4j
1✔
19
@RequiredArgsConstructor
20
public class JwtServiceImpl implements JwtService {
21

22
    @Value("${jwt.token.secret}")
23
    private final String secret;
24

25
    @Value("${jwt.token.expiration}")
26
    private final String expiration;
27

28
    @Value("${jwt.token.issuer.info}")
29
    private final String issuer;
30

31
    @Override
32
    public String createJWS(String name) {
33
        log.debug("[JWT SERVICE] Generating JWT");
1✔
34
        return Jwts.builder()
1✔
35
                .issuedAt(new Date())
1✔
36
                .issuer(issuer)
1✔
37
                .subject(name)
1✔
38
                .expiration(new Date(System.currentTimeMillis() + Long.parseLong(expiration)))
1✔
39
                .signWith(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8)))
1✔
40
                .compact();
1✔
41
    }
42

43
    @Override
44
    public String validateJWS(String jws) {
45
        try {
46
            var claims = Jwts.parser()
1✔
47
                    .verifyWith(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8)))
1✔
48
                    .build()
1✔
49
                    .parseSignedClaims(jws);
1✔
50
            return claims.getPayload().getSubject();
1✔
NEW
51
        } catch (SecurityException e) {
×
NEW
52
            log.error("Invalid JWT signature: {}", e.getMessage());
×
NEW
53
        } catch (MalformedJwtException e) {
×
NEW
54
            log.error("Invalid JWT token: {}", e.getMessage());
×
NEW
55
        } catch (ExpiredJwtException e) {
×
NEW
56
            log.error("JWT token is expired: {}", e.getMessage());
×
NEW
57
        } catch (UnsupportedJwtException e) {
×
NEW
58
            log.error("JWT token is unsupported: {}", e.getMessage());
×
NEW
59
        } catch (IllegalArgumentException e) {
×
NEW
60
            log.error("JWT claims string is empty: {}", e.getMessage());
×
NEW
61
        }
×
NEW
62
        return null;
×
63
    }
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc