2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
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=========================================================
21 package org.openecomp.portalapp.service;
24 import org.openecomp.policy.dao.RolesDao;
25 import org.openecomp.policy.model.Roles;
26 import org.openecomp.policy.rest.dao.UserInfoDao;
27 import org.openecomp.policy.rest.jpa.UserInfo;
28 import org.openecomp.portalsdk.core.domain.Role;
29 import org.openecomp.portalsdk.core.domain.User;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional;
34 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
35 import org.openecomp.policy.common.logging.flexlogger.Logger;
37 @Service("adminAuthExtension")
39 public class AdminAuthExtension {
45 UserInfoDao userInfoDao;
47 private static Logger logger = FlexLogger.getLogger(AdminAuthExtension.class);
48 public void saveUserExtension(User user){
49 System.out.println("User Object Recieved");
51 Roles roles = new Roles();
52 roles.setName(user.getFullName());
53 roles.setLoginId(user.getLoginId());
54 if(user.getRoles() != null){
55 rolesDAO.delete(roles);
56 for(Role role : user.getRoles()){
57 if(role.getName().trim().equalsIgnoreCase("Policy Super Admin") || role.getName().trim().equalsIgnoreCase("System Administrator") || role.getName().trim().equalsIgnoreCase("Standard User") ){
58 roles.setRole("super-admin");
59 }else if(role.getName().trim().equalsIgnoreCase("Policy Super Editor")){
60 roles.setRole("super-editor");
61 }else if(role.getName().trim().equalsIgnoreCase("Policy Super Guest")){
62 roles.setRole("super-guest");
63 }else if(role.getName().trim().equalsIgnoreCase("Policy Admin")){
64 roles.setRole("admin");
65 }else if(role.getName().trim().equalsIgnoreCase("Policy Editor")){
66 roles.setRole("editor");
67 }else if(role.getName().trim().equalsIgnoreCase("Policy Guest")){
68 roles.setRole("guest");
74 UserInfo userInfo = new UserInfo();
75 userInfo.setUserLoginId(user.getLoginId());
76 userInfo.setUserName(user.getFullName());
77 userInfoDao.save(userInfo);
80 logger.error("Exception caused while Setting role to Policy DB"+e);