Permalink
Browse files

Integrate Stormpath's AngularJS SDK

1 parent 88f43da commit 2eee2b677237f793bf4ff25b6705d9c72efc984d @mraible mraible committed Oct 19, 2016
View
@@ -6,9 +6,22 @@ angular.module('myApp', [
'ngResource',
'myApp.view1',
'myApp.view2',
- 'myApp.version'
+ 'myApp.version',
+ 'stormpath',
+ 'stormpath.templates'
]).
-config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
+config(['$stateProvider', '$urlRouterProvider', '$locationProvider', 'STORMPATH_CONFIG', function($stateProvider, $urlRouterProvider, $locationProvider, STORMPATH_CONFIG) {
// For any unmatched url, redirect to /view1
$urlRouterProvider.otherwise('/view1');
+
+ $locationProvider.html5Mode(true);
+
+ STORMPATH_CONFIG.ENDPOINT_PREFIX = 'http://localhost:8080';
+ STORMPATH_CONFIG.FORM_CONTENT_TYPE = 'application/json';
+}]).
+run(['$stormpath', function($stormpath){
+ $stormpath.uiRouter({
+ loginState: 'login',
+ defaultPostLoginState: 'view1'
+ });
}]);
@@ -0,0 +1,6 @@
+<div class="container-fluid">
+ <h2 class="col-sm-offset-2" style="margin-bottom: 30px">
+ Forgot your password?
+ </h2>
+ <div sp-password-reset-request-form></div>
+</div>
@@ -0,0 +1,16 @@
+(function () {
+ 'use strict';
+
+ angular.module('myApp')
+ .config(stateConfig);
+
+ stateConfig.$inject = ['$stateProvider'];
+
+ function stateConfig($stateProvider) {
+ $stateProvider
+ .state('forgot', {
+ url: '/forgot',
+ templateUrl: 'forgot/forgot.html'
+ });
+ }
+})();
View
@@ -4,11 +4,13 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My AngularJS App</title>
+ <base href="/">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- build:css css/seed.min.css -->
<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/normalize.css">
<link rel="stylesheet" href="bower_components/html5-boilerplate/dist/css/main.css">
+ <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/app2.css">
<!-- endbuild -->
@@ -17,8 +19,10 @@
<body>
<ul class="menu">
<li><a ui-sref="view1">view1</a></li>
- <li><a ui-sref="view2">view2</a></li>
- <li><a ui-sref="search">search</a></li>
+ <li if-user><a ui-sref="view2">view2</a></li>
+ <li if-user><a ui-sref="search">search</a></li>
+ <li if-not-user><a ui-sref="login">Login</a></li>
+ <li if-user><a href="" sp-logout>Logout</a>
</ul>
<!--[if lt IE 7]>
@@ -33,6 +37,8 @@
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
+ <script src="bower_components/stormpath-sdk-angularjs/dist/stormpath-sdk-angularjs.min.js"></script>
+ <script src="bower_components/stormpath-sdk-angularjs/dist/stormpath-sdk-angularjs.tpls.min.js"></script>
<script src="app.js"></script>
<script src="view1/view1.js"></script>
<script src="view2/view2.js"></script>
@@ -41,6 +47,9 @@
<script src="search/search.service.js"></script>
<script src="edit/edit.state.js"></script>
<script src="edit/edit.controller.js"></script>
+ <script src="login/login.state.js"></script>
+ <script src="register/register.state.js"></script>
+ <script src="forgot/forgot.state.js"></script>
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>
<script src="components/version/interpolate-filter.js"></script>
@@ -0,0 +1,4 @@
+<h2 class="col-sm-offset-2" style="margin-bottom: 30px">
+ Login or <a href="" ui-sref="register">Create Account</a>
+</h2>
+<div sp-login-form></div>
@@ -0,0 +1,16 @@
+(function () {
+ 'use strict';
+
+ angular.module('myApp')
+ .config(stateConfig);
+
+ stateConfig.$inject = ['$stateProvider'];
+
+ function stateConfig($stateProvider) {
+ $stateProvider
+ .state('login', {
+ url: '/login',
+ templateUrl: 'login/login.html'
+ });
+ }
+})();
@@ -0,0 +1,6 @@
+<div class="container-fluid">
+ <h2 class="col-sm-offset-2" style="margin-bottom: 30px">
+ Create Account
+ </h2>
+ <div sp-registration-form></div>
+</div>
@@ -0,0 +1,16 @@
+(function () {
+ 'use strict';
+
+ angular.module('myApp')
+ .config(stateConfig);
+
+ stateConfig.$inject = ['$stateProvider'];
+
+ function stateConfig($stateProvider) {
+ $stateProvider
+ .state('register', {
+ url: '/register',
+ templateUrl: 'register/register.html'
+ });
+ }
+})();
View
@@ -11,6 +11,8 @@
"angular-resource": "~1.5.0",
"angular-mocks": "~1.5.0",
"html5-boilerplate": "^5.3.0",
- "angular-ui-router": "^0.3.1"
+ "angular-ui-router": "^0.3.1",
+ "stormpath-sdk-angularjs": "^1.0.0",
+ "bootstrap": "^3.3.7"
}
}
View
@@ -40,7 +40,7 @@
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-default-spring-boot-starter</artifactId>
- <version>1.0.3</version>
+ <version>1.1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -1,27 +0,0 @@
-package com.example;
-
-import org.springframework.stereotype.Component;
-import org.springframework.web.filter.OncePerRequestFilter;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * Code borrowed from https://jira.spring.io/browse/DATAREST-573 to
- * workaround Spring Data REST not supporting @CrossOrigin.
- */
-@Component
-public class CorsFilter extends OncePerRequestFilter {
-
- public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
- throws IOException, ServletException {
- response.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
- response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
- response.setHeader("Access-Control-Max-Age", "3600");
- response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
- chain.doFilter(request, response);
- }
-}
@@ -1,13 +1,44 @@
package com.example;
+import org.springframework.boot.web.servlet.FilterRegistrationBean;
+import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath;
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
+
+ @Override
+ public void configure(WebSecurity web) throws Exception {
+ web.debug(true);
+ }
+
@Override
protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests().antMatchers("/**").permitAll();
+ http.apply(stormpath()).and()
+ .authorizeRequests()
+ .antMatchers("/api/**").fullyAuthenticated()
+ .antMatchers("/**").permitAll();
+ }
+
+ @Bean
+ public FilterRegistrationBean corsFilter() {
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ CorsConfiguration config = new CorsConfiguration();
+ config.setAllowCredentials(true);
+ config.addAllowedOrigin("http://localhost:3000");
+ config.addAllowedHeader("*");
+ config.addAllowedMethod("*");
+ source.registerCorsConfiguration("/**", config);
+ FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
+ bean.setOrder(0);
+ return bean;
}
}
@@ -1 +1,3 @@
spring.data.rest.basePath=/api
+#stormpath.web.me.expand.customData=true
+stormpath.web.stormpathFilter.order=1

0 comments on commit 2eee2b6

Please sign in to comment.