Skip to main content

Posts

Showing posts from December, 2018

Spring5 + Rest + Agile (3)

The basic framework is created already. 1. JWT Auth 2. Hello Rest API. now, it will be good time to switch to database based user authorization. we use customized userDetailService instead of default in memeory user services. Replace InMemeory UserDetailService as DaoUserDetallService @Autowired private UserDetailsService userDetailService ; @Autowired public void globalUserDetails (AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService( userDetailService ) ; } and create new class of it: @Primary @Service public class DaoUserDetailServices implements UserDetailsService { @Autowired private PasswordEncoder bCryptPasswordEncoder ; @Override public UserDetails loadUserByUsername (String name) throws UsernameNotFoundException { if (name.equals( "admin" )) { return new UserPrincipal(name , bCryptPasswordEncoder .encode( "password" ) , "ADMIN" ) ; } else if

Spring5 + Rest In Agile (2)

Spring5 + Rest In Agile (2) In day 1, we implemented a simple rest api with spring security enabled.   Continue to add JWT feature for our rest api. Setup Authorization Server The idea of “Authorization Server” is to generate the token per access. The “Resource Server” will verify the token when accessing rest api. We just hard code everything to make this simple. @Configuration @EnableAuthorizationServer public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {     static final String CLIEN_ID = "lzheng-client" ;     static final String CLIENT_SECRET = "lzheng-secret" ;     static final String GRANT_TYPE_PASSWORD = "password" ;     static final String AUTHORIZATION_CODE = "authorization_code" ;     static final String REFRESH_TOKEN = "refresh_token" ;     static final String IMPLICIT = "implicit" ;     static final String SCOPE_READ = "read" ;     s

Spring5 + Rest In Agile (1)

Spring5 + Rest In Agijle  (1) Agile is used widely during developer’s daily life. Although it was abused a lot to hold unnecessary daily meeting to update status. But it is definitely not the reason why Agile is used at initial beginning.   Per personal experience, I just apply the agile and tdd in our daily work even at the initial step of project as coder.   Create Spring5 With Java 11 The first step is just go https://start.spring.io/ and create the baseline of spring5 project.E   The generated code will like like import the project into IntelliJ Idea The most basic idea of agile in coding way is to have each step of small and correct. There is no big jump or surprise in the whole SDLC. At first, make sure the our first step is passed. Run “./mvnw clean install” [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO