Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
Created stormpath default spring boot starter. Has the same example a…
Browse files Browse the repository at this point in the history
…s the spring security spring boot webmvc.
  • Loading branch information
dogeared committed Sep 3, 2015
1 parent 879336b commit 6ed8f1f
Show file tree
Hide file tree
Showing 11 changed files with 377 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<module>spring-boot-webmvc</module>
<module>spring-security-webmvc</module>
<module>spring-security-spring-boot-webmvc</module>
<module>spring-boot-default</module>
<module>quickstart</module>
</modules>

Expand Down
78 changes: 78 additions & 0 deletions examples/spring-boot-default/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 Stormpath, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.stormpath.sdk</groupId>
<artifactId>stormpath-sdk-root</artifactId>
<version>1.0.RC4.6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>stormpath-sdk-examples-spring-boot-default</artifactId>
<name>Stormpath Java SDK :: Examples :: Spring Boot Default</name>
<description>A simple Spring Boot Web MVC application with out-of-the-box login and self-service screens!</description>

<properties>
<tomcat.version>7.0.59</tomcat.version>
</properties>

<dependencies>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>

<!-- Compile-time dependencies: -->
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-default-spring-boot-starter</artifactId>
</dependency>

<!-- Runtime-only dependencies: -->
<dependency>
<groupId>com.stormpath.sdk</groupId>
<artifactId>stormpath-sdk-httpclient</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2015 Stormpath, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tutorial;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @since 1.0.RC4.6
*/
@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2015 Stormpath, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tutorial;

import com.stormpath.sdk.account.Account;
import com.stormpath.sdk.servlet.account.AccountResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
* @since 1.0.RC4.4
*/
@RestController
public class HelloController {

@Autowired
private HelloService helloService;

@RequestMapping("/")
String home(HttpServletRequest request) {

String name = "World";

Account account = AccountResolver.INSTANCE.getAccount(request);
if (account != null) {
name = account.getGivenName();
}

return "Hello " + name + "!";
}

@RequestMapping("/restricted")
String restricted(HttpServletRequest request) {
return helloService.sayHello(AccountResolver.INSTANCE.getAccount(request));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2015 Stormpath, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tutorial;

import com.stormpath.sdk.account.Account;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;

/**
* @since 1.0.RC4.6
*/
@Service
public class HelloService {

//Let's just specify some role here so we can grant it access to restricted resources
public static final String roleA = "GROUP_HREF_HERE";

/**
* Only users who have a Custom Data entry in their Stormpath Account or Group containing something like
* <code>"springSecurityPermissions":["play:*"]</code> or <code>"springSecurityGrantedAuthorities":["play:outside"]</code>
* will be allowed to execute this method.
*/
@PreAuthorize("hasRole('" + roleA + "') and hasPermission('play', 'outside')")
public String sayHello(Account account) {
return account.getGivenName() + ". You are allowed to say hello!";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2015 Stormpath, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tutorial;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
* @since 1.0.RC4.6
*/
@Configuration
public class SpringSecurityWebAppConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/restricted").fullyAuthenticated();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Copyright 2015 Stormpath, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# If you have more than one application registered with Stormpath, you must specify which one
# corresponds to this webapp:
#
#stormpath.application.href = https://api.stormpath.com/v1/applications/YOUR_APPLICATION_ID_HERE
21 changes: 21 additions & 0 deletions examples/spring-boot-default/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 Stormpath, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!-- <logger name="org.springframework.web" level="DEBUG"/> -->
<logger name="com.stormpath" level="INFO"/>
</configuration>
1 change: 1 addition & 0 deletions extensions/spring/boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<module>stormpath-thymeleaf-spring-boot-starter</module>
<module>stormpath-spring-security-spring-boot-starter</module>
<module>stormpath-spring-security-webmvc-spring-boot-starter</module>
<module>stormpath-default-spring-boot-starter</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 Stormpath, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-spring-parent</artifactId>
<version>1.0.RC4.6-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>stormpath-default-spring-boot-starter</artifactId>
<name>Stormpath :: Spring :: Boot :: Default :: Starter</name>
<description>Spring Boot Default Starter for Stormpath with WebMVC, Thymeleaf and Spring Security</description>

<properties>
<tomcat.version>7.0.59</tomcat.version>
</properties>

<dependencies>

<dependency>
<groupId>com.stormpath.sdk</groupId>
<artifactId>stormpath-sdk-api</artifactId>
</dependency>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-spring-security-webmvc</artifactId>
</dependency>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-webmvc-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-spring-security-webmvc-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-thymeleaf-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>com.stormpath.sdk</groupId>
<artifactId>stormpath-sdk-httpclient</artifactId>
<scope>runtime</scope>
</dependency>

<!--
We need to force Tomcat 7 for the ITs to run in Java 6.
Otherwise Tomcat 8.0.15 is used and it throws:
javax/servlet/ServletContext : Unsupported major.minor version 51.0
-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>

0 comments on commit 6ed8f1f

Please sign in to comment.