I am completely new to spring boot and trying to write Unit test cases but stuck completely and not able to understand how Authentication works.
Controller class
@GetMapping(value = "/getAllConceptsNames")
public ConceptCO getAllConceptsNames(Authentication authentication) {
return conceptDelegate
.getAllConceptNames(PrincipalUtil.getConcepts(authentication));
}
PrincipalUtil.java
public final class PrincipalUtil {
public static Set<String> getConcepts(final Authentication authentication) {
UserPrincipal user =
(UserPrincipal) authentication.getPrincipal();
Set<String> allConcepts = new HashSet<String>();
user.getUserPrincipalAttributes().forEach(role -> allConcepts.addAll(role.getConcepts()));
return allConcepts;
}
UserPrincipalAttributes .java
public class UserPrincipalAttributes {
Set<String> columns;
Set<String> concepts;
String role;
// getter & setters
}
UserPrincipal.java
public class UserPrincipal implements AuthenticatedPrincipal {
private String name;
private Set<UserPrincipalAttributes> userPrincipalAttributes;
private String token;
// getter & setters
}
Aucun commentaire:
Enregistrer un commentaire