Clover icon

sunshower-core

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

File JpaCredentialService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart2.png
54% of files have more coverage

Code metrics

2
10
5
1
49
40
6
0.6
2
5
1.2

Classes

Class Line # Actions
JpaCredentialService 12 10 6
0.1176470611.8%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package io.sunshower.service.security;
2   
3    import io.sunshower.common.Identifier;
4    import io.sunshower.model.core.auth.Credential;
5    import io.sunshower.service.BaseRepository;
6    import javax.inject.Inject;
7    import javax.persistence.PersistenceException;
8    import org.jasypt.util.text.TextEncryptor;
9    import org.springframework.security.access.prepost.PreAuthorize;
10   
11    /** Created by haswell on 6/6/17. */
 
12    public class JpaCredentialService extends BaseRepository<Identifier, Credential>
13    implements CredentialService {
14   
15    @Inject private TextEncryptor encryptor;
16   
 
17  2 toggle public JpaCredentialService() {
18  2 super(Credential.class, "Credential");
19    }
20   
 
21  0 toggle @Override
22    @PreAuthorize("hasPermission(#id, 'io.sunshower.model.core.auth.Credential', 'WRITE')")
23    public Credential get(Identifier id) {
24  0 return super.get(id);
25    }
26   
 
27  0 toggle @Override
28    @PreAuthorize("hasPermission(#id, 'io.sunshower.model.core.auth.Credential', 'DELETE')")
29    public Credential delete(Identifier id) {
30  0 return super.delete(id);
31    }
32   
 
33  0 toggle @Override
34    @PreAuthorize("hasAuthority('tenant:user')")
35    public Credential create(Credential entity) {
36  0 Credential credential = getEntityManager().find(Credential.class, entity.getId());
37  0 if (credential != null) {
38  0 throw new PersistenceException("Cannot modify credential");
39    }
40  0 entity.setSecret(encryptor.encrypt(entity.getSecret()));
41  0 return super.create(entity);
42    }
43   
 
44  0 toggle @Override
45    public String getSecret(Identifier id) {
46  0 Credential credential = getEntityManager().find(Credential.class, id);
47  0 return encryptor.decrypt(credential.getSecret());
48    }
49    }