Clover icon

sunshower-sdk

  1. Project Clover database Wed Apr 4 2018 21:39:43 UTC
  2. Package io.sunshower.sdk.v1.core.security

File DefaultSecurityEndpoint.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
12% of files have more coverage

Code metrics

2
11
3
1
48
40
5
0.45
3.67
3
1.67

Classes

Class Line # Actions
DefaultSecurityEndpoint 18 11 5
0.812581.2%
 

Contributing tests

This file is covered by 7 tests. .

Source view

1    package io.sunshower.sdk.v1.core.security;
2   
3    import io.sunshower.core.security.AuthenticationService;
4    import io.sunshower.core.security.InvalidCredentialException;
5    import io.sunshower.model.core.auth.Authentication;
6    import io.sunshower.model.core.auth.Token;
7    import io.sunshower.model.core.auth.User;
8    import io.sunshower.sdk.core.model.Authentications;
9    import io.sunshower.sdk.v1.endpoints.core.security.SecurityEndpoint;
10    import io.sunshower.sdk.v1.model.core.faults.authorization.AuthenticationFailedException;
11    import io.sunshower.sdk.v1.model.core.security.AuthenticationElement;
12    import io.sunshower.sdk.v1.model.core.security.AuthenticationRequest;
13    import io.sunshower.sdk.v1.model.core.security.AuthenticationTokenElement;
14   
15    import javax.inject.Inject;
16    import java.util.Date;
17   
 
18    public class DefaultSecurityEndpoint implements SecurityEndpoint {
19   
20    @Inject private Authentications authentications;
21   
22    @Inject private AuthenticationService authenticationService;
23   
 
24  1 toggle @Override
25    public void validate(AuthenticationTokenElement element) {
26  1 authenticationService.validate(new Token(element.getValue(), new Date()));
27    }
28   
 
29  7 toggle @Override
30    public AuthenticationElement authenticate(AuthenticationRequest request) {
31  7 final User user = new User();
32  7 user.setUsername(request.getUsername());
33  7 user.setPassword(request.getPassword());
34  7 Authentication authenticate = authenticationService.authenticate(user);
35  5 return authentications.toElement(authenticate);
36    }
37   
 
38  1 toggle @Override
39    public AuthenticationElement authenticate(AuthenticationTokenElement token) {
40  1 final String value = token.getValue();
41  1 if (value == null || value.isEmpty()) {
42  1 throw new AuthenticationFailedException();
43    }
44  0 Authentication validate =
45    authenticationService.validate(new Token(token.getValue(), new Date()));
46  0 return authentications.toElement(validate);
47    }
48    }