Clover icon

sunshower-sdk

  1. Project Clover database Sat May 12 2018 05:15:40 UTC
  2. Package io.sunshower.sdk.core.model

File Authentications.java

 

Coverage histogram

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

Code metrics

6
15
2
1
49
42
5
0.33
7.5
2
2.5

Classes

Class Line # Actions
Authentications 18 15 5
0.869565287%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    package io.sunshower.sdk.core.model;
2   
3    import io.sunshower.model.core.auth.Authentication;
4    import io.sunshower.model.core.auth.Role;
5    import io.sunshower.sdk.v1.model.core.Roles;
6    import io.sunshower.sdk.v1.model.core.Users;
7    import io.sunshower.sdk.v1.model.core.security.AuthenticationElement;
8    import io.sunshower.sdk.v1.model.core.security.RoleElement;
9    import org.mapstruct.*;
10   
11    import java.util.*;
12   
13    @Mapper(
14    componentModel = "jsr330",
15    unmappedTargetPolicy = ReportingPolicy.IGNORE,
16    uses = {Roles.class, Users.class, Tokens.class}
17    )
 
18    public interface Authentications {
19   
20    @Mappings(@Mapping(source = "principal", target = "user"))
21    Authentication toModel(AuthenticationElement element);
22   
23    @InheritInverseConfiguration
24    AuthenticationElement toElement(Authentication authentication);
25   
 
26  1 toggle static List<RoleElement> mapRoles(Role root) {
27  1 if (root == null) {
28  0 return null;
29    }
30  1 Queue<Role> set = new LinkedList<>();
31  1 List<RoleElement> roleElements = new ArrayList<>();
32  1 set.add(root);
33  7 while (!set.isEmpty()) {
34  6 Role poll = set.poll();
35  6 roleElements.add(mapRole(poll));
36  6 Set<Role> children = poll.getChildren();
37  6 if (children != null) {
38  6 set.addAll(children);
39    }
40    }
41  1 return roleElements;
42    }
43   
 
44  6 toggle static RoleElement mapRole(Role poll) {
45  6 RoleElement e = new RoleElement();
46  6 e.setAuthority(poll.getAuthority());
47  6 return e;
48    }
49    }