Table of Contents
A backend made just for politicians in my country to rate their performance by the public. This is to let the public or the citizens critic and rate politicians based on how satisfied they are.
Here's why:
- Politics in the Philippines is becoming hot these past few months because of social media.
- A lot of fake news have been spreading.
- Credit Grabbing
- Demonizing other politicians
- Undermining works of other politicians
This project aims to let the public decide whether this politician did good in their job.
This section should list any major frameworks that you built your project using. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
- This project uses jdk 16 and maven as the build tool.
- Install a database of your choice(mine is postgresql).
- Populate the spring datasource properties.
spring.datasource.url=jdbc:postgresql://localhost:5432/politics spring.datasource.username=politics spring.datasource.password=politics
- Add an
Oauth2Provider
of your own and populate it in a properties file. Mine includes a local-development profile specific property for Oauth2 in my own machine. Not adding any Oauth2 properties would ignore all Oauth2 specific configuration in theSecurityConfig
class which would break the app.spring.security.oauth2.client.registration.facebook.clientId=697702354184763 spring.security.oauth2.client.registration.facebook.clientSecret=${OAUTH2_CLIENT_SECRET}
Or do it programatically:
private ClientRegistration facebookClientRegistration() {
return ClientRegistration.withRegistrationId("facebook")
.clientId("id")
.clientSecret("secret")
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.redirectUri("{baseUrl}/login/oauth2/code/facebook")
.authorizationUri("https://www.facebook.com/dialog/oauth")
.tokenUri("https://graph.facebook.com/v10.0/oauth/access_token")
.userInfoUri("https://graph.facebook.com/me")
.userNameAttributeName("id,email")
.clientName("Facebook")
.build();
}
- Add a Security Configuration Class
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.sessionFixation()
.none()
.and()
.requestCache()
.requestCache(this.statelessRequestCache())
.and()
.csrf()
.disable()
.httpBasic()
.disable()
.oauth2Client()
.authorizationCodeGrant()
.authorizationRequestRepository(this.authorizationRequestsRepo())
.and()
.authorizedClientRepository(this.authorizedClientRepo())
.and()
.addFilterBefore(new AddPoliticianFilter(), UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(new RefreshJwtFilter(), UsernamePasswordAuthenticationFilter.class);
}
public OAuth2AuthorizedClientRepository authorizedClientRepo() {
return new CustomOauth2AuthorizedClientsRepository(this.facebookUserInfoEndpointUtility());
}
@Bean
public ClientRegistrationRepository registration() {
return new InMemoryClientRegistrationRepository(this.facebookClientRegistration());
}
public FacebookOauth2UserInfoUtility facebookUserInfoEndpointUtility() {
return new FacebookOauth2UserInfoUtility();
}
@Bean
public AuthorizationRequestRepository<OAuth2AuthorizationRequest> authorizationRequestsRepo() {
return new CustomOauth2AuthorizationRequestsRepository();
}
public ClientRegistration facebookClientRegistration() {
return ClientRegistration.withRegistrationId("facebook")
.clientId(client_id)
.clientSecret(client_secret)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.redirectUri("{baseUrl}/login/oauth2/code/facebook")
.authorizationUri("https://www.facebook.com/dialog/oauth")
.tokenUri("https://graph.facebook.com/v10.0/oauth/access_token")
.userInfoUri("https://graph.facebook.com/me")
.userNameAttributeName("id,email")
.clientName("Facebook")
.build();
}
private HttpSessionRequestCache statelessRequestCache() {
HttpSessionRequestCache cache = new HttpSessionRequestCache();
cache.setCreateSessionAllowed(false);
return cache;
}
- Add Identifiers for Politicians e.g. Presidential Politician/Senatorial Politician X Add Rate Limiting functionality for adding ratings to politicians so users can't abuse their favorite or most hated politician. X Use Test Containers instead of manually adding a postgresql service on github actions. X Add Account Numbers for raters
- Add documentation
- Fork the Project
- Append
testcontainers.reuse.enabled=true
to your testcontainer properties which is usually located in/home/$USER/.testcontainers.properties
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Discord - [asianmalaysian vietnamese#1514]