blob: dadb66c8ec91128d28466919287045f0c35ef049 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*-
* ================================================================================
* ONAP Portal SDK
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ================================================================================
*/
package org.onap.portalapp.service;
import java.util.Set;
import org.onap.policy.model.Roles;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.UserInfo;
import org.openecomp.portalapp.service.IAdminAuthExtension;
import org.openecomp.portalsdk.core.domain.Role;
import org.openecomp.portalsdk.core.domain.User;
import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service("adminAuthExtension")
@Transactional
/**
* Provides empty implementations of the methods in IAdminAuthExtension.
*/
public class AdminAuthExtension implements IAdminAuthExtension {
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AdminAuthExtension.class);
@Autowired
CommonClassDao commonClassDao;
/*
* (non-Javadoc)
* @see org.onap.portalapp.service.IAdminAuthExtension#saveUserExtension(org.openecomp.portalsdk.core.domain.User)
*/
public void saveUserExtension(User user) {
logger.debug("saveUserExtension");
savePolicyRole(null, user);
}
/*
* (non-Javadoc)
* @see org.onap.portalapp.service.IAdminAuthExtension#editUserExtension(org.openecomp.portalsdk.core.domain.User)
*/
public void editUserExtension(User user) {
logger.debug("editUserExtension");
}
/*
* (non-Javadoc)
* @see org.onap.portalapp.service.IAdminAuthExtension#saveUserRoleExtension(java.util.Set, org.openecomp.portalsdk.core.domain.User)
*/
public void saveUserRoleExtension(Set<Role> roles, User user) {
logger.debug("saveUserRoleExtension");
savePolicyRole(roles, user);
}
private void savePolicyRole(Set<Role> roles, User user){
System.out.println("User Object Recieved");
try{
Roles roles1 = new Roles();
roles1.setName(user.getFullName());
roles1.setLoginId(user.getLoginId());
if(user.getRoles() != null){
String query = "delete from Roles where loginid='"+user.getLoginId()+"'";
commonClassDao.updateQuery(query);
for(Role role : user.getRoles()){
System.out.println("User Role"+role);
if(role.getName().trim().equalsIgnoreCase("Policy Super Admin") || role.getName().trim().equalsIgnoreCase("System Administrator") || role.getName().trim().equalsIgnoreCase("Standard User") ){
roles1.setRole("super-admin");
}else if(role.getName().trim().equalsIgnoreCase("Policy Super Editor")){
roles1.setRole("super-editor");
}else if(role.getName().trim().equalsIgnoreCase("Policy Super Guest")){
roles1.setRole("super-guest");
}else if(role.getName().trim().equalsIgnoreCase("Policy Admin")){
roles1.setRole("admin");
}else if(role.getName().trim().equalsIgnoreCase("Policy Editor")){
roles1.setRole("editor");
}else if(role.getName().trim().equalsIgnoreCase("Policy Guest")){
roles1.setRole("guest");
}
commonClassDao.save(roles1);
}
}
UserInfo userInfo = new UserInfo();
userInfo.setUserLoginId(user.getLoginId());
userInfo.setUserName(user.getFullName());
commonClassDao.save(userInfo);
System.out.println("User Object Updated Successfully");
}
catch(Exception e){
logger.error("Exception caused while Setting role to Policy DB"+e);
}
}
}
|