Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1023 - Install Spring Security #7

Closed
Tracked by #1
njtalba5127 opened this issue Dec 8, 2022 · 10 comments · Fixed by #25 or #27
Closed
Tracked by #1

1023 - Install Spring Security #7

njtalba5127 opened this issue Dec 8, 2022 · 10 comments · Fixed by #25 or #27
Assignees
Labels
enhancement New feature or request

Comments

@njtalba5127
Copy link
Member

njtalba5127 commented Dec 8, 2022

Timestamp: (1023) 1023 / 1433

@njtalba5127 njtalba5127 mentioned this issue Dec 8, 2022
23 tasks
@njtalba5127 njtalba5127 added the enhancement New feature or request label Dec 8, 2022
@njtalba5127 njtalba5127 self-assigned this Dec 8, 2022
@njtalba5127
Copy link
Member Author

move the controller we just made inside a new package called "controllers"

.
└── backend
    ├── HELP.md
    ├── mvnw
    ├── mvnw.cmd
    ├── pom.xml
    ├── src
    │   ├── main
    │   │   ├── java
    │   │   │   └── com
    │   │   │       └── nellyxinwei
    │   │   │           └── backend
    │   │   │               ├── BackendApplication.java
    │   │   │               └── controllers
    │   │   │                   └── GreetingsController.java

@njtalba5127
Copy link
Member Author

add the spring-security dependency inside our pom.xml

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.7.6</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.nellyxinwei</groupId>
	<artifactId>backend</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>backend</name>
	<description>Demo project for Spring Boot</description>
	<properties>
		<java.version>19</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<excludes>
						<exclude>
							<groupId>org.projectlombok</groupId>
							<artifactId>lombok</artifactId>
						</exclude>
					</excludes>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>

@njtalba5127
Copy link
Member Author

after making changes to pom.xml, reload the java project again

@njtalba5127
Copy link
Member Author

rerun spring boot application

terminal

./mvnw spring-boot:run  

@njtalba5127
Copy link
Member Author

njtalba5127 commented Dec 16, 2022

if u see the run logs of our app. by default spring boot would generate this generated security password now that we have added spring-security as our dependency

output from our terminal:

2022-12-16 17:01:57.111  WARN 993373 --- [ main] .s.s.UserDetailsServiceAutoConfiguration : 

Using generated security password: d6f58a90-4f24-454b-94e1-79bdbcb19571

@njtalba5127
Copy link
Member Author

njtalba5127 commented Dec 16, 2022

now if we open our localhost again in our browser, this time we'll be met up with a login form
http://localhost:8080/api/v1/greetings

@njtalba5127
Copy link
Member Author

now lets try using the generated password from our running log to try and login and access our api endpoints.

username: "user" (by default its user)
password: "d6f58a90-4f24-454b-94e1-79bdbcb19571"

@njtalba5127
Copy link
Member Author

njtalba5127 commented Dec 16, 2022

now making through the login page, we can once again see the output when performing the different get requests we made with our simple controller - api using our browsers

@njtalba5127
Copy link
Member Author

now when we go to the route in our browser http://localhost:8080/logout, itll show us a page with the message "Are you sure want to log out?" with a blue log out button

@njtalba5127
Copy link
Member Author

on the next part theyll explain what happened exactly

This was linked to pull requests Dec 16, 2022
Repository owner moved this from In Progress to Done in 2223-1202WinterFuyu-Projects Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant