aboutsummaryrefslogtreecommitdiffstats
path: root/dcae_dmaapbc_webapp/dbca-common/src/main/java/org/onap/dcae/dmaapbc/dbcapp/domain/DmaapAccess.java
blob: 31b0fdd172502de97e44f685e9e1f95e0da3fb80 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package org.onap.dcae.dmaapbc.dbcapp.domain;

import org.openecomp.portalsdk.core.domain.support.DomainVo;
import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;

/**
 * Hold an access profile for a DMaaP REST endpoint. Represents one row in the
 * DBCA_DMAAP table.
 */
public class DmaapAccess extends DomainVo {

	private static final long serialVersionUID = 6443219375733216340L;

	// parent class defines these fields:
	// ID, created, modified, created_id, modified_id

	/** Login ID for user who owns this row */
	private String userId;
	/** Nickname for this row */
	private String name;
	/** REST API endpoint */
	private String dmaapUrl;
	/** Credentials */
	private String mechId;
	/** Credentials */
	private String password;
	/** User's preferred access profile */
	private boolean selected;

	/**
	 * Standard POJO no-arg constructor
	 */
	public DmaapAccess() {
	}

	/**
	 * Copy constructor
	 * 
	 * @param copy
	 *            Instance to copy
	 */
	public DmaapAccess(final DmaapAccess copy) {
		// Unfortunately DomainVo doesn't provide a copy constructor;
		// only the ID field is needed.
		this.id = copy.id;
		// Our fields
		this.userId = copy.userId;
		this.name = copy.name;
		this.dmaapUrl = copy.dmaapUrl;
		this.mechId = copy.mechId;
		this.password = copy.password;
		this.selected = copy.selected;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDmaapUrl() {
		return dmaapUrl;
	}

	public void setDmaapUrl(String dmaapUrl) {
		this.dmaapUrl = dmaapUrl;
	}

	public String getMechId() {
		return mechId;
	}

	public void setMechId(String mechId) {
		this.mechId = mechId;
	}

	/**
	 * Gets the encrypted password. Applications should use
	 * {@link #decryptPassword()}!
	 * 
	 * @return The encrypted password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * Sets the encrypted password. Applications should use
	 * {@link #encryptPassword(String)}!
	 * 
	 * @param password
	 *            The encrypted password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	public boolean getSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	/**
	 * A getter that decrypts the value read from the database and returns the
	 * clear text. Has no side effects.
	 * 
	 * @return Clear-text password.
	 * @throws Exception
	 *             If the password cannot be decrypted
	 */
	public String decryptPassword() throws Exception {
		if (password == null)
			return null;
		return CipherUtil.decrypt(password);
	}

	/**
	 * A setter that encrypts the clear-text in preparation for storing in the
	 * database.
	 * 
	 * @param clearText
	 *            The clear-text password to be encrypted
	 * @throws Exception
	 *             If the password cannot be encrypted
	 */
	public void encryptPassword(String clearText) throws Exception {
		if (clearText == null) {
			password = null;
			return;
		}
		password = CipherUtil.encrypt(clearText);
	}

	@Override
	public String toString() {
		return "DmaapAccess[id=" + id + ", url=" + dmaapUrl + ", ...]";
	}

}