Advertisement
Guest User

Untitled

a guest
Aug 12th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
  3. <context-param>
  4. <param-name>javax.faces.PROJECT_STAGE</param-name>
  5. <param-value>Development</param-value>
  6. </context-param>
  7. <servlet>
  8. <servlet-name>Faces Servlet</servlet-name>
  9. <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  10. <load-on-startup>1</load-on-startup>
  11. </servlet>
  12. <servlet-mapping>
  13. <servlet-name>Faces Servlet</servlet-name>
  14. <url-pattern>/faces/*</url-pattern>
  15. </servlet-mapping>
  16. <session-config>
  17. <session-timeout>
  18. 30
  19. </session-timeout>
  20. </session-config>
  21. <welcome-file-list>
  22. <welcome-file>faces/index.xhtml</welcome-file>
  23. </welcome-file-list>
  24.  
  25.  
  26. <!--MANUAL INPUT BY TW-->
  27.  
  28. <context-param>
  29. <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
  30. <param-value>/WEB-INF/resources</param-value>
  31. </context-param>
  32.  
  33.  
  34. <context-param>
  35. <param-name>contextConfigLocation</param-name>
  36. <param-value>
  37. /WEB-INF/applicationContext.xml
  38. /WEB-INF/spring-security.xml
  39. </param-value>
  40. </context-param>
  41.  
  42. <listener>
  43. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  44. </listener>
  45.  
  46. <filter>
  47. <filter-name>springSecurityFilterChain</filter-name>
  48. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  49. </filter>
  50.  
  51. <!--<filter-mapping>-->
  52. <!--<filter-name>springSecurityFilterChain</filter-name>-->
  53. <!--<url-pattern>/*</url-pattern>-->
  54. <!--</filter-mapping>-->
  55.  
  56. <listener>
  57. <listener-class> org.springframework.security.web.session.HttpSessionEventPublisher </listener-class>
  58. </listener>
  59.  
  60. <listener>
  61. <listener-class> com.auth.SessionListener </listener-class>
  62. </listener>
  63.  
  64.  
  65. </web-app>
  66.  
  67. <?xml version="1.0" encoding="UTF-8"?>
  68. <beans xmlns="http://www.springframework.org/schema/beans"
  69. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  70. xmlns:p="http://www.springframework.org/schema/p"
  71. xmlns:aop="http://www.springframework.org/schema/aop"
  72. xmlns:tx="http://www.springframework.org/schema/tx"
  73. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  74. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  75. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
  76.  
  77. <bean id="KSAuthenticationProvider" class="com.auth.KSAuthenticationProvider"/>
  78.  
  79. </beans>
  80.  
  81. <?xml version="1.0" encoding="UTF-8"?>
  82. <beans:beans xmlns="http://www.springframework.org/schema/security"
  83. xmlns:beans="http://www.springframework.org/schema/beans"
  84. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  85. xsi:schemaLocation="http://www.springframework.org/schema/beans
  86. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  87. http://www.springframework.org/schema/security
  88. http://www.springframework.org/schema/security/spring-security.xsd">
  89.  
  90.  
  91.  
  92. <authentication-manager>
  93. <authentication-provider ref='KSAuthenticationProvider' />
  94. </authentication-manager>
  95.  
  96.  
  97. <http auto-config="true" use-expressions="false">
  98. <access-denied-handler error-page="/faces/index.xhtml" />
  99. <intercept-url pattern="/index.xhtml*" access="ROLE_ANONYMOUS"/>
  100. <intercept-url pattern="/faces/index.xhtml*" access="ROLE_ANONYMOUS"/>
  101. <intercept-url pattern="/protected/**" access="ROLE_USER" />
  102. <intercept-url pattern="/faces/protected/**" access="ROLE_USER" />
  103. <intercept-url pattern="/vod/**" access="ROLE_USER" />
  104. <intercept-url pattern="/faces/vod/**" access="ROLE_USER" />
  105. <session-management>
  106. <concurrency-control max-sessions="1" />
  107. </session-management>
  108. <session-management invalid-session-url="/faces/index.xhtml" />
  109.  
  110. <logout logout-success-url="/afterlogout.html" />
  111.  
  112. </http>
  113.  
  114.  
  115. </beans:beans>
  116.  
  117. package com.auth;
  118.  
  119. import com.utils.Logger;
  120. import java.util.List;
  121. import javax.faces.bean.ManagedProperty;
  122. import org.springframework.security.authentication.AuthenticationProvider;
  123. import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
  124. import org.springframework.security.core.Authentication;
  125. import org.springframework.security.core.AuthenticationException;
  126. import org.springframework.security.core.GrantedAuthority;
  127. import org.springframework.security.core.authority.AuthorityUtils;
  128.  
  129.  
  130. public class KSAuthenticationProvider implements AuthenticationProvider {
  131.  
  132. private Logger logger = new Logger();
  133.  
  134. @ManagedProperty(value = "#{sessionService}")
  135. private SessionService sessionService;
  136.  
  137. public SessionService getSessionService() {
  138. return sessionService;
  139. }
  140.  
  141. public void setSessionService(SessionService sessionService) {
  142. this.sessionService = sessionService;
  143. }
  144.  
  145. @Override
  146. public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  147. UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
  148. String userName = String.valueOf(auth.getPrincipal());
  149. String password = String.valueOf(auth.getCredentials());
  150.  
  151. // blended out some internal login stuff
  152. String rolesString = "ROLE_USER";
  153.  
  154. List<GrantedAuthority> roles = AuthorityUtils.commaSeparatedStringToAuthorityList(rolesString);
  155. return new UsernamePasswordAuthenticationToken(userName, null, roles);
  156. }
  157.  
  158. @Override
  159. public boolean supports(Class<?> authentication) {
  160. return true; //To indicate that this authenticationprovider can handle the auth request. since there's currently only one way of logging in, always return true
  161. }
  162.  
  163. }
  164.  
  165. <!--PRIMEFACES-->
  166. <dependency>
  167. <groupId>org.primefaces</groupId>
  168. <artifactId>primefaces</artifactId>
  169. <version>6.0</version>
  170. </dependency>
  171. <dependency>
  172. <groupId>org.primefaces.extensions</groupId>
  173. <artifactId>all-themes</artifactId>
  174. <version>1.0.8</version>
  175. <scope>compile</scope>
  176. </dependency>
  177.  
  178.  
  179. <!--Spring Security-->
  180. <dependency>
  181. <groupId>org.springframework.security</groupId>
  182. <artifactId>spring-security-web</artifactId>
  183. <version>4.1.1.RELEASE</version>
  184. </dependency>
  185. <dependency>
  186. <groupId>org.springframework.security</groupId>
  187. <artifactId>spring-security-config</artifactId>
  188. <version>4.1.1.RELEASE</version>
  189. </dependency>
  190. <dependency>
  191. <groupId>commons-logging</groupId>
  192. <artifactId>commons-logging</artifactId>
  193. <version>1.2</version>
  194. </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement