Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4c8cc04
Create Section.java
albert-yakubov Nov 15, 2019
41a87ea
Update Section.java
albert-yakubov Nov 15, 2019
d1e943e
Author Model
albert-yakubov Nov 15, 2019
ccbaa23
Create Book.java
albert-yakubov Nov 15, 2019
c54777e
Create Wrote.java
albert-yakubov Nov 15, 2019
07572cc
Update Section.java
albert-yakubov Nov 15, 2019
93faf93
Update Author.java
albert-yakubov Nov 15, 2019
8df4001
Update Book.java
albert-yakubov Nov 15, 2019
3035634
Create SectionRepo.java
albert-yakubov Nov 15, 2019
68a9696
other repos
albert-yakubov Nov 15, 2019
c74bc9b
Create SectionService.java
albert-yakubov Nov 15, 2019
b97e2ed
serviceSectionImpl
albert-yakubov Nov 15, 2019
2b2d863
Create AuthorService.java
albert-yakubov Nov 15, 2019
1750d99
AuthorServiceImpl
albert-yakubov Nov 15, 2019
f786ac6
Create BookService.java
albert-yakubov Nov 15, 2019
c5c0e3e
Update BookService.java
albert-yakubov Nov 15, 2019
1042c3f
BookServiceImpl
albert-yakubov Nov 15, 2019
1285c64
AuthorController
albert-yakubov Nov 15, 2019
5c7a2c6
1st end point still not working
albert-yakubov Nov 15, 2019
d87918d
AuthorController
albert-yakubov Nov 15, 2019
c4f6a2c
Create AuthorControllerTest.java
albert-yakubov Nov 15, 2019
6554d6c
Create data.sql
albert-yakubov Nov 15, 2019
bbab378
Update application.properties
albert-yakubov Nov 15, 2019
cd4f1bb
Update pom.xml
albert-yakubov Nov 15, 2019
711fe99
createdBookController
albert-yakubov Nov 15, 2019
8dc5383
Create BookControllerTest.java
albert-yakubov Nov 15, 2019
bf01a2a
bookController
albert-yakubov Nov 16, 2019
f283bc2
oh rebuilt project
albert-yakubov Nov 16, 2019
0940300
got past the password issue
albert-yakubov Nov 18, 2019
c8f05f7
fixed the looping issue
albert-yakubov Nov 18, 2019
b35a754
Update BookController.java
albert-yakubov Nov 18, 2019
c7e684b
deploy LOL
albert-yakubov Nov 18, 2019
6a56d44
got it!!!!!!!!!!!
albert-yakubov Nov 18, 2019
37d41c6
iddingauser
albert-yakubov Nov 18, 2019
08e5c4d
Update BookController.java
albert-yakubov Nov 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions oauth2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<!-- <scope>runtime</scope>-->
<!--<scope>runtime</scope>-->
</dependency>

<dependency>
Expand Down Expand Up @@ -105,10 +105,14 @@
<version>4.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

<build>
<finalName>jrmmba-usermodel</finalName>
<finalName>als-usermodel</finalName>

<plugins>
<plugin>
Expand All @@ -127,7 +131,7 @@
<includeTarget>false</includeTarget>
<includes>
<!-- For windows <include>${project.build.directory}\${project.build.finalName}.jar</include>-->
<include>${project.build.directory}/${project.build.finalName}.jar</include>
<include>${project.build.directory}\${project.build.finalName}.jar</include>
</includes>
<jdkVersion>${java.version}</jdkVersion>
<processTypes>
Expand Down
99 changes: 55 additions & 44 deletions oauth2/src/main/java/com/lambdaschool/usermodel/SeedData.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@
import com.lambdaschool.usermodel.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Locale;

Expand Down Expand Up @@ -42,82 +53,82 @@ public void run(String[] args) throws Exception
// admin, data, user
ArrayList<UserRoles> admins = new ArrayList<>();
admins.add(new UserRoles(new User(),
r1));
r1));
admins.add(new UserRoles(new User(),
r2));
r2));
admins.add(new UserRoles(new User(),
r3));
r3));
User u1 = new User("admin",
"password",
"admin@lambdaschool.local",
admins);
"password",
"admin@lambdaschool.local",
admins);
u1.getUseremails()
.add(new Useremail(u1,
"admin@email.local"));
.add(new Useremail(u1,
"admin@email.local"));
u1.getUseremails()
.add(new Useremail(u1,
"admin@mymail.local"));
.add(new Useremail(u1,
"admin@mymail.local"));

userService.save(u1);

// data, user
ArrayList<UserRoles> datas = new ArrayList<>();
datas.add(new UserRoles(new User(),
r3));
r3));
datas.add(new UserRoles(new User(),
r2));
r2));
User u2 = new User("cinnamon",
"1234567",
"cinnamon@lambdaschool.local",
datas);
"1234567",
"cinnamon@lambdaschool.local",
datas);
u2.getUseremails()
.add(new Useremail(u2,
"cinnamon@mymail.local"));
.add(new Useremail(u2,
"cinnamon@mymail.local"));
u2.getUseremails()
.add(new Useremail(u2,
"hops@mymail.local"));
.add(new Useremail(u2,
"hops@mymail.local"));
u2.getUseremails()
.add(new Useremail(u2,
"bunny@email.local"));
.add(new Useremail(u2,
"bunny@email.local"));
userService.save(u2);

// user
ArrayList<UserRoles> users = new ArrayList<>();
users.add(new UserRoles(new User(),
r2));
r2));
User u3 = new User("barnbarn",
"ILuvM4th!",
"barnbarn@lambdaschool.local",
users);
"ILuvM4th!",
"barnbarn@lambdaschool.local",
users);
u3.getUseremails()
.add(new Useremail(u3,
"barnbarn@email.local"));
.add(new Useremail(u3,
"barnbarn@email.local"));
userService.save(u3);

users = new ArrayList<>();
users.add(new UserRoles(new User(),
r2));
r2));
User u4 = new User("puttat",
"password",
"puttat@school.lambda",
users);
"password",
"puttat@school.lambda",
users);
userService.save(u4);

users = new ArrayList<>();
users.add(new UserRoles(new User(),
r2));
r2));
User u5 = new User("misskitty",
"password",
"misskitty@school.lambda",
users);
"password",
"misskitty@school.lambda",
users);
userService.save(u5);

// using JavaFaker create a bunch of regular users
// https://www.baeldung.com/java-faker
// https://www.baeldung.com/regular-expressions-java

FakeValuesService fakeValuesService = new FakeValuesService(new Locale("en-US"),
new RandomService());
new RandomService());
Faker nameFaker = new Faker(new Locale("en-US"));

for (int i = 0; i < 100; i++)
Expand All @@ -127,16 +138,16 @@ public void run(String[] args) throws Exception

users = new ArrayList<>();
users.add(new UserRoles(new User(),
r2));
r2));
fakeUser = new User(nameFaker.name()
.username(),
"password",
nameFaker.internet()
.emailAddress(),
users);
.username(),
"password",
nameFaker.internet()
.emailAddress(),
users);
fakeUser.getUseremails()
.add(new Useremail(fakeUser,
fakeValuesService.bothify("????##@gmail.com")));
fakeValuesService.bothify("????##@gmail.com")));
userService.save(fakeUser);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;

// TODO AUTH 1

@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.lambdaschool.usermodel.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,6 +14,8 @@

import javax.sql.DataSource;


//TODO 8 db switch
@Configuration
public class DataSourceConfig
{
Expand Down Expand Up @@ -56,7 +57,7 @@ public DataSource dataSource()
{
logger.info("Manually shutting down system");
int exitCode = SpringApplication.exit(appContext,
(ExitCodeGenerator) () -> 1);
() -> 1);
System.exit(exitCode);
}

Expand All @@ -75,11 +76,11 @@ public DataSource dataSource()

logger.info("Database URL is " + myUrlString);
return DataSourceBuilder.create()
.username(myDBUser)
.password(myDBPassword)
.url(myUrlString)
.driverClassName(myDriverClass)
.build();
.username(myDBUser)
.password(myDBPassword)
.url(myUrlString)
.driverClassName(myDriverClass)
.build();
}

@Bean(name = "jdbcCustom")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lambdaschool.usermodel.config;


import org.h2.tools.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;

//TODO AUTH 6

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@

import javax.annotation.Resource;


//TODO AUTH 2

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter
{

@Resource(name = "securityUserService")
private UserDetailsService userDetailsService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.lambdaschool.usermodel.controllers;

import com.lambdaschool.usermodel.handlers.RestExceptionHandler;
import com.lambdaschool.usermodel.logging.Loggable;
import com.lambdaschool.usermodel.services.AuthorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/authors")
@Loggable
public class AuthorController {
private static final Logger logger = LoggerFactory.getLogger(RestExceptionHandler.class);
@Autowired
private AuthorService authorService;

// http://localhost:2021/authors/authors
@GetMapping(value = "/authors", produces = {"application/json"})
public ResponseEntity<?> listAllAuthors(HttpServletRequest request)
{
logger.trace(request.getMethod()
.toUpperCase() + " " + request.getRequestURI() + " accessed");
return new ResponseEntity<>(authorService.findAll(), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.lambdaschool.usermodel.controllers;

import com.lambdaschool.usermodel.models.Book;
import com.lambdaschool.usermodel.services.BookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/book")
public class BookController {

@Autowired
private BookService bookService;

private static final Logger logger = LoggerFactory.getLogger(BookController.class);

// http://localhost:2021/book/books
@GetMapping(value = "/books", produces = "application/json")
ResponseEntity<?> getBooks(){
logger.info("books/books Accessed");
List<Book> books = bookService.findAll();
return new ResponseEntity<>(books, HttpStatus.OK);
}

// http://localhost:2021/books/books/1
@PutMapping(value = "/books/{id}", consumes = {"application/json"})
public ResponseEntity<?> updateBookById(HttpServletRequest request, @RequestBody Book book, @PathVariable long id) {
logger.info(request.getMethod().toUpperCase() + " " + request.getRequestURI() + " accessed");
bookService.update(id, book);
return new ResponseEntity<>(HttpStatus.OK);
}

@PostMapping(value = "/books/{bookid}/authors/{authorid}", consumes = {"application/json"})
public ResponseEntity postBookAuthorById(HttpServletRequest request, @PathVariable long bookid, @PathVariable Book authorid) {
logger.info(request.getMethod().toUpperCase() + " " + request.getRequestURI() + " accessed");
bookService.update(bookid, authorid);
return new ResponseEntity(HttpStatus.CREATED);
}

@DeleteMapping(value = "/books/{id}")
public ResponseEntity<?> deleteBook(HttpServletRequest request, @PathVariable long id) {
logger.info(request.getMethod().toUpperCase() + " " + request.getRequestURI() + " accessed");
bookService.delete(id);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.servlet.http.HttpServletRequest;

//TODO AUTH 7 this is to logout
@Loggable
@Controller
@Api(tags = {"LogoutEndpoint"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.ArrayList;
import java.util.List;


// TODO CU 1
@Loggable
@RestController
@Api(tags = {"OpenEndpoint"})
Expand Down Expand Up @@ -80,7 +82,7 @@ public ResponseEntity<?> addNewUser(HttpServletRequest httpServletRequest,
newuser.setUsername(newminuser.getUsername());
newuser.setPassword(newminuser.getPassword());
newuser.setPrimaryemail(newminuser.getPrimaryemail());

//TODO CU 1a (auto defaults to user)(requires model UserMinimum)
ArrayList<UserRoles> newRoles = new ArrayList<>();
newRoles.add(new UserRoles(newuser,
roleService.findByName("user")));
Expand Down
Loading