Clover icon

sunshower-core

  1. Project Clover database Fri Apr 6 2018 03:27:42 UTC
  2. Package io.sunshower.service.security

File GridTokenManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
36% of files have more coverage

Code metrics

4
10
2
1
46
40
6
0.6
5
2
3

Classes

Class Line # Actions
GridTokenManager 15 10 6
0.550%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    package io.sunshower.service.security;
2   
3    import io.sunshower.core.security.InvalidTokenException;
4    import io.sunshower.core.security.crypto.EncryptionService;
5    import io.sunshower.model.core.auth.User;
6    import java.io.UnsupportedEncodingException;
7    import java.net.URLDecoder;
8    import java.util.logging.Logger;
9    import javax.inject.Inject;
10    import org.springframework.security.authentication.BadCredentialsException;
11    import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
12    import org.springframework.security.core.context.SecurityContextHolder;
13   
14    /** Created by haswell on 3/5/17. */
 
15    public class GridTokenManager implements TokenManager {
16    static final Logger log = Logger.getLogger(GridTokenManager.class.getName());
17   
18    @Inject private EncryptionService encryptionService;
19   
 
20  0 toggle @Override
21    public void checkEncoded(String token) {
22  0 try {
23  0 check(URLDecoder.decode(token, "UTF-8"));
24    } catch (UnsupportedEncodingException e) {
25  0 throw new IllegalStateException(e);
26    }
27    }
28   
 
29  2 toggle @Override
30    public void check(String token) {
31  2 if (token != null) {
32  2 try {
33  2 final User user = encryptionService.findByToken(token);
34  2 if (user != null) {
35  2 SecurityContextHolder.getContext()
36    .setAuthentication(
37    new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities()));
38    } else {
39  0 throw new BadCredentialsException("No Valid authentication present");
40    }
41    } catch (InvalidTokenException ex) {
42  0 log.info("No valid authentication information");
43    }
44    }
45    }
46    }