forked from spring-guides/tut-spring-security-and-angular-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
22 changed files
with
1,138 additions
and
524 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
89 changes: 89 additions & 0 deletions
89
oauth2-vanilla/authserver/src/main/java/demo/AuthorizationServerConfiguration.java
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,89 @@ | ||
/* | ||
* Copyright 2016-2020 the original author or authors. | ||
* | ||
* 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 demo; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.crypto.keys.KeyManager; | ||
import org.springframework.security.crypto.keys.StaticKeyGeneratingKeyManager; | ||
import org.springframework.security.oauth2.core.AuthorizationGrantType; | ||
import org.springframework.security.oauth2.core.ClientAuthenticationMethod; | ||
import org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository; | ||
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; | ||
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.springframework.security.config.Customizer.withDefaults; | ||
|
||
@EnableWebSecurity | ||
@Import(OAuth2AuthorizationServerConfiguration.class) | ||
public class AuthorizationServerConfiguration { | ||
|
||
@Configuration | ||
@Order(1) | ||
public static class UserSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http | ||
.antMatcher("/user") | ||
.authorizeRequests(authorize -> authorize | ||
.anyRequest().authenticated() | ||
) | ||
.oauth2ResourceServer(auth -> auth | ||
.jwt(jwt -> jwt | ||
.jwkSetUri("http://localhost:9999/uaa/oauth2/jwks") | ||
) | ||
); | ||
} | ||
} | ||
|
||
@Configuration | ||
public static class AuthServerSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http | ||
.authorizeRequests(authorize -> authorize | ||
.anyRequest().authenticated() | ||
) | ||
.formLogin(withDefaults()) | ||
.httpBasic(withDefaults()); | ||
} | ||
} | ||
|
||
@Bean | ||
public RegisteredClientRepository registeredClientRepository() { | ||
RegisteredClient pilotClient = RegisteredClient.withId(UUID.randomUUID().toString()) | ||
.clientId("acme") | ||
.clientSecret("acmesecret") | ||
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC) | ||
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE) | ||
.redirectUri("http://localhost:8080/login/oauth2/code/spring") | ||
.build(); | ||
return new InMemoryRegisteredClientRepository(pilotClient); | ||
} | ||
|
||
@Bean | ||
public KeyManager keyManager() { | ||
return new StaticKeyGeneratingKeyManager(); | ||
} | ||
} |
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
109 changes: 0 additions & 109 deletions
109
oauth2-vanilla/authserver/src/main/java/demo/OAuth2AuthorizationServerConfiguration.java
This file was deleted.
Oops, something went wrong.
13 changes: 3 additions & 10 deletions
13
oauth2-vanilla/authserver/src/main/resources/application.properties
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 |
---|---|---|
@@ -1,10 +1,3 @@ | ||
server.port: 9999 | ||
server.contextPath: /uaa | ||
security.user.password: password | ||
security.sessions: if-required | ||
security.oauth2.client.clientId: acme | ||
security.oauth2.client.clientSecret: acmesecret | ||
security.oauth2.client.authorized-grant-types: authorization_code,refresh_token,password | ||
security.oauth2.client.scope: openid | ||
#security.oauth2.client.accessTokenValiditySeconds: 10 | ||
logging.level.org.springframework.security: DEBUG | ||
server.port=9999 | ||
server.servlet.context-path=/uaa | ||
spring.security.user.password=password |
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
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
6 changes: 3 additions & 3 deletions
6
oauth2-vanilla/resource/src/main/resources/application.properties
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
server.port: 9000 | ||
server.address: 127.0.0.1 | ||
security.oauth2.resource.userInfoUri: http://localhost:9999/uaa/user | ||
server.port=9000 | ||
server.address=127.0.0.1 | ||
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=http://localhost:9999/uaa/oauth2/jwks |
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
Oops, something went wrong.