security work
This commit is contained in:
parent
74bafb99a9
commit
3572f7ecd5
@ -7,7 +7,7 @@
|
|||||||
</configSuffixes>
|
</configSuffixes>
|
||||||
<enableImports><![CDATA[false]]></enableImports>
|
<enableImports><![CDATA[false]]></enableImports>
|
||||||
<configs>
|
<configs>
|
||||||
<config>src/main/webapp/WEB-INF/mvc-servlet.xml</config>
|
<config>src/main/webapp/WEB-INF/api-servlet.xml</config>
|
||||||
</configs>
|
</configs>
|
||||||
<configSets>
|
<configSets>
|
||||||
</configSets>
|
</configSets>
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package org.baeldung.spring.config;
|
package org.baeldung.spring.config;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.ViewResolver;
|
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
||||||
import org.springframework.web.servlet.view.JstlView;
|
|
||||||
|
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -19,24 +14,4 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter {
|
|||||||
|
|
||||||
// API
|
// API
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addViewControllers(final ViewControllerRegistry registry) {
|
|
||||||
super.addViewControllers(registry);
|
|
||||||
|
|
||||||
registry.addViewController("/anonymous.html");
|
|
||||||
|
|
||||||
registry.addViewController("/login.html");
|
|
||||||
registry.addViewController("/homepage.html");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ViewResolver viewResolver() {
|
|
||||||
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
|
||||||
|
|
||||||
bean.setViewClass(JstlView.class);
|
|
||||||
bean.setPrefix("/WEB-INF/view/");
|
|
||||||
bean.setSuffix(".jsp");
|
|
||||||
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -9,6 +9,9 @@ import org.springframework.security.core.AuthenticationException;
|
|||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Entry Point will not redirect to any sort of Login - it will return the 401
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
public final class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
public final class RestAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||||
|
|
||||||
@ -16,4 +19,5 @@ public final class RestAuthenticationEntryPoint implements AuthenticationEntryPo
|
|||||||
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException {
|
public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException {
|
||||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
|
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@
|
|||||||
http://www.springframework.org/schema/beans
|
http://www.springframework.org/schema/beans
|
||||||
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
|
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
|
||||||
|
|
||||||
<http entry-point-ref="restAuthenticationEntryPoint">
|
<http use-expressions="true" entry-point-ref="restAuthenticationEntryPoint">
|
||||||
<intercept-url pattern="/api/admin/**" access="ROLE_ADMIN" />
|
<intercept-url pattern="/api/**" access="isAuthenticated()" />
|
||||||
|
|
||||||
<custom-filter ref="myFilter" position="FORM_LOGIN_FILTER" />
|
<custom-filter ref="myFilter" position="FORM_LOGIN_FILTER" />
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
|
||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>Anonymous page</h1>
|
|
||||||
|
|
||||||
<a href="<c:url value="/login.html" />">To Login</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,9 +0,0 @@
|
|||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
|
||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>This is the body of the sample view</h1>
|
|
||||||
<a href="<c:url value="/perform_logout" />">Logout</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,26 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>Login</h1>
|
|
||||||
|
|
||||||
<form name='f' action="perform_login" method='POST'>
|
|
||||||
|
|
||||||
<table>
|
|
||||||
<tr>
|
|
||||||
<td>User:</td>
|
|
||||||
<td><input type='text' name='j_username' value=''></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Password:</td>
|
|
||||||
<td><input type='password' name='j_password' /></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><input name="submit" type="submit" value="submit" /></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -24,13 +24,13 @@
|
|||||||
|
|
||||||
<!-- Spring child -->
|
<!-- Spring child -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>mvc</servlet-name>
|
<servlet-name>api</servlet-name>
|
||||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>mvc</servlet-name>
|
<servlet-name>api</servlet-name>
|
||||||
<url-pattern>/</url-pattern>
|
<url-pattern>/api/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Spring Security -->
|
<!-- Spring Security -->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user