Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
64e94f3b
Commit
64e94f3b
authored
Feb 18, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct javadoc syntax and apply code formatting
parent
9d0e50c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
29 deletions
+39
-29
BootGlobalAuthenticationConfiguration.java
...igure/security/BootGlobalAuthenticationConfiguration.java
+15
-7
SecurityAutoConfiguration.java
...oot/autoconfigure/security/SecurityAutoConfiguration.java
+1
-1
pom.xml
...y-tests/spring-boot-security-tests-web-helloworld/pom.xml
+3
-0
HelloWebSecurityApplication.java
...rld/src/main/java/sample/HelloWebSecurityApplication.java
+3
-7
HelloWebSecurityApplicationTests.java
...rc/test/java/sample/HelloWebSecurityApplicationTests.java
+17
-14
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/BootGlobalAuthenticationConfiguration.java
View file @
64e94f3b
...
...
@@ -20,6 +20,7 @@ import java.util.Map;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -29,7 +30,8 @@ import org.springframework.security.config.annotation.authentication.configurati
import
org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter
;
/**
* This works with the {@link AuthenticationConfiguration} to ensure that users are able to use:
* This works with the {@link AuthenticationConfiguration} to ensure that users are able
* to use:
*
* <pre>
* public void configureGlobal(AuthenticationManagerBuilder auth) {
...
...
@@ -37,22 +39,27 @@ import org.springframework.security.config.annotation.authentication.configurers
* }
* </pre>
*
* within their classes annotated with {{@EnableAutoConfiguration}} or use {{@SpringBootApplication}}.
* within their classes annotated with {@link EnableAutoConfiguration} or
* {@link SpringBootApplication}.
*
* @author Rob Winch
* @since 1.2.2
*/
@Configuration
@ConditionalOnClass
(
GlobalAuthenticationConfigurerAdapter
.
class
)
public
class
BootGlobalAuthenticationConfiguration
{
@Bean
public
static
BootGlobalAuthenticationConfigurationAdapter
bootGlobalAuthenticationConfigurationAdapter
(
ApplicationContext
context
)
{
public
static
BootGlobalAuthenticationConfigurationAdapter
bootGlobalAuthenticationConfigurationAdapter
(
ApplicationContext
context
)
{
return
new
BootGlobalAuthenticationConfigurationAdapter
(
context
);
}
private
static
class
BootGlobalAuthenticationConfigurationAdapter
extends
GlobalAuthenticationConfigurerAdapter
{
private
static
class
BootGlobalAuthenticationConfigurationAdapter
extends
GlobalAuthenticationConfigurerAdapter
{
private
final
ApplicationContext
context
;
private
static
final
Log
logger
=
LogFactory
.
getLog
(
BootGlobalAuthenticationConfiguration
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
BootGlobalAuthenticationConfiguration
.
class
);
public
BootGlobalAuthenticationConfigurationAdapter
(
ApplicationContext
context
)
{
this
.
context
=
context
;
...
...
@@ -60,8 +67,9 @@ public class BootGlobalAuthenticationConfiguration {
@Override
public
void
init
(
AuthenticationManagerBuilder
auth
)
{
Map
<
String
,
Object
>
beansWithAnnotation
=
context
.
getBeansWithAnnotation
(
EnableAutoConfiguration
.
class
);
if
(
logger
.
isDebugEnabled
())
{
Map
<
String
,
Object
>
beansWithAnnotation
=
this
.
context
.
getBeansWithAnnotation
(
EnableAutoConfiguration
.
class
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Eagerly initializing "
+
beansWithAnnotation
);
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfiguration.java
View file @
64e94f3b
...
...
@@ -50,7 +50,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
@EnableConfigurationProperties
@Import
({
SpringBootWebSecurityConfiguration
.
class
,
AuthenticationManagerConfiguration
.
class
,
BootGlobalAuthenticationConfiguration
.
class
})
BootGlobalAuthenticationConfiguration
.
class
})
public
class
SecurityAutoConfiguration
{
@Bean
...
...
spring-boot-security-tests/spring-boot-security-tests-web-helloworld/pom.xml
View file @
64e94f3b
...
...
@@ -15,6 +15,9 @@
<name>
Pivotal Software, Inc.
</name>
<url>
http://www.spring.io
</url>
</organization>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/main/java/sample/HelloWebSecurityApplication.java
View file @
64e94f3b
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -24,13 +25,8 @@ import org.springframework.security.config.annotation.authentication.builders.Au
public
class
HelloWebSecurityApplication
{
@Autowired
public
void
configureGlobal
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
// @formatter:off
auth
.
inMemoryAuthentication
()
.
withUser
(
"user"
).
password
(
"password"
).
roles
(
"USER"
);
// @formatter:on
public
void
configureGlobal
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
inMemoryAuthentication
().
withUser
(
"user"
).
password
(
"password"
).
roles
(
"USER"
);
}
public
static
void
main
(
String
[]
args
)
{
...
...
spring-boot-security-tests/spring-boot-security-tests-web-helloworld/src/test/java/sample/HelloWebSecurityApplicationTests.java
View file @
64e94f3b
...
...
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -30,43 +31,45 @@ import org.springframework.security.crypto.codec.Base64;
import
org.springframework.security.web.FilterChainProxy
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
static
org
.
hamcrest
.
Matchers
.
*
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
HelloWebSecurityApplication
.
class
)
@WebIntegrationTest
(
randomPort
=
true
)
public
class
HelloWebSecurityApplicationTests
{
@Autowired
FilterChainProxy
springSecurityFilterChain
;
private
FilterChainProxy
springSecurityFilterChain
;
MockHttpServletRequest
request
;
private
MockHttpServletRequest
request
;
MockHttpServletResponse
response
;
private
MockHttpServletResponse
response
;
MockFilterChain
chain
;
private
MockFilterChain
chain
;
@Before
public
void
setup
()
{
request
=
new
MockHttpServletRequest
();
response
=
new
MockHttpServletResponse
();
chain
=
new
MockFilterChain
();
this
.
request
=
new
MockHttpServletRequest
();
this
.
response
=
new
MockHttpServletResponse
();
this
.
chain
=
new
MockFilterChain
();
}
@Test
public
void
requiresAuthentication
()
throws
Exception
{
springSecurityFilterChain
.
doFilter
(
request
,
response
,
chain
);
this
.
springSecurityFilterChain
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
response
.
getStatus
(),
equalTo
(
HttpServletResponse
.
SC_UNAUTHORIZED
));
assertThat
(
this
.
response
.
getStatus
(),
equalTo
(
HttpServletResponse
.
SC_UNAUTHORIZED
));
}
@Test
public
void
userAuthenticates
()
throws
Exception
{
request
.
addHeader
(
"Authorization"
,
"Basic "
+
new
String
(
Base64
.
encode
(
"user:password"
.
getBytes
(
"UTF-8"
))));
this
.
request
.
addHeader
(
"Authorization"
,
"Basic "
+
new
String
(
Base64
.
encode
(
"user:password"
.
getBytes
(
"UTF-8"
))));
springSecurityFilterChain
.
doFilter
(
request
,
response
,
chain
);
this
.
springSecurityFilterChain
.
doFilter
(
this
.
request
,
this
.
response
,
this
.
chain
);
assertThat
(
response
.
getStatus
(),
equalTo
(
HttpServletResponse
.
SC_OK
));
assertThat
(
this
.
response
.
getStatus
(),
equalTo
(
HttpServletResponse
.
SC_OK
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment