Skip to content

Commit 757e1a9

Browse files
author
Alex Huang
committed
cleanup warnings in utils
1 parent 1294cdc commit 757e1a9

16 files changed

Lines changed: 382 additions & 424 deletions

File tree

plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import javax.naming.ConfigurationException;
3333

3434
import org.apache.log4j.Logger;
35+
import org.springframework.stereotype.Component;
3536

3637
import com.cloud.exception.PermissionDeniedException;
3738
import com.cloud.user.AccountManager;
@@ -40,6 +41,7 @@
4041

4142
// This is the default API access checker that grab's the user's account
4243
// based on the account type, access is granted
44+
@Component
4345
@Local(value=APIAccessChecker.class)
4446
public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIAccessChecker {
4547

pom.xml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
</issueManagement>
4444

4545
<properties>
46-
<skipTest>true</skipTest>
46+
<skipTests>true</skipTests>
4747
<cs.jdk.version>1.6</cs.jdk.version>
4848
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4949

@@ -296,6 +296,36 @@
296296
<defaultGoal>install</defaultGoal>
297297
<pluginManagement>
298298
<plugins>
299+
<!--This plugin's configuration is used to store Eclipse m2e settings
300+
only. It has no influence on the Maven build itself. -->
301+
<plugin>
302+
<groupId>org.eclipse.m2e</groupId>
303+
<artifactId>lifecycle-mapping</artifactId>
304+
<version>1.0.0</version>
305+
<configuration>
306+
<lifecycleMappingMetadata>
307+
<pluginExecutions>
308+
<pluginExecution>
309+
<pluginExecutionFilter>
310+
<groupId>
311+
org.apache.maven.plugins
312+
</groupId>
313+
<artifactId>
314+
maven-antrun-plugin
315+
</artifactId>
316+
<versionRange>[1.7,)</versionRange>
317+
<goals>
318+
<goal>run</goal>
319+
</goals>
320+
</pluginExecutionFilter>
321+
<action>
322+
<ignore />
323+
</action>
324+
</pluginExecution>
325+
</pluginExecutions>
326+
</lifecycleMappingMetadata>
327+
</configuration>
328+
</plugin>
299329
<plugin>
300330
<groupId>org.apache.tomcat.maven</groupId>
301331
<artifactId>tomcat7-maven-plugin</artifactId>

server/src/com/cloud/api/ApiServer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ public class ApiServer implements HttpRequestHandler {
155155
@Inject List<PluggableService> _pluggableServices;
156156
@Inject IdentityDao _identityDao;
157157

158-
@Inject
159-
protected List<APIAccessChecker> _apiAccessCheckers;
158+
@Inject List<APIAccessChecker> _apiAccessCheckers;
160159

161160
private Account _systemAccount = null;
162161
private User _systemUser = null;

server/src/com/cloud/servlet/CloudStartupServlet.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
3737

3838
@Override
3939
public void init() throws ServletException {
40-
// Save Configuration Values
41-
//ComponentLocator loc = ComponentLocator.getLocator(ConfigurationServer.Name);
4240
ConfigurationServer c = (ConfigurationServer)ComponentContext.getComponent(ConfigurationServer.Name);
43-
//ConfigurationServer c = new ConfigurationServerImpl();
4441
try {
4542
c.persistDefaultValues();
4643
ManagementServer ms = (ManagementServer)ComponentContext.getComponent(ManagementServer.Name);

utils/src/com/cloud/utils/UriUtils.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static String formNfsUri(String host, String path) {
3232
throw new CloudRuntimeException("Unable to form nfs URI: " + host + " - " + path);
3333
}
3434
}
35-
35+
3636
public static String formIscsiUri(String host, String iqn, Integer lun) {
3737
try {
3838
String path = iqn;
@@ -48,34 +48,34 @@ public static String formIscsiUri(String host, String iqn, Integer lun) {
4848

4949
public static String formFileUri(String path) {
5050
File file = new File(path);
51-
51+
5252
return file.toURI().toString();
5353
}
54-
54+
5555
// a simple URI component helper (Note: it does not deal with URI paramemeter area)
5656
public static String encodeURIComponent(String url) {
57-
int schemeTail = url.indexOf("://");
58-
59-
int pathStart = 0;
60-
if(schemeTail > 0)
61-
pathStart = url.indexOf('/', schemeTail + 3);
62-
else
63-
pathStart = url.indexOf('/');
64-
65-
if(pathStart > 0) {
66-
String[] tokens = url.substring(pathStart + 1).split("/");
67-
if(tokens != null) {
68-
StringBuffer sb = new StringBuffer();
69-
sb.append(url.substring(0, pathStart));
70-
for(String token : tokens) {
71-
sb.append("/").append(URLEncoder.encode(token));
72-
}
73-
74-
return sb.toString();
75-
}
76-
}
77-
78-
// no need to do URL component encoding
79-
return url;
57+
int schemeTail = url.indexOf("://");
58+
59+
int pathStart = 0;
60+
if(schemeTail > 0)
61+
pathStart = url.indexOf('/', schemeTail + 3);
62+
else
63+
pathStart = url.indexOf('/');
64+
65+
if(pathStart > 0) {
66+
String[] tokens = url.substring(pathStart + 1).split("/");
67+
if(tokens != null) {
68+
StringBuffer sb = new StringBuffer();
69+
sb.append(url.substring(0, pathStart));
70+
for(String token : tokens) {
71+
sb.append("/").append(URLEncoder.encode(token));
72+
}
73+
74+
return sb.toString();
75+
}
76+
}
77+
78+
// no need to do URL component encoding
79+
return url;
8080
}
8181
}

utils/src/com/cloud/utils/crypt/EncryptionSecretKeyChecker.java

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -40,108 +40,108 @@
4040

4141
@Local(value = {SystemIntegrityChecker.class})
4242
public class EncryptionSecretKeyChecker implements SystemIntegrityChecker {
43-
44-
private static final Logger s_logger = Logger.getLogger(EncryptionSecretKeyChecker.class);
45-
43+
44+
private static final Logger s_logger = Logger.getLogger(EncryptionSecretKeyChecker.class);
45+
4646
private static final String s_keyFile = "/etc/cloud/management/key";
4747
private static final String s_envKey = "CLOUD_SECRET_KEY";
4848
private static StandardPBEStringEncryptor s_encryptor = new StandardPBEStringEncryptor();
4949
private static boolean s_useEncryption = false;
50-
50+
5151
@Override
5252
public void check() {
53-
//Get encryption type from db.properties
54-
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
53+
//Get encryption type from db.properties
54+
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
5555
final Properties dbProps = new Properties();
5656
try {
57-
dbProps.load(new FileInputStream(dbPropsFile));
58-
59-
final String encryptionType = dbProps.getProperty("db.cloud.encryption.type");
60-
61-
s_logger.debug("Encryption Type: "+ encryptionType);
62-
63-
if(encryptionType == null || encryptionType.equals("none")){
64-
return;
65-
}
66-
67-
s_encryptor.setAlgorithm("PBEWithMD5AndDES");
68-
String secretKey = null;
69-
70-
SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
71-
72-
if(encryptionType.equals("file")){
73-
try {
74-
BufferedReader in = new BufferedReader(new FileReader(s_keyFile));
75-
secretKey = in.readLine();
76-
//Check for null or empty secret key
77-
} catch (FileNotFoundException e) {
78-
throw new CloudRuntimeException("File containing secret key not found: "+s_keyFile, e);
79-
} catch (IOException e) {
80-
throw new CloudRuntimeException("Error while reading secret key from: "+s_keyFile, e);
81-
}
82-
83-
if(secretKey == null || secretKey.isEmpty()){
84-
throw new CloudRuntimeException("Secret key is null or empty in file "+s_keyFile);
85-
}
86-
87-
} else if(encryptionType.equals("env")){
88-
secretKey = System.getenv(s_envKey);
89-
if(secretKey == null || secretKey.isEmpty()){
90-
throw new CloudRuntimeException("Environment variable "+s_envKey+" is not set or empty");
91-
}
92-
} else if(encryptionType.equals("web")){
93-
ServerSocket serverSocket = null;
94-
int port = 8097;
95-
try {
57+
dbProps.load(new FileInputStream(dbPropsFile));
58+
59+
final String encryptionType = dbProps.getProperty("db.cloud.encryption.type");
60+
61+
s_logger.debug("Encryption Type: "+ encryptionType);
62+
63+
if(encryptionType == null || encryptionType.equals("none")){
64+
return;
65+
}
66+
67+
s_encryptor.setAlgorithm("PBEWithMD5AndDES");
68+
String secretKey = null;
69+
70+
SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
71+
72+
if(encryptionType.equals("file")){
73+
try {
74+
BufferedReader in = new BufferedReader(new FileReader(s_keyFile));
75+
secretKey = in.readLine();
76+
//Check for null or empty secret key
77+
} catch (FileNotFoundException e) {
78+
throw new CloudRuntimeException("File containing secret key not found: "+s_keyFile, e);
79+
} catch (IOException e) {
80+
throw new CloudRuntimeException("Error while reading secret key from: "+s_keyFile, e);
81+
}
82+
83+
if(secretKey == null || secretKey.isEmpty()){
84+
throw new CloudRuntimeException("Secret key is null or empty in file "+s_keyFile);
85+
}
86+
87+
} else if(encryptionType.equals("env")){
88+
secretKey = System.getenv(s_envKey);
89+
if(secretKey == null || secretKey.isEmpty()){
90+
throw new CloudRuntimeException("Environment variable "+s_envKey+" is not set or empty");
91+
}
92+
} else if(encryptionType.equals("web")){
93+
ServerSocket serverSocket = null;
94+
int port = 8097;
95+
try {
9696
serverSocket = new ServerSocket(port);
9797
} catch (IOException ioex) {
98-
throw new CloudRuntimeException("Error initializing secret key reciever", ioex);
98+
throw new CloudRuntimeException("Error initializing secret key reciever", ioex);
99+
}
100+
s_logger.info("Waiting for admin to send secret key on port "+port);
101+
Socket clientSocket = null;
102+
try {
103+
clientSocket = serverSocket.accept();
104+
} catch (IOException e) {
105+
throw new CloudRuntimeException("Accept failed on "+port);
99106
}
100-
s_logger.info("Waiting for admin to send secret key on port "+port);
101-
Socket clientSocket = null;
102-
try {
103-
clientSocket = serverSocket.accept();
104-
} catch (IOException e) {
105-
throw new CloudRuntimeException("Accept failed on "+port);
106-
}
107-
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
108-
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
109-
String inputLine, outputLine;
110-
if ((inputLine = in.readLine()) != null) {
111-
secretKey = inputLine;
112-
}
113-
out.close();
114-
in.close();
115-
clientSocket.close();
116-
serverSocket.close();
117-
} else {
118-
throw new CloudRuntimeException("Invalid encryption type: "+encryptionType);
119-
}
120-
121-
stringConfig.setPassword(secretKey);
122-
s_encryptor.setConfig(stringConfig);
123-
s_useEncryption = true;
107+
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
108+
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
109+
String inputLine;
110+
if ((inputLine = in.readLine()) != null) {
111+
secretKey = inputLine;
112+
}
113+
out.close();
114+
in.close();
115+
clientSocket.close();
116+
serverSocket.close();
117+
} else {
118+
throw new CloudRuntimeException("Invalid encryption type: "+encryptionType);
119+
}
120+
121+
stringConfig.setPassword(secretKey);
122+
s_encryptor.setConfig(stringConfig);
123+
s_useEncryption = true;
124124
} catch (FileNotFoundException e) {
125-
throw new CloudRuntimeException("File db.properties not found", e);
125+
throw new CloudRuntimeException("File db.properties not found", e);
126126
} catch (IOException e) {
127-
throw new CloudRuntimeException("Error while reading db.properties", e);
127+
throw new CloudRuntimeException("Error while reading db.properties", e);
128128
}
129129
}
130-
130+
131131
public static StandardPBEStringEncryptor getEncryptor() {
132132
return s_encryptor;
133133
}
134-
134+
135135
public static boolean useEncryption(){
136-
return s_useEncryption;
136+
return s_useEncryption;
137137
}
138-
138+
139139
//Initialize encryptor for migration during secret key change
140140
public static void initEncryptorForMigration(String secretKey){
141-
s_encryptor.setAlgorithm("PBEWithMD5AndDES");
142-
SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
143-
stringConfig.setPassword(secretKey);
144-
s_encryptor.setConfig(stringConfig);
145-
s_useEncryption = true;
141+
s_encryptor.setAlgorithm("PBEWithMD5AndDES");
142+
SimpleStringPBEConfig stringConfig = new SimpleStringPBEConfig();
143+
stringConfig.setPassword(secretKey);
144+
s_encryptor.setConfig(stringConfig);
145+
s_useEncryption = true;
146146
}
147147
}

0 commit comments

Comments
 (0)