跳至主要内容

博文

目前显示的是 2013的博文

Create a restful application with AngularJS and Grails(4):Standalone AngularJS application

Standalone AngularJS application In the real world applications, it is usually required to integrate the third party APIs into the project. Most of case, the third party service is provided as flexible REST APIs for developers. Imagine the REST API in this sample could sever other applications, such as a mobile app or other website in future, ideally it should be designated as an API centric application. The AngularJS codes can be moved to a standalone application, and consume the REST web service remotely, like other applications. Split the original codes into two projects. / /client /server The   client   is an AngularJS based application. The codes are based on AngularJS Seed sandbox. I copied the app folder in the former Grails application. The   server   is nearly no difference from the original Grails part, but the app folder in the web-app folder is moved to client. Additionally, you have to configure CORS in the server side. Configure CORS There is a good

Create a restful application with AngularJS and Grails(3): Authentication and Authorization

Authentication and Authorization Grails provides a series of built-in authentication solutions, such as Form, Basic, Digest etc. And there are several additional plugins which provides CAS, OAuth authentication, please search them from the official   Grails.org website . For API centric applications,   Basic   is the simplest authentication. Configure Basic authentication By default, Form based authentication is enabled, it is easy to configure Basic authentication in Grails application. Includes the following line in the   Config.groovy   file. grails.plugin.springsecurity.useBasicAuth = true Basic authentication includes a specific   basicExceptionTranslationFilter , so the general-purpose   exceptionTranslationFilter   can be excluded. grails.plugin.springsecurity.filterChain.chainMap = [ '/api/**':'JOINED_FILTERS,-exceptionTranslationFilter', '/**':JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter' ] All res

Create a restful application with AngularJS and Grails(2): Secure the backend REST API

Secure the backend REST API In Spring application, Spring Security is usually used to secure the application. Grails has a builtin Spring Security based plugin to integrate Spring Security into Grails applications. Install SpringSecurity core plugin Open   BuildConfig.groovy   file, add spring-security-core plugin. plugins { ... compile ":spring-security-core:2.0-RC2" } Run the following command in the project root folder to initialize the spring security plugin. grails compile --non-interactive --refresh-dependencies And use the built-in   s2-quickstart   script from this plugin to create the essential domain classes. grails s2-quickstart Person Authority Requestmap When it is done, the basic security configuration is added in   Config.groovy . grails.plugin.springsecurity.userLookup.userDomainClassName = 'com.hantsylabs.grails.example.security.Person' grails.plugin.springsecurity.userLookup.authorityJoinClassName = 'com.hantsylabs.grails.exa

Spring 4: Groovy DSL bean definition

Spring 4: Groovy DSL bean definition In Spring 2.x, script language is supported in Spring via the Java scripting engine. In Spring 4.0, Groovy is a first class citizen in Spring. Groovy can be used as an alternative for configuring bean definition. Groovy DSL bean definition As a Spring developer, you could be very familiar with XML based or/and Java annotation based bean definition. The following is an example of XML bean definition. <jdbc:embedded-database id="dataSource" type="H2"> </jdbc:embedded-database> <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <property name="persistenceUnitName" value="persistenceUnit" /> <property name="dataSource" ref="dataSource" /> <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"></property>