Skip to content

Commit 2bb0f74

Browse files
author
Phillip Webb
committed
Polish
1 parent 8295e82 commit 2bb0f74

File tree

10 files changed

+143
-143
lines changed

10 files changed

+143
-143
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDatabaseConnection.java

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2013 the original author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,36 +119,13 @@ public static boolean isEmbedded(String driverClass) {
119119
* @return true if the data sourceis one of the embedded types
120120
*/
121121
public static boolean isEmbedded(DataSource dataSource) {
122-
boolean embedded = false;
123122
try {
124-
embedded = new JdbcTemplate(dataSource)
125-
.execute(new ConnectionCallback<Boolean>() {
126-
@Override
127-
public Boolean doInConnection(Connection con)
128-
throws SQLException, DataAccessException {
129-
String productName = con.getMetaData()
130-
.getDatabaseProductName();
131-
if (productName == null) {
132-
return false;
133-
}
134-
productName = productName.toUpperCase();
135-
if (productName.contains(H2.name())) {
136-
return true;
137-
}
138-
if (productName.contains(HSQL.name())) {
139-
return true;
140-
}
141-
if (productName.contains(DERBY.name())) {
142-
return true;
143-
}
144-
return false;
145-
}
146-
});
123+
return new JdbcTemplate(dataSource).execute(new IsEmbedded());
147124
}
148-
catch (DataAccessException e) {
125+
catch (DataAccessException ex) {
149126
// Could not connect, which means it's not embedded
127+
return false;
150128
}
151-
return embedded;
152129
}
153130

154131
/**
@@ -170,4 +147,27 @@ public static EmbeddedDatabaseConnection get(ClassLoader classLoader) {
170147
return NONE;
171148
}
172149

150+
/**
151+
* {@link ConnectionCallback} to determine if a connection is embedded.
152+
*/
153+
private static class IsEmbedded implements ConnectionCallback<Boolean> {
154+
155+
@Override
156+
public Boolean doInConnection(Connection connection) throws SQLException,
157+
DataAccessException {
158+
String productName = connection.getMetaData().getDatabaseProductName();
159+
if (productName == null) {
160+
return false;
161+
}
162+
productName = productName.toUpperCase();
163+
EmbeddedDatabaseConnection[] candidates = EmbeddedDatabaseConnection.values();
164+
for (EmbeddedDatabaseConnection candidate : candidates) {
165+
if (candidate != NONE && productName.contains(candidate.name())) {
166+
return true;
167+
}
168+
}
169+
return false;
170+
}
171+
172+
}
173173
}

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsTemplateAutoConfiguration.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.annotation.Bean;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.jms.core.JmsTemplate;
31+
import org.springframework.util.StringUtils;
3132

3233
/**
3334
* {@link EnableAutoConfiguration Auto-configuration} for {@link JmsTemplate}.
@@ -64,25 +65,22 @@ protected static class ActiveMQConnectionFactoryCreator {
6465

6566
@Bean
6667
public ConnectionFactory jmsConnectionFactory() {
67-
ConnectionFactory connectionFactory;
68-
if (this.config.getUser() != null && !"".equals(this.config.getUser())
69-
&& this.config.getPassword() != null
70-
&& !"".equals(this.config.getPassword())) {
71-
connectionFactory = new ActiveMQConnectionFactory(this.config.getUser(),
72-
this.config.getPassword(), this.config.getBrokerUrl());
73-
}
74-
else {
75-
connectionFactory = new ActiveMQConnectionFactory(
76-
this.config.getBrokerUrl());
77-
}
68+
ConnectionFactory connectionFactory = getActiveMQConnectionFactory();
7869
if (this.config.isPooled()) {
7970
PooledConnectionFactory pool = new PooledConnectionFactory();
8071
pool.setConnectionFactory(connectionFactory);
8172
return pool;
8273
}
83-
else {
84-
return connectionFactory;
74+
return connectionFactory;
75+
}
76+
77+
private ConnectionFactory getActiveMQConnectionFactory() {
78+
if (StringUtils.hasLength(this.config.getUser())
79+
&& StringUtils.hasLength(this.config.getPassword())) {
80+
return new ActiveMQConnectionFactory(this.config.getUser(),
81+
this.config.getPassword(), this.config.getBrokerUrl());
8582
}
83+
return new ActiveMQConnectionFactory(this.config.getBrokerUrl());
8684
}
8785
}
8886

spring-boot-docs/src/main/asciidoc/howto.adoc

+12-9
Original file line numberDiff line numberDiff line change
@@ -935,14 +935,14 @@ and {sc-spring-boot-autoconfigure}/orm/jpa/JpaBaseConfiguration.{sc-ext}[`JpaBas
935935
for more details.
936936

937937

938+
938939
[[howto-use-custom-entity-manager]]
939940
=== Use a custom EntityManagerFactory
940-
To take full control of the configuration of the
941-
`EntityManagerFactory`, you need to add a `@Bean` named
942-
"entityManagerFactory". To avoid eager initialization of JPA
943-
infrastructure Spring Boot autoconfiguration does not switch on its
944-
entity manager based on the presence of a bean of that type. Instead
945-
it has to do it by name.
941+
To take full control of the configuration of the `EntityManagerFactory`, you need to add
942+
a `@Bean` named "entityManagerFactory". To avoid eager initialization of JPA
943+
infrastructure, Spring Boot auto-configuration does not switch on its entity manager
944+
based on the presence of a bean of that type. Instead it has to do it by name.
945+
946946

947947

948948
[[howto-use-traditional-persistence-xml]]
@@ -1140,9 +1140,12 @@ use this in a webapp is to inject it into a void method in a
11401140
}
11411141
----
11421142

1143-
You will get the best results if you put this in a nested class, or a standalone class (i.e.
1144-
not mixed in with a lot of other `@Beans` that might be allowed to influence the order of
1145-
instantiation). The https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-web-secure[secure web sample] is a useful template to follow.
1143+
You will get the best results if you put this in a nested class, or a standalone class
1144+
(i.e. not mixed in with a lot of other `@Beans` that might be allowed to influence the
1145+
order of instantiation). The {github-code}/spring-boot-samples/spring-boot-sample-web-secure[secure web sample]
1146+
is a useful template to follow.
1147+
1148+
11461149

11471150
[[howto-enable-https]]
11481151
=== Enable HTTPS

spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

+8-7
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ all non-sensitive endpoints to be exposed over HTTP. The default convention is t
251251

252252
[[production-ready-sensitive-endpoints]]
253253
=== Exposing sensitive endpoints
254-
If you use ``Spring Security'' sensitive endpoints will be exposed over HTTP, but also
255-
protected. By default ``basic'' authentication will be used with the username `user`
254+
If you use ``Spring Security'' sensitive endpoints will be exposed over HTTP, but also
255+
protected. By default ``basic'' authentication will be used with the username `user`
256256
and a generated password (which is printed on the console when the application starts).
257257

258258
TIP: Generated passwords are logged as the application starts. Search for ``Using default
@@ -300,11 +300,10 @@ The `management.port` property can be used to change the HTTP port.
300300
management.port=8081
301301
----
302302

303-
Since your management
304-
port is often protected by a firewall, and not exposed to the public you might not need
305-
security on the management endpoints, even if your main application is secure. In that
306-
case you will have Spring
307-
Security on the classpath, and you can disable management security like this:
303+
Since your management port is often protected by a firewall, and not exposed to the public
304+
you might not need security on the management endpoints, even if your main application is
305+
secure. In that case you will have Spring Security on the classpath, and you can disable
306+
management security like this:
308307

309308
[source,properties,indent=0]
310309
----
@@ -314,6 +313,8 @@ Security on the classpath, and you can disable management security like this:
314313
(If you don't have Spring Security on the classpath then there is no need to explicitly
315314
disable the management security in this way, and it might even break the application.)
316315

316+
317+
317318
[[production-ready-customizing-management-server-address]]
318319
=== Customizing the management server address
319320
You can customize the address that the management endpoints are available on by

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

+36-45
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,8 @@ packaged as an executable archive), there are some limitations in the JSP suppor
993993
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so
994994
you can see how to set things up.
995995

996+
997+
996998
[[boot-features-security]]
997999
== Security
9981000
If Spring Security is on the classpath then web applications will be secure by default
@@ -1001,58 +1003,47 @@ application you can also add `@EnableGlobalMethodSecurity` with your desired set
10011003
Additional information can be found in the {spring-security-reference}#jc-method[Spring
10021004
Security Reference].
10031005

1004-
The default `AuthenticationManager` has a single user (username
1005-
``user'' and password random, printed at INFO level when the
1006-
application starts up). You can change the password by providing a
1007-
`security.user.password`. This and other useful properties are
1008-
externalized via
1009-
{sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`]
1006+
The default `AuthenticationManager` has a single user (username ``user'' and password
1007+
random, printed at INFO level when the application starts up). You can change the
1008+
password by providing a `security.user.password`. This and other useful properties are
1009+
externalized via {sc-spring-boot-autoconfigure}/security/SecurityProperties.{sc-ext}[`SecurityProperties`]
10101010
(properties prefix "security").
10111011

1012-
The default security configuration is implemented in
1013-
`SecurityAutoConfiguration` and in the classes imported from there
1014-
(`SpringBootWebSecurityConfiguration` for web security and
1015-
`AuthenticationManagerConfiguration` for authentication configuration
1016-
which is also relevant in non-web applications). To switch off the
1017-
Boot default configuration completely in a web application you can add
1018-
a bean with `@EnableWebSecurity`. To customize it you normally use
1019-
external properties and beans of type `WebConfigurerAdapter` (e.g. to
1012+
The default security configuration is implemented in `SecurityAutoConfiguration` and in
1013+
the classes imported from there (`SpringBootWebSecurityConfiguration` for web security
1014+
and `AuthenticationManagerConfiguration` for authentication configuration which is also
1015+
relevant in non-web applications). To switch off the Boot default configuration
1016+
completely in a web application you can add a bean with `@EnableWebSecurity`. To customize
1017+
it you normally use external properties and beans of type `WebConfigurerAdapter` (e.g. to
10201018
add form-based login). There are several secure applications in the
1021-
{github-code}/spring-boot-samples/[Spring Boot samples] to get you
1022-
started with common use cases.
1023-
1024-
The basic features you get out of the box in a web application are
1025-
1026-
* An `AuthenticationManager` bean with in-memory store and a single
1027-
user (see `SecurityProperties.User` for the properties of the user).
1019+
{github-code}/spring-boot-samples/[Spring Boot samples] to get you started with common
1020+
use cases.
10281021

1029-
* Ignored (unsecure) paths for common static resource locations
1030-
(`/css/**`, `/js/**`, `/images/**` and `**/favicon.ico`).
1022+
The basic features you get out of the box in a web application are:
10311023

1024+
* An `AuthenticationManager` bean with in-memory store and a single user (see
1025+
`SecurityProperties.User` for the properties of the user).
1026+
* Ignored (unsecure) paths for common static resource locations (`/css/**`, `/js/**`,
1027+
`/images/**` and `**/favicon.ico`).
10321028
* HTTP Basic security for all other endpoints.
1029+
* Security events published to Spring's `ApplicationEventPublisher` (successful and
1030+
unsuccessful authentication and access denied).
1031+
* Common low-level features (HSTS, XSS, CSRF, caching) provided by Spring Security are
1032+
on by default.
10331033

1034-
* Security events published to Spring's `ApplicationEventPublisher`
1035-
(successful and unsuccessful authentication and access denied).
1036-
1037-
* Common low-level features (HSTS, XSS, CSRF, caching) provided by Spring
1038-
Security are on by default.
1039-
1040-
All of the above can be switched on and off or modified using external
1041-
properties (`security.*`).
1034+
All of the above can be switched on and off or modified using external properties
1035+
(`security.*`).
10421036

10431037
If the Actuator is also in use, you will find:
10441038

1045-
* The management endpoints are secure even if the application
1046-
endpoints are unsecure.
1039+
* The management endpoints are secure even if the application endpoints are unsecure.
1040+
* Security events are transformed into `AuditEvents` and published to the `AuditService`.
1041+
* The default user will have the "ADMIN" role as well as the "USER" role.
10471042

1048-
* Security events are transformed into `AuditEvents` and published to
1049-
the `AuditService`.
1043+
The Actuator security features can be modified using external properties
1044+
(`management.security.*`).
10501045

1051-
* The default user will have the "ADMIN" role as well as the "USER"
1052-
role.
10531046

1054-
The Actuator security features can be modified using external
1055-
properties (`management.security.*`).
10561047

10571048
[[boot-features-sql]]
10581049
== Working with SQL databases
@@ -1299,12 +1290,12 @@ following to your `application.properties`.
12991290
spring.jpa.hibernate.ddl-auto=create-drop
13001291
----
13011292

1302-
Note that Hibernate's own internal property name for this (if you
1303-
happen to remember it better) is `hibernate.hbm2ddl.auto`. You can set
1304-
it, along with other Hibernate native properties, using
1305-
`spring.jpa.properties.*` (the prefix is stripped before adding them
1306-
to the entity manager). Also relevant:
1307-
`spring.jpa.generate-ddl=false` switches off all DDL generation.
1293+
NOTE: Hibernate's own internal property name for this (if you happen to remember it
1294+
better) is `hibernate.hbm2ddl.auto`. You can set it, along with other Hibernate native
1295+
properties, using `spring.jpa.properties.*` (the prefix is stripped before adding them
1296+
to the entity manager). Alternatively, `spring.jpa.generate-ddl=false` switches off all
1297+
DDL generation.
1298+
13081299

13091300

13101301
[[boot-features-nosql]]

spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/RunApp.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
/**
3737
* Run the project from Gradle.
38-
*
38+
*
3939
* @author Dave Syer
4040
*/
4141
public class RunApp extends DefaultTask {
@@ -75,7 +75,7 @@ public String call() throws Exception {
7575
}
7676
if (outputDir != null) {
7777
for (File directory : allResources) {
78-
FileUtils.removeDuplicatesFromCopy(outputDir, directory);
78+
FileUtils.removeDuplicatesFromOutputDirectory(outputDir, directory);
7979
}
8080
}
8181
exec.exec();

spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/FileUtils.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* originright 2012-2013 the copyal author or authors.
2+
* Copyright 2012-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
6-
* You may obtain a origin of the License at
6+
* You may obtain a copy of the License at
77
*
88
* http://www.apache.org/licenses/LICENSE-2.0
99
*
@@ -26,24 +26,24 @@
2626
public class FileUtils {
2727

2828
/**
29-
* Utility to remove duplicate files from a "copy" directory if they already exist in
30-
* an "origin". Recursively scans the origin directory looking for files (not
29+
* Utility to remove duplicate files from an "output" directory if they already exist
30+
* in an "origin". Recursively scans the origin directory looking for files (not
3131
* directories) that exist in both places and deleting the copy.
32-
*
33-
* @param copy the copy directory
34-
* @param origin the origin directory
32+
* @param outputDirectory the output directory
33+
* @param originDirectory the origin directory
3534
*/
36-
public static void removeDuplicatesFromCopy(File copy, File origin) {
37-
if (origin.isDirectory()) {
38-
for (String name : origin.list()) {
39-
File targetFile = new File(copy, name);
35+
public static void removeDuplicatesFromOutputDirectory(File outputDirectory,
36+
File originDirectory) {
37+
if (originDirectory.isDirectory()) {
38+
for (String name : originDirectory.list()) {
39+
File targetFile = new File(outputDirectory, name);
4040
if (targetFile.exists() && targetFile.canWrite()) {
4141
if (!targetFile.isDirectory()) {
4242
targetFile.delete();
4343
}
4444
else {
45-
FileUtils.removeDuplicatesFromCopy(targetFile, new File(origin,
46-
name));
45+
FileUtils.removeDuplicatesFromOutputDirectory(targetFile,
46+
new File(originDirectory, name));
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)