The use of SPRINGMVC interceptor life is such a tragedy, just write the content has not been saved, the results notepad++ crash, and I saw crash from scratch again, this version will be a lot simpler, first written to this.
Get personal information successfully, then write the Interceptor.
Former IBM colleague Vincent has done a W3 mandated project for Java Web and mobile, and I've learned a few things about W3 licensing from daily standup.
Now one of our projects also involves the issue of permission logins and role assignments.
SSO single sign-on USF User Rights role management explanation: SSO single sign-on is mandatory only content colleagues to log on to the system USF requires that the logged-on user is a registered user of our system and that the appropriate role is assigned, so we can think of this as dual user authentication.
USF is a separate service for the content areas that are related to the project business, and this is certainly a particularly good case for a micro-service architecture. -----------------------------------the above is about basic business requirements and the basic services that need to be accessed to implement functionality------------------------------------------------- ----------------below we will talk about how to implement the configuration of both interceptors and the management of the logon user session-------------------first, the default interceptor Dispatcherservlet for spring MVC, This interceptor is typically configured with the <servlet> <servlet-name>selection</servlet-name> <servlet-class& in Web.xml
Gt Org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load -on-startup> </servlet> <servlet-mapping> <SERVLET-NAME>SELECTION</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> that is to say, all Web requests need to be Ser Vlet processing at the same time in our other servlet-name.xml we have configured <mvc:default-servlet-handler/>, below briefly explain the role of the configuration in Springmvc-servlet.xml <mvc:default-servlet-handler/> is configured in the spring The MVC context defines a org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler, and it will look like an inspector,
The URL to enter Dispatcherservlet is screened, and if a request for a static resource is found, the request is forwarded to the Web application server default servlet processing, and the Dispatcherservlet continues processing if it is not a static resource request. The default servlet name for the general Web application server is "default", so Defaultservlethttprequesthandler can find it. If the default servlet name for all your Web application servers is not "default", you need to display the specified through the Default-servlet-name property: <mvc:default-servlet-handler Default-servlet-name= the Web server used by default servlet name/> SSO single sign-on and USF logins all belong to the Interceptor SSO and USF of Spring MVC need to configure the appropriate dependency jar or mvn files need to be displayed in the XML file in the use of their gods, and eventually configured to web.xml USF configuration code, exclude-mapping should be a static resource, will be transferred by Tomcat and other default server Ser Vlet for processing <mvc:interceptor> <mvc:mapping path= "/**"/> <!--mvc:exclude-mapping path= "/**"/--> <mvc:exclude-mapping path= "/views/**"/> <mvc : exclude-mapping path= "/static/**"/> <bean id= "Authmanagerinterceptor" class=. Interceptor.
Authmanagerinterceptor "> <!--DEV development environment Please use the following value, which is not configured for training, is the identification of USF service--> <property name= "Appcode" value= "USF"/> <property name= "Apptoken" value= "xixc9kt8z7itk6y8az1n"/>
; </bean> </mvc:interceptor> class, of course, is the default corresponding class, using USF services to obtain data, permissions, role judgments and return to the corresponding data structure, if it is all the judgment is not abnormal, then we b The request will continue to the controller side, on the contrary, will issue an alarm, prompt, end this visit authmanagerinterceptor need to inherit class Handlerinterceptoradapter or Handlerint Erceptor and implement the same method here we are going to implement a Boolean prehandle (HttpServletRequest request, httpservletresponse response, Object hand LER) For more information on other interceptor methods please refer to the relevant data SSO and USF services can be configured separately in one file. Sso-usf-interceptor.xml, and inject the file into the ServleT project-name-servlet.xml <import resource= "classpath:/springconfig/sso-usf-interceptor.xml"/> servlet file in Inject into the Web XML file <context-param> <param-name>contextConfigLocation</param-name> <p aram-value>classpath*:p roject-name-servlet.xml </param-value> </context-param> to complete the interceptor configuration------ --------------------------------------------------------------------------due to the USF to the user roles and permissions of the content, the nature of the session Discussion of related topics in the authorization file, we send the user information to an Entity data and httpservletrequest into the getsession as a global variable using request.getsession (). setattribute
(Authconstants_key, Entity Data); So that the next launch to obtain the login user information displayed in the page or bar with other interfaces can be obtained through the HttpSession session of the information, do not need to launch a database request Session.getattribute (Authconstants_key
);
--------------------------------------------------------------------------------------Done