-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPWDUtil.java
227 lines (195 loc) · 5.65 KB
/
PWDUtil.java
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package xxgl.scripts;
import java.util.Map;
import java.util.Iterator;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import oracle.apps.fnd.common.AppsContext;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.Properties;
public class PWDUtil
{
static String fnd_secure="FND_SECURE";
static String two_task="TWO_TASK";
static String profileName="encryption_password.txt";
static String eyEBSSriptHome="ey_EBSScript_HOME";
static String profileFullPath="";
private static Properties props = new Properties();
static {
try {
String osname = System.getProperty("os.name");
if (osname.startsWith("win") || osname.startsWith("Win"))
{
profileFullPath=getEnvValue(eyEBSSriptHome)+"\\"+profileName;
}
else
{
profileFullPath=getEnvValue(eyEBSSriptHome)+"/"+profileName;
}
props.load(new FileInputStream(profileFullPath));
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(-1);
} catch (IOException e) {
System.exit(-1);
}
}
public static void main(String[] args)
{
if (args[0].equals("DECRYPT") && !args[1].equals(""))
{
System.out.println(getDecryptValue(getKeyValue(args[1])));
}
if (args[0].equals("ENCRYPT") && !args[1].equals("") && !args[2].equals(""))
{
String encrypt_password=getEncryptValue(args[2]);
System.out.println(encrypt_password);
writeProperties(args[1],encrypt_password);
}
if (args[0].equals("KEYVALUE") && !args[1].equals(""))
{
System.out.println(getKeyValue(args[1]));
}
System.exit(0);
}
public static String getEnvValue(String Key)
{
Map<String, String> map = System.getenv();
//check LoadBalance wether applied;
if (Key.equals(two_task))
{
if (map.get(Key).toUpperCase().indexOf("_BALANCE")>=0)
{
return map.get(Key).substring(0,map.get(Key).indexOf("_"));
}
else
{
return map.get(Key);
}
}
else {
return map.get(Key);
}
}
public static String getDecryptValue(String str)
{
Connection conn=null;
AppsContext apps;
CallableStatement cstmt;
String decrypt_value="";
try
{
String osname = System.getProperty("os.name");
if (osname.startsWith("win") || osname.startsWith("Win"))
{
apps = new AppsContext(getEnvValue(fnd_secure)+"\\"+getEnvValue(two_task)+".dbc");
}
else
{
apps = new AppsContext(getEnvValue(fnd_secure)+"/"+getEnvValue(two_task)+".dbc");
}
conn = apps.getJDBCConnection();
cstmt = conn.prepareCall("{? = call xxgl_apps_pwd.decrypt(?)}");
cstmt.registerOutParameter(1, Types.VARCHAR);
cstmt.setString(2, str);
cstmt.executeUpdate();
decrypt_value = cstmt.getString(1);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (conn != null) {
conn.close();
}
return decrypt_value;
} catch (SQLException e) {
e.printStackTrace();
return "";
}
}
}
public static String getEncryptValue(String str)
{
Connection conn=null;
AppsContext apps;
CallableStatement cstmt;
String decrypt_value="";
try
{
String osname = System.getProperty("os.name");
if (osname.startsWith("win") || osname.startsWith("Win"))
{
apps = new AppsContext(getEnvValue(fnd_secure)+"\\"+getEnvValue(two_task)+".dbc");
}
else
{
apps = new AppsContext(getEnvValue(fnd_secure)+"/"+getEnvValue(two_task)+".dbc");
}
conn = apps.getJDBCConnection();
cstmt = conn.prepareCall("{? = call xxgl_apps_pwd.encrypt(?)}");
cstmt.registerOutParameter(1, Types.VARCHAR);
cstmt.setString(2, str);
cstmt.executeUpdate();
decrypt_value = cstmt.getString(1);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (conn != null) {
conn.close();
}
return decrypt_value;
} catch (SQLException e) {
e.printStackTrace();
return "";
}
}
}
public static String getKeyValue(String key) {
return props.getProperty(key);
}
public static String readValue(String filePath, String key) {
Properties props = new Properties();
try {
InputStream in = new BufferedInputStream(new FileInputStream(
filePath));
props.load(in);
String value = props.getProperty(key);
System.out.println(key +"value:"+ value);
return value;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void writeProperties(String keyname,String keyvalue) {
try {
FileOutputStream fos = new FileOutputStream(profileFullPath);
props.setProperty(keyname, keyvalue);
props.store(fos, "Update '" + keyname + "' value");
} catch (IOException e) {
e.printStackTrace();
}
}
public void updateProperties(String keyname,String keyvalue) {
try {
props.load(new FileInputStream(profileFullPath));
FileOutputStream fos = new FileOutputStream(profileFullPath);
props.setProperty(keyname, keyvalue);
props.store(fos, "Update '" + keyname + "' value");
} catch (IOException e) {
e.printStackTrace();
}
}
}