-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure Stormpath security and add /api/people REST endpoint
- Loading branch information
Showing
10 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.example; | ||
|
||
import javax.persistence.Embeddable; | ||
|
||
@Embeddable | ||
public class Address { | ||
|
||
private String street; | ||
private String city; | ||
private String state; | ||
private String zip; | ||
|
||
public String getStreet() { | ||
return street; | ||
} | ||
|
||
public void setStreet(String street) { | ||
this.street = street; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public void setState(String state) { | ||
this.state = state; | ||
} | ||
|
||
public String getZip() { | ||
return zip; | ||
} | ||
|
||
public void setZip(String zip) { | ||
this.zip = zip; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Address{" + | ||
"street='" + street + '\'' + | ||
", city='" + city + '\'' + | ||
", state='" + state + '\'' + | ||
", zip='" + zip + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example; | ||
|
||
import com.stormpath.sdk.account.Account; | ||
import com.stormpath.sdk.servlet.account.AccountResolver; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@Controller | ||
public class HomeController { | ||
|
||
@RequestMapping("/") | ||
public String home(HttpServletRequest request, Model model) { | ||
String name = "World"; | ||
Account account = AccountResolver.INSTANCE.getAccount(request); | ||
|
||
if (account != null) { | ||
name = account.getGivenName(); | ||
model.addAttribute(account); | ||
} | ||
|
||
model.addAttribute("name", name); | ||
|
||
return "index"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.example; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
@Entity | ||
public class Person { | ||
|
||
private Long id; | ||
private String name; | ||
private String phone; | ||
private Address address; | ||
|
||
@Id | ||
@GeneratedValue | ||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getPhone() { | ||
return phone; | ||
} | ||
|
||
public void setPhone(String phone) { | ||
this.phone = phone; | ||
} | ||
|
||
public Address getAddress() { | ||
return address; | ||
} | ||
|
||
public void setAddress(Address address) { | ||
this.address = address; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Person{" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||
", phone='" + phone + '\'' + | ||
", address=" + address + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example; | ||
|
||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
|
||
import java.util.List; | ||
|
||
@RepositoryRestResource(collectionResourceRel = "people", path = "people") | ||
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> { | ||
|
||
List<Person> findByName(@Param("name") String name); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
|
||
import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath; | ||
|
||
@Configuration | ||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.apply(stormpath()).and() | ||
.authorizeRequests() | ||
.antMatchers("/api/**").fullyAuthenticated() | ||
.antMatchers("/**").permitAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.data.rest.basePath=/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
insert into person (name, phone, street, city, state, zip) values ('Peyton Manning', '(303) 567-8910', '1234 Main Street', 'Greenwood Village', 'CO', '80111'); | ||
insert into person (name, phone, street, city, state, zip) values ('Damaryius Thomas', '(720) 213-9876', '5555 Marion Street', 'Denver', 'CO', '80202'); | ||
insert into person (name, phone, street, city, state, zip) values ('Von Miller', '(917) 323-2333', '14 Mountain Way', 'Vail', 'CO', '81657'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Hello World</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!doctype html> | ||
<html xmlns:th="http://www.thymeleaf.org"> | ||
<body> | ||
<h1 th:text="'Hello, ' + ${name} + '!'"/> | ||
|
||
<div th:unless="${account}"> | ||
<a th:href="@{/login}" class="btn btn-primary">Login</a> | ||
</div> | ||
<div th:if="${account}"> | ||
<h4 th:text="'Account Store: ' + ${account.Directory.Name}"></h4> | ||
<h4 th:text="'Provider: ' + ${account.ProviderData.ProviderId}"></h4> | ||
<form id="logoutForm" th:action="@{/logout}" method="post"> | ||
<input type="submit" class="btn btn-danger" value="Logout"/> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |