2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
20 package org.oransc.ric.portal.dashboard.model;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.List;
27 import org.onap.portalsdk.core.restful.domain.EcompRole;
28 import org.onap.portalsdk.core.restful.domain.EcompUser;
29 import org.springframework.security.core.GrantedAuthority;
30 import org.springframework.security.core.authority.SimpleGrantedAuthority;
31 import org.springframework.security.core.userdetails.UserDetails;
33 public class EcompUserDetails implements UserDetails {
35 private static final long serialVersionUID = 1L;
36 private final EcompUser ecompUser;
38 // This is the default Spring role-name prefix.
39 private static final String ROLEP = "ROLE_";
41 public EcompUserDetails(EcompUser ecompUser) {
42 this.ecompUser = ecompUser;
46 * Gets a list of authorities (roles) for this user. To keep Spring happy, every
47 * item has prefix ROLE_.
49 public Collection<? extends GrantedAuthority> getAuthorities() {
50 List<GrantedAuthority> roleList = new ArrayList<>();
51 Iterator<EcompRole> roleIter = ecompUser.getRoles().iterator();
52 while (roleIter.hasNext()) {
53 EcompRole role = roleIter.next();
54 // Add the prefix if the ONAP portal doesn't supply it.
55 final String roleName = role.getName().startsWith(ROLEP) ? role.getName() : ROLEP + role.getName();
56 roleList.add(new SimpleGrantedAuthority(roleName));
61 public String getPassword() {
65 public String getUsername() {
66 return ecompUser.getLoginId();
69 public boolean isAccountNonExpired() {
73 public boolean isAccountNonLocked() {
77 public boolean isCredentialsNonExpired() {
81 public boolean isEnabled() {
82 return ecompUser.isActive();