-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
400 additions
and
69 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
Binary file added
BIN
+4.63 KB
backend/bin/gr/ntua/ece/softeng/config/AuthorizationServerConfig.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-432 Bytes
(88%)
backend/bin/gr/ntua/ece/softeng/controllers/ParentController.class
Binary file not shown.
Binary file modified
BIN
-863 Bytes
(75%)
backend/bin/gr/ntua/ece/softeng/controllers/ProviderController.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
68 changes: 68 additions & 0 deletions
68
backend/src/main/java/gr/ntua/ece/softeng/config/AuthorizationServerConfig.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,68 @@ | ||
package gr.ntua.ece.softeng.config; | ||
import java.util.Arrays; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; | ||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; | ||
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; | ||
import org.springframework.security.oauth2.provider.token.TokenStore; | ||
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; | ||
|
||
@Configuration | ||
@EnableAuthorizationServer | ||
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { | ||
|
||
@Value("${security.jwt.client-id}") | ||
private String clientId; | ||
|
||
@Value("${security.jwt.client-secret}") | ||
private String clientSecret; | ||
|
||
@Value("${security.jwt.grant-type}") | ||
private String grantType; | ||
|
||
@Value("${security.jwt.scope-read}") | ||
private String scopeRead; | ||
|
||
@Value("${security.jwt.scope-write}") | ||
private String scopeWrite = "write"; | ||
|
||
@Value("${security.jwt.resource-ids}") | ||
private String resourceIds; | ||
|
||
@Autowired | ||
private TokenStore tokenStore; | ||
|
||
@Autowired | ||
private JwtAccessTokenConverter accessTokenConverter; | ||
|
||
@Autowired | ||
private AuthenticationManager authenticationManager; | ||
|
||
@Override | ||
public void configure(ClientDetailsServiceConfigurer configurer) throws Exception { | ||
configurer | ||
.inMemory() | ||
.withClient(clientId) | ||
.secret(clientSecret) | ||
.authorizedGrantTypes(grantType) | ||
.scopes(scopeRead, scopeWrite) | ||
.resourceIds(resourceIds); | ||
} | ||
|
||
@Override | ||
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { | ||
TokenEnhancerChain enhancerChain = new TokenEnhancerChain(); | ||
enhancerChain.setTokenEnhancers(Arrays.asList(accessTokenConverter)); | ||
endpoints.tokenStore(tokenStore) | ||
.accessTokenConverter(accessTokenConverter) | ||
.tokenEnhancer(enhancerChain) | ||
.authenticationManager(authenticationManager); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
backend/src/main/java/gr/ntua/ece/softeng/config/ResourceServerConfig.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,35 @@ | ||
package gr.ntua.ece.softeng.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | ||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; | ||
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; | ||
import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; | ||
|
||
@Configuration | ||
@EnableResourceServer | ||
public class ResourceServerConfig extends ResourceServerConfigurerAdapter { | ||
@Autowired | ||
private ResourceServerTokenServices tokenServices; | ||
|
||
@Value("${security.jwt.resource-ids}") | ||
private String resourceIds; | ||
|
||
@Override | ||
public void configure(ResourceServerSecurityConfigurer resources) throws Exception { | ||
resources.resourceId(resourceIds).tokenServices(tokenServices); | ||
} | ||
|
||
@Override | ||
public void configure(HttpSecurity http) throws Exception { | ||
http | ||
.requestMatchers() | ||
.and() | ||
.authorizeRequests() | ||
.antMatchers("/actuator/**", "/api-docs/**").permitAll() | ||
.antMatchers("/private/**" ).authenticated(); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
backend/src/main/java/gr/ntua/ece/softeng/config/SecurityConfig.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,85 @@ | ||
package gr.ntua.ece.softeng.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
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.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.oauth2.provider.token.DefaultTokenServices; | ||
import org.springframework.security.oauth2.provider.token.TokenStore; | ||
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; | ||
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(prePostEnabled = true) | ||
public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
|
||
@Value("${security.signing-key}") | ||
private String signingKey; | ||
|
||
@Value("${security.encoding-strength}") | ||
private Integer encodingStrength; | ||
|
||
@Value("${security.security-realm}") | ||
private String securityRealm; | ||
|
||
@Autowired | ||
private UserDetailsService userDetailsService; | ||
|
||
@Bean | ||
@Override | ||
protected AuthenticationManager authenticationManager() throws Exception { | ||
return super.authenticationManager(); | ||
} | ||
|
||
@Override | ||
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | ||
auth.userDetailsService(userDetailsService) | ||
.passwordEncoder(new ShaPasswordEncoder(encodingStrength)); | ||
} | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http | ||
.sessionManagement() | ||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS) | ||
.and() | ||
.httpBasic() | ||
.realmName(securityRealm) | ||
.and() | ||
.csrf() | ||
.disable(); | ||
|
||
} | ||
|
||
@Bean | ||
public JwtAccessTokenConverter accessTokenConverter() { | ||
JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); | ||
converter.setSigningKey(signingKey); | ||
return converter; | ||
} | ||
|
||
@Bean | ||
public TokenStore tokenStore() { | ||
return new JwtTokenStore(accessTokenConverter()); | ||
} | ||
|
||
@Bean | ||
@Primary //Making this primary to avoid any accidental duplication with another token service instance of the same name | ||
public DefaultTokenServices tokenServices() { | ||
DefaultTokenServices defaultTokenServices = new DefaultTokenServices(); | ||
defaultTokenServices.setTokenStore(tokenStore()); | ||
defaultTokenServices.setSupportRefreshToken(true); | ||
return defaultTokenServices; | ||
} | ||
} |
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.