- First REST operation working

This commit is contained in:
Paulo Gustavo Veiga 2012-02-12 21:57:11 -03:00
parent 5fd6ba30f5
commit 826606dc53
11 changed files with 133 additions and 77 deletions

View File

@ -250,6 +250,17 @@
<version>1.8.0.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
<build>
@ -418,6 +429,8 @@
<version>8.1.0.v20120127</version>
<configuration>
<war>${project.build.directory}/wisemapping.war</war>
<reload>automatic</reload>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
</plugins>

View File

@ -0,0 +1,44 @@
package com.wisemapping.rest;
import com.wisemapping.model.MindMap;
import com.wisemapping.service.MindmapService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Controller
public class MindmapController {
private MindmapService mindmapService;
public void setMindmapService(MindmapService mindmapService) {
this.mindmapService = mindmapService;
}
@RequestMapping(method = RequestMethod.GET, value = "/map/{id}")
public
@ResponseBody
Map<String, Object> getMindmap(@PathVariable int id) throws IOException {
final Map<String, Object> result = new HashMap<String, Object>();
final MindMap mindMap = mindmapService.getMindmapById(id);
result.put("xml", mindMap.getNativeXml());
result.put("creationTime", mindMap.getCreationTime());
result.put("description", mindMap.getDescription());
result.put("lastModification", mindMap.getLastModificationDate());
result.put("owner", mindMap.getOwner().getUsername());
return result;
}
@RequestMapping(method = RequestMethod.POST, value = "/map/{id}")
public void updateMindmap(@PathVariable int id) throws IOException {
}
}

View File

@ -1,30 +0,0 @@
package com.wisemapping.rest;
import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class UserController {
private Jaxb2Marshaller jaxb2Mashaller;
public void setJaxb2Mashaller(@NotNull final Jaxb2Marshaller jaxb2Mashaller) {
this.jaxb2Mashaller = jaxb2Mashaller;
}
private static final String XML_VIEW_NAME = "users";
@RequestMapping(method = RequestMethod.GET, value = "/employee/{id}")
public ModelAndView getEmployee(@PathVariable String id) {
User user = new User();
return new ModelAndView(XML_VIEW_NAME, "object", user);
}
}

View File

@ -21,6 +21,7 @@ public class AuthenticationProvider implements org.springframework.security.auth
public Authentication authenticate(@NotNull final Authentication auth) throws AuthenticationException {
// All your user authentication needs
final String email = auth.getName();
final User user = userManager.getUserBy(email);
final String credentials = (String) auth.getCredentials();

View File

@ -25,8 +25,7 @@ import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
public class CustomPasswordEncoder
implements PasswordEncoder
{
implements PasswordEncoder {
private PasswordEncoder delegateEncoder = new ShaPasswordEncoder();
private static final String ENC_PREFIX = "ENC:";
@ -34,8 +33,7 @@ public class CustomPasswordEncoder
public String encodePassword(@NotNull String rawPass, @Nullable Object salt) throws DataAccessException {
String password = rawPass;
if (!rawPass.startsWith(ENC_PREFIX))
{
if (!rawPass.startsWith(ENC_PREFIX)) {
password = ENC_PREFIX + delegateEncoder.encodePassword(rawPass, salt);
}
@ -47,8 +45,7 @@ public class CustomPasswordEncoder
String pass1 = "" + encPass;
String pass2 = rawPass;
if (pass1.startsWith(ENC_PREFIX))
{
if (pass1.startsWith(ENC_PREFIX)) {
pass2 = encodePassword(rawPass, salt);
}

View File

@ -21,11 +21,11 @@ package com.wisemapping.security;
import com.wisemapping.dao.UserManager;
import org.jetbrains.annotations.NotNull;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
public class DatabaseUserDetailService
implements UserDetailsService {
public class UserDetailService
implements org.springframework.security.core.userdetails.UserDetailsService {
private UserManager userManager;
@Override

View File

@ -44,10 +44,6 @@
</init-param>
</filter>
<filter-mapping>
<filter-name>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hibernate</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
@ -60,6 +56,7 @@
<param-value>mindmapSessionFactory</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
@ -75,6 +72,12 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

View File

@ -157,7 +157,7 @@
<property name="encoder" ref="encoder"/>
</bean>
<bean id="userDetailsService" class="com.wisemapping.security.DatabaseUserDetailService">
<bean id="userDetailsService" class="com.wisemapping.security.UserDetailService">
<property name="userManager" ref="userManager"/>
</bean>

View File

@ -12,25 +12,13 @@
<!-- To enable @RequestMapping process on type level and method level -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.wisemapping.model.User</value>
</list>
</property>
</bean>
<bean id="employees" class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg ref="jaxbMarshaller"/>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml"/>
<entry key="html" value="text/html"/>
<entry key="json" value="application/json"/>
</map>
</property>
<property name="viewResolvers">
@ -39,16 +27,42 @@
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp-rest"/>
<property name="prefix" value="/WEB-INF/jsp-rest/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
<!--bean id="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" /-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonConverter"/>
<ref bean="marshallingConverter"/>
</list>
</property>
</bean>
<bean id="employeeController" class="com.wisemapping.rest.UserController">
<property name="jaxb2Mashaller" ref="jaxbMarshaller"/>
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json"/>
</bean>
<bean id="marshallingConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<constructor-arg ref="jaxbMarshaller"/>
<property name="supportedMediaTypes" value="application/xml"/>
</bean>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>java.util.HashMap</value>
</list>
</property>
</bean>
<bean id="mindmapRestController" class="com.wisemapping.rest.MindmapController">
<property name="mindmapService" ref="mindmapService"/>
</bean>
</beans>

View File

@ -11,11 +11,11 @@
<bean id="encoder"
class="com.wisemapping.security.CustomPasswordEncoder"/>
<sec:http pattern="/css/*" security="none"/>
<sec:http pattern="/js/*" security="none"/>
<sec:http pattern="/images/*" security="none"/>
<sec:http pattern="/css/**" security="none"/>
<sec:http pattern="/js/**" security="none"/>
<sec:http pattern="/images/**" security="none"/>
<sec:http pattern="/favicon.ico" security="none"/>
<sec:http pattern="/c/login*" security="none"/>
<sec:http pattern="/c/login.htm" security="none"/>
<sec:http pattern="/c/userregistration.htm" security="none"/>
<sec:http pattern="/c/activation.htm" security="none"/>
<sec:http pattern="/c/forgotpassword.htm" security="none"/>
@ -23,24 +23,26 @@
<sec:http pattern="/c/try.htm" security="none"/>
<sec:http pattern="/c/search.htm" security="none"/>
<sec:http pattern="/c/keyboard.htm" security="none"/>
<sec:http pattern="/c/embeddedview*" security="none"/>
<sec:http pattern="/c/embeddedview.htm" security="none"/>
<sec:http pattern="/c/export.htm" security="none"/>
<sec:http pattern="/c/publicview.htm" security="none"/>
<sec:http pattern="/dwr/engine.js" security="none"/>
<sec:http pattern="/dwr/interface/loggerservice.js" security="none"/>
<sec:http pattern="/dwr/call/plaincall/loggerservice.logerror.dwr" security="none"/>
<sec:http use-expressions="true" >
<sec:http use-expressions="true" create-session="stateless" entry-point-ref="digestEntryPoint"
pattern="/service/**">
<sec:intercept-url pattern="/service/**" access="isAuthenticated()"/>
<sec:http-basic/>
<sec:custom-filter ref="digestFilter" after="BASIC_AUTH_FILTER"/>
</sec:http>
<sec:intercept-url pattern="/**/*" access="isFullyAuthenticated()"/>
<sec:http use-expressions="true">
<sec:intercept-url pattern="/c/*.htm" access="isFullyAuthenticated()"/>
<sec:form-login login-page="/c/login.htm" default-target-url='/c/mymaps.htm'
always-use-default-target='true' authentication-failure-url="/c/login.htm?login_error=2"
login-processing-url="/j_spring_security_check"/>
<sec:remember-me key="rememberMeKey" user-service-ref="userDetailsService"/>
<!--<sec:session-management session-fixation-protection="newSession">-->
<!--<sec:concurrency-control error-if-maximum-exceeded="true" max-sessions="1"/>-->
<!--</sec:session-management>-->
<sec:logout logout-url="/c/logout.htm" invalidate-session="true" logout-success-url="/c/login.htm"/>
</sec:http>
@ -54,8 +56,20 @@
<property name="encoder" ref="encoder"/>
</bean>
<bean id="userDetailsService" class="com.wisemapping.security.DatabaseUserDetailService">
<bean id="userDetailsService" class="com.wisemapping.security.UserDetailService">
<property name="userManager" ref="userManager"/>
</bean>
<bean id="digestFilter" class="org.springframework.security.web.authentication.www.DigestAuthenticationFilter">
<property name="userDetailsService" ref="userDetailsService"/>
<property name="authenticationEntryPoint" ref="digestEntryPoint"/>
</bean>
<bean id="digestEntryPoint"
class="org.springframework.security.web.authentication.www.DigestAuthenticationEntryPoint">
<property name="realmName" value="Wise Contacts Realm via Digest Authentication"/>
<property name="key" value="wisemapping-digest"/>
<property name="nonceValiditySeconds" value="10"/>
</bean>
</beans>