Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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-4.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd">
- <beans:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
- <beans:property name="service" value="https://localhost:4444/welcome.html"/>
- <beans:property name="sendRenew" value="false"/>
- </beans:bean>
- <http entry-point-ref="casEntryPoint">
- <intercept-url pattern="/admin**" access="hasRole('ADMIN')"/>
- <custom-filter position="CAS_FILTER" ref="casFilter"/>
- </http>
- <beans:bean id="casFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
- <beans:property name="authenticationManager" ref="authenticationManager"/>
- </beans:bean>
- <beans:bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
- <beans:property name="loginUrl" value="https://localhost:8443/login/cas"/>
- <beans:property name="serviceProperties" ref="serviceProperties"/>
- </beans:bean>
- <authentication-manager alias="authenticationManager">
- <authentication-provider ref="casAuthenticationProvider"/>
- </authentication-manager>
- <beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
- <beans:property name="userDetailsService" ref="userService"/>
- <beans:property name="authenticationUserDetailsService" ref="authenticationUserDetailsService"/>
- <beans:property name="serviceProperties" ref="serviceProperties"/>
- <beans:property name="ticketValidator">
- <beans:bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
- <beans:constructor-arg index="0" value="https://localhost:9443/cas"/>
- </beans:bean>
- </beans:property>
- <beans:property name="key" value="an_id_for_this_auth_provider_only"/>
- </beans:bean>
- <user-service id="userService">
- <user name="joe" password="joe" authorities="ROLE_USER"/>
- <user name="casuser" password="Mellon" authorities="ROLE_USER"/>
- </user-service>
- <beans:bean id="authenticationUserDetailsService" class="org.springframework.security.cas.userdetails.GrantedAuthorityFromAssertionAttributesUserDetailsService">
- <beans:constructor-arg>
- <beans:array>
- <beans:value>uid</beans:value>
- <beans:value>id</beans:value>
- <beans:value>ROLE_</beans:value>
- </beans:array>
- </beans:constructor-arg>
- </beans:bean>
- </beans:beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
- <display-name>CrunchifySpringMVCTutorial</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <servlet>
- <servlet-name>test</servlet-name>
- <servlet-class>
- org.springframework.web.servlet.DispatcherServlet
- </servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>test</servlet-name>
- <url-pattern>/welcome.jsp</url-pattern>
- <url-pattern>/welcome.html</url-pattern>
- <url-pattern>*.html</url-pattern>
- </servlet-mapping>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener
- </listener-class>
- </listener>
- <!-- Loads Spring Security config file -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- /WEB-INF/spring-security.xml
- </param-value>
- </context-param>
- <!-- Spring Security -->
- <filter>
- <filter-name>springSecurityFilterChain</filter-name>
- <filter-class>org.springframework.web.filter.DelegatingFilterProxy
- </filter-class>
- </filter>
- <filter-mapping>
- <filter-name>springSecurityFilterChain</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- @Controller
- public class SimpleController {
- @RequestMapping("/welcome")
- public ModelAndView helloWorld(HttpServletRequest request) {
- Principal activeUser = request.getUserPrincipal();
- Object currentClerk = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
- String message = "<br><div style='text-align:center;'>"
- + "<h3>********** Hello World, Spring MVC Tutorial</h3> **********</div><br><br>";
- return new ModelAndView("welcome", "message", message);
- }
- @RequestMapping("/admin")
- public ModelAndView admin() {
- String message = "<br><div style='text-align:center;'>"
- + "<h3>********** Hello World, Spring MVC Tutorial</h3> **********</div><br><br>";
- return new ModelAndView("welcome", "message", message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement