jaxio / celerio

Celerio is a code generator tool for data-driven application.
Apache License 2.0
80 stars 35 forks source link

Spring Security generation with postgresal #8

Open ayoubelabbassi opened 6 years ago

ayoubelabbassi commented 6 years ago

Hi ,

i m using postgresql 9.3 as database ,i used celerio spring security convention so spring security would connect to the database ,unfortunately it is not working ,here is my table and the code generated :

CREATE TABLE account
(
  account_id integer NOT NULL DEFAULT nextval('sgedi_account_account_id_seq'::regclass),
  username character varying(255) NOT NULL,
  password character varying(255) NOT NULL,
  enabled boolean NOT NULL,
  last_connection date,
  mdp_expiration date,
  CONSTRAINT sgedi_account_pkey PRIMARY KEY (account_id)
)

CREATE TABLE userrole
(
  role_id integer NOT NULL DEFAULT nextval('sgedi_role_role_id_seq'::regclass),
  role character varying(255) NOT NULL,
  CONSTRAINT sgedi_role_pkey PRIMARY KEY (role_id)
)
CREATE TABLE account_role
(
  id serial NOT NULL,
  account_id integer NOT NULL,
  role_id integer NOT NULL,
  CONSTRAINT account_role_pkey PRIMARY KEY (id),
  CONSTRAINT fk_sgedi_accountrole_sgedi_account FOREIGN KEY (account_id)
      REFERENCES account (account_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk_sgedi_accountrole_sgedi_role FOREIGN KEY (role_id)
      REFERENCES userrole (role_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)

Code generated :

public UserDetails loadUserByUsername(String username) {
        if (username == null || username.trim().isEmpty()) {
            throw new UsernameNotFoundException("Empty username");
        }
        log.debug("Security verification for user '{}'", username);

        if ("user".equals(username)) {
            String password = "user";
            boolean enabled = true;
            boolean accountNonExpired = true;
            boolean credentialsNonExpired = true;
            boolean accountNonLocked = true;
            List<String> roles = newArrayList("ROLE_USER");
            return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
        }
        if ("admin".equals(username)) {
            String password = "admin";
            boolean enabled = true;
            boolean accountNonExpired = true;
            boolean credentialsNonExpired = true;
            boolean accountNonLocked = true;
            List<String> roles = newArrayList("ROLE_ADMIN");
            return new UserWithId(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, toGrantedAuthorities(roles), null);
        }
        return null;
    }

Thanks