Vishnu G S
Vishnu G S

Reputation: 714

Spring - JWTParser(String) not found

I have a token based authentication scheme in Spring. But the JWTParser seems troublesome. What does JWTParser class in the below code really do? Also, I cant import this class.

public class JWTAuthenticationToken extends AbstractAuthenticationToken {
    private static final long serialVersionUID = 1L;
    private final Object principal;
    private Object details;

    Collection authorities;

    public JWTAuthenticationToken( String jwtToken ) {
        super( null );
        super.setAuthenticated( true ); // must use super, as we override
        JWTParser parser = new JWTParser( jwtToken );

        this.principal = parser.getSub();

        this.setDetailsAuthorities();

    }

    @Override
    public Object getCredentials() {
        return "";
    }

    @Override
    public Object getPrincipal() {
        return principal;
    }

    private void setDetailsAuthorities() {
        String username = principal.toString();
        SpringUserDetailsAdapter adapter = new SpringUserDetailsAdapter( username );
        details = adapter;
        authorities = ( Collection ) adapter.getAuthorities();

    }

    @Override
    public Collection getAuthorities() {
        return authorities;
    }
}

Any work around?

Upvotes: 1

Views: 1936

Answers (1)

Ahmad R. Nazemi
Ahmad R. Nazemi

Reputation: 805

JwtParser parser =new  DefaultJwtParser();
parser.parse(jwtToken);

<dependency>
 <groupId>io.jsonwebtoken</groupId>
 <artifactId>jjwt</artifactId>
 <version>0.6.0</version>
</dependency>

Upvotes: 1

Related Questions