Skip to content

Commit

Permalink
Integrate Stormpath's AngularJS SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible committed Oct 19, 2016
1 parent 88f43da commit 2eee2b6
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 34 deletions.
17 changes: 15 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}]);
6 changes: 6 additions & 0 deletions app/forgot/forgot.html
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions app/forgot/forgot.state.js
Original file line number Diff line number Diff line change
@@ -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'
});
}
})();
13 changes: 11 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand All @@ -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]>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions app/login/login.html
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions app/login/login.state.js
Original file line number Diff line number Diff line change
@@ -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'
});
}
})();
6 changes: 6 additions & 0 deletions app/register/register.html
Original file line number Diff line number Diff line change
@@ -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>
16 changes: 16 additions & 0 deletions app/register/register.state.js
Original file line number Diff line number Diff line change
@@ -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'
});
}
})();
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/com/example/CorsFilter.java

This file was deleted.

33 changes: 32 additions & 1 deletion src/main/java/com/example/SecurityConfiguration.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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.