3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
23 package org.onap.dcaegen2.platform.mod.security.services;
25 import org.onap.dcaegen2.platform.mod.models.ModUser;
26 import com.fasterxml.jackson.annotation.JsonIgnore;
27 import lombok.EqualsAndHashCode;
28 import org.springframework.security.core.GrantedAuthority;
29 import org.springframework.security.core.authority.SimpleGrantedAuthority;
30 import org.springframework.security.core.userdetails.UserDetails;
32 import java.util.Collection;
33 import java.util.List;
34 import java.util.stream.Collectors;
39 * User Details Implementation
42 public class UserDetailsImpl implements UserDetails{
44 private static final long serialVersionUID = 1L;
48 private String username;
50 private String fullName;
53 private String password;
55 private Collection<? extends GrantedAuthority> authorities;
57 public UserDetailsImpl(String id, String username, String fullName, String password, Collection<?
58 extends GrantedAuthority> authorities) {
60 this.username = username;
61 this.fullName = fullName;
62 this.password = password;
63 this.authorities = authorities;
66 public static UserDetails build(ModUser user) {
67 List<GrantedAuthority> authorities = user.getRoles().stream()
68 .map(role -> new SimpleGrantedAuthority(role.getName()))
69 .collect(Collectors.toList());
71 return new UserDetailsImpl(
80 public String getId() {
85 public Collection<? extends GrantedAuthority> getAuthorities() {
89 public List<String> getAuthoritiesAsList(){
90 return authorities.stream().map(GrantedAuthority::getAuthority)
91 .collect(Collectors.toList());
95 public String getPassword() {
100 public String getUsername() {
104 public String getFullName() {
109 public boolean isAccountNonExpired() {
114 public boolean isAccountNonLocked() {
119 public boolean isCredentialsNonExpired() {
124 public boolean isEnabled() {