Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--?xml version="1.0" encoding="UTF-8"?-->
- <beans:beans xmlns="http://www.springframework.org/schema/security"
- xmlns:beans="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/security
- http://www.springframework.org/schema/security/spring-security.xsd">
- <http create-session="always"
- use-expressions="true"
- authentication-manager-ref="authenticationManager"
- entry-point-ref="authenticationEntryPoint">
- <csrf disabled="true" />
- <intercept-url pattern="/**" access="hasRole('USER')" />
- <form-login authentication-success-handler-ref="customAuthenticationSuccessHandler" />
- <logout />
- </http>
- <authentication-manager alias="authenticationManager">
- <authentication-provider user-service-ref="userDao"></authentication-provider>
- </authentication-manager>
- </beans:beans>
- @Component
- public class CustomEntryPoint implements AuthenticationEntryPoint {
- @Override
- public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
- System.out.println("Entering commence due to failed Authentication");
- response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized Access!");
- }
- }
- public class UserDao implements UserDetailsService {
- @Override
- public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
- String password = readPasswordFromFileOrDatabase(username);
- if (password == null) throw new UsernameNotFoundException("failure");
- return User.withUsername("user").password(password).authorities("ROLE_USER").build();
- }
- private String readPasswordFromFileOrDatabase(String username) {
- if (username.equals("user")) return "q";
- return null;
- }
- }
- String plainClientCredentials="myusername:mypassword";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement