minor cleanup
This commit is contained in:
parent
2a64bb227a
commit
acd6f0432e
@ -0,0 +1,31 @@
|
||||
package org.baeldung.security.basic;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
|
||||
|
||||
@Override
|
||||
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException {
|
||||
response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\"");
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
final PrintWriter writer = response.getWriter();
|
||||
writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
setRealmName("Baeldung");
|
||||
super.afterPropertiesSet();
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package org.baeldung.spring.config;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
@Configuration
|
||||
@ImportResource({ "classpath:webSecurityConfig.xml" })
|
||||
@ComponentScan("org.baeldung.security")
|
||||
public class SecSecurityConfig {
|
||||
|
||||
public SecSecurityConfig() {
|
||||
|
@ -1,28 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/security"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
|
||||
|
||||
<http pattern="/securityNone" security="none" />
|
||||
<http pattern="/securityNone" security="none" />
|
||||
|
||||
<http use-expressions="true">
|
||||
<intercept-url pattern="/login*" access="isAnonymous()" />
|
||||
<http use-expressions="true">
|
||||
<intercept-url pattern="/login*" access="isAnonymous()" />
|
||||
<intercept-url pattern="/permitAll" access="permitAll" />
|
||||
<intercept-url pattern="/**" access="isAuthenticated()" />
|
||||
|
||||
<intercept-url pattern="/permitAll" access="permitAll" />
|
||||
<http-basic entry-point-ref="myBasicAuthenticationEntryPoint" />
|
||||
|
||||
<intercept-url pattern="/**" access="isAuthenticated()" />
|
||||
</http>
|
||||
|
||||
<http-basic />
|
||||
|
||||
</http>
|
||||
|
||||
<authentication-manager>
|
||||
<authentication-provider>
|
||||
<user-service>
|
||||
<user name="user1" password="user1Pass" authorities="ROLE_USER" />
|
||||
</user-service>
|
||||
</authentication-provider>
|
||||
</authentication-manager>
|
||||
<authentication-manager>
|
||||
<authentication-provider>
|
||||
<user-service>
|
||||
<user name="user1" password="user1Pass" authorities="ROLE_USER" />
|
||||
</user-service>
|
||||
</authentication-provider>
|
||||
</authentication-manager>
|
||||
|
||||
</beans:beans>
|
Loading…
x
Reference in New Issue
Block a user