Commit baef9795 authored by Valentin Suhnjov's avatar Valentin Suhnjov

Merge branch 'releases/release-0.1.0' into master

parents 3af3d660 e548b9cb
......@@ -5,7 +5,7 @@
<groupId>ee.eesti.riha</groupId>
<artifactId>rest</artifactId>
<version>0.0.5-SNAPSHOT</version>
<version>0.1.0</version>
<packaging>war</packaging>
......
alter table riha.role_right add CONSTRAINT fk_role_rights_kind FOREIGN KEY (kind_id)
REFERENCES riha.kind (kind_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
alter table riha.main_resource add CONSTRAINT fk_kind FOREIGN KEY (kind_id)
REFERENCES riha.kind (kind_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
alter table riha.main_resource add CONSTRAINT fk_main_resource_main_resource_02 FOREIGN KEY (main_resource_template_id)
REFERENCES riha.main_resource (main_resource_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
......
......@@ -58,19 +58,6 @@ START 436069
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.main_resource_seq TO riha;
-- Sequence: riha.role_right_seq
-- DROP SEQUENCE riha.role_right_seq;
CREATE SEQUENCE riha.role_right_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 338
CACHE 1;
GRANT SELECT, USAGE ON SEQUENCE riha.role_right_seq TO riha;
-- Table: riha.kind
-- DROP TABLE riha.kind;
......@@ -105,50 +92,6 @@ COMMENT ON COLUMN riha.kind.modified_date IS 'Kirje muutmise ajamoment';
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.kind TO riha;
-- Table:fdsfdsff riha.role_right
-- DROP TABLE riha.role_right;
CREATE TABLE riha.role_right
(
role_right_id integer NOT NULL,
kind_id integer NOT NULL, -- Objekti liik, millele antud õigus rakendub.
role_name character varying(50) NOT NULL, -- Rolli nimi, mille korral antud õigus kehtib.
access_restriction integer NOT NULL, -- Juurdepääsupiirang, mille suhtes õigus rakendub. Kui väärtus on võrdne või suurem objekti vastava välja väärtusest, siis rakendub antud õigus sellele objektile.
read integer NOT NULL, -- 0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes
"create" integer NOT NULL, -- 0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes
update integer NOT NULL, -- 0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes
delete integer NOT NULL, -- 0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes
CONSTRAINT pk_user_rights PRIMARY KEY (role_right_id),
CONSTRAINT fk_role_rights_kind FOREIGN KEY (kind_id)
REFERENCES riha.kind (kind_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
COMMENT ON COLUMN riha.role_right.kind_id IS 'Objekti liik, millele antud õigus rakendub.';
COMMENT ON COLUMN riha.role_right.role_name IS 'Rolli nimi, mille korral antud õigus kehtib.';
COMMENT ON COLUMN riha.role_right.access_restriction IS 'Juurdepääsupiirang, mille suhtes õigus rakendub. Kui väärtus on võrdne või suurem objekti vastava välja väärtusest, siis rakendub antud õigus sellele objektile.';
COMMENT ON COLUMN riha.role_right.read IS '0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes';
COMMENT ON COLUMN riha.role_right."create" IS '0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes';
COMMENT ON COLUMN riha.role_right.update IS '0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes';
COMMENT ON COLUMN riha.role_right.delete IS '0-õigus puudub 1-õigus oma objektide suhtes 2-õigus kõikide objektide suhtes';
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE riha.role_right TO riha;
-- Index: riha.ixfk_user_rights_kind
-- DROP INDEX riha.ixfk_user_rights_kind;
CREATE INDEX ixfk_user_rights_kind
ON riha.role_right
USING btree
(kind_id);
-- Table: riha.main_resource
-- DROP TABLE riha.main_resource;
......@@ -156,11 +99,11 @@ CREATE INDEX ixfk_user_rights_kind
CREATE TABLE riha.main_resource
(
main_resource_id integer NOT NULL, -- Ressursi unikaalne ID. Iga uus versioon saab uue ID. Kõige väiksema ID-ga ressurss on hetkel aktuaalne
uri character varying(150) NOT NULL, -- Ressursi unikaalne URI. Sellega määratakse millised on samad aga erineva versiooniga ressursid ressursside tabelis
name character varying(190) NOT NULL, -- Ressursi nimetus
owner character varying(150) NOT NULL, -- Ressursi omanik. Tavapäraselt ettevõtte registrikood. Infosüsteemi mõttes vastutav isik.
uri character varying(150), -- Ressursi unikaalne URI. Sellega määratakse millised on samad aga erineva versiooniga ressursid ressursside tabelis
name character varying(190), -- Ressursi nimetus
owner character varying(150), -- Ressursi omanik. Tavapäraselt ettevõtte registrikood. Infosüsteemi mõttes vastutav isik.
short_name character varying(50), -- Ressursi lühinimetus
version character varying(10) NOT NULL, -- Inimloetav versiooni nimi. See ei ühti infosüsteemi versiooni nimetusega
version character varying(10), -- Inimloetav versiooni nimi. See ei ühti infosüsteemi versiooni nimetusega
json_content jsonb, -- Ressursi kirjelduse täisinfo esitatuna json struktuurina (sisaldab ka eraldi väljadena toodud andmed).
parent_uri character varying(150), -- Hierarhilise ressursi puhul on siin näidatud vanema URI
main_resource_parent_id integer, -- Hierarhilise ressursi puhul on siin näidatud vanema ID
......@@ -169,18 +112,15 @@ CREATE TABLE riha.main_resource
state character(1), -- Ressursi olek (C-current, O-old, T-temporary, D-deleted jms.) Vaikimisi 'C'.
start_date timestamp without time zone, -- Käesoleva versiooni kehtivuse algus
end_date timestamp without time zone, -- Käesoleva versiooni kehtivuse lõpp
creator character varying(150) NOT NULL, -- Kirje loonud isiku isikukood või muu identifikaator
creator character varying(150), -- Kirje loonud isiku isikukood või muu identifikaator
modifier character varying(150), -- Viimati kirjet muutnud isiku isikukood või muu identifikaator
creation_date timestamp without time zone NOT NULL, -- Kirje loomise ajahetk.
creation_date timestamp without time zone, -- Kirje loomise ajahetk.
modified_date timestamp without time zone, -- Kirje viimati muutmise ajahetk.
old_id integer,
field_name character varying(150),
kind_id integer, -- Ressursi liik (infosystem, classifier, service, dictionary, xmlresource vms.).
main_resource_template_id integer,
CONSTRAINT pk_main_resource PRIMARY KEY (main_resource_id),
CONSTRAINT fk_kind FOREIGN KEY (kind_id)
REFERENCES riha.kind (kind_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk_main_resource_main_resource_02 FOREIGN KEY (main_resource_template_id)
REFERENCES riha.main_resource (main_resource_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
......
alter table riha.role_right drop constraint fk_role_rights_kind;
alter table riha.main_resource drop constraint fk_kind;
alter table riha.main_resource drop constraint fk_main_resource_main_resource_02;
alter table riha.data_object drop constraint fk_data_object_data_object;
alter table riha.data_object drop constraint fk_data_object_kind;
......
......@@ -38,20 +38,10 @@ DROP INDEX riha.ixfk_main_resource_main_resource;
DROP TABLE riha.main_resource;
-- Index: riha.ixfk_user_rights_kind
DROP INDEX riha.ixfk_user_rights_kind;
-- Table: riha.role_right
DROP TABLE riha.role_right;
-- Table: riha.kind
DROP TABLE riha.kind;
-- Sequence: riha.comment_seq
DROP SEQUENCE riha.comment_seq;
......@@ -71,7 +61,3 @@ DROP SEQUENCE riha.kind_seq;
-- Sequence: riha.main_resource_seq
DROP SEQUENCE riha.main_resource_seq;
-- Sequence: riha.role_right_seq
DROP SEQUENCE riha.role_right_seq;
package ee.eesti.riha.rest.auth;
import java.util.List;
import ee.eesti.riha.rest.model.readonly.Role_right;
// TODO: Auto-generated Javadoc
/**
* The Class AuthInfo.
*/
/**
* @author Praktikant
*
*/
public class AuthInfo {
private String user_code;
private String user_name;
private String org_code;
private String org_name;
private String role_code;
private String role_name;
private String token;
private List<SimpleRoleRight> role_right;
public static final AuthInfo DEFAULT = new AuthInfo("UNAUTHORIZED", "UNAUTHORIZED", "DEFAULT");
/**
* Instantiates a new auth info.
*/
public AuthInfo() {
}
/**
* Instantiates a new auth info.
*
* @param isikuKood the isiku kood
* @param asutus the asutus
* @param roll the roll
*/
public AuthInfo(String isikuKood, String asutus, String roll) {
this.user_code = isikuKood;
this.org_code = asutus;
this.role_code = roll;
}
/**
* Instantiates a new auth info.
*
* @param isikuKood the isiku kood
* @param asutus the asutus
* @param roll the roll
* @param token the token
*/
public AuthInfo(String isikuKood, String asutus, String roll, String token) {
this.user_code = isikuKood;
this.org_code = asutus;
this.role_code = roll;
this.token = token;
}
/**
* Convert 3rd party data to be suitable for rest api.
*
* @param authInfo3rdParty the auth info3rd party
*/
public AuthInfo(AuthInfo3rdParty authInfo3rdParty) {
this.user_code = authInfo3rdParty.getIsikuKood();
this.org_code = authInfo3rdParty.getAsutus();
this.role_code = authInfo3rdParty.getRoll();
this.token = authInfo3rdParty.getToken();
}
/**
* Gets the isiku kood.
*
* @return the isiku kood
*/
public String getUser_code() {
return user_code;
}
/**
* Sets the isiku kood.
*
* @param aUser_code the new user_code
*/
public void setUser_code(String aUser_code) {
user_code = aUser_code;
}
/**
* Gets the org_code.
*
* @return the org_code
*/
public String getOrg_code() {
return org_code;
}
/**
* Sets the org_code.
*
* @param aOrg_code the new org_code
*/
public void setOrg_code(String aOrg_code) {
org_code = aOrg_code;
}
/**
* Gets the role_code.
*
* @return the role_code
*/
public String getRole_code() {
return role_code;
}
/**
* Sets the role_code.
*
* @param aRole_code the new role_code
*/
public void setRole_code(String aRole_code) {
role_code = aRole_code;
}
/**
* Gets the token.
*
* @return the token
*/
public String getToken() {
return token;
}
/**
* Sets the token.
*
* @param aToken the new token
*/
public void setToken(String aToken) {
token = aToken;
}
/**
* Gets the user_name.
*
* @return the user_name
*/
public String getUser_name() {
return user_name;
}
/**
* Sets the user_name.
*
* @param user_name the new user_name
*/
public void setUser_name(String user_name) {
this.user_name = user_name;
}
/**
* Gets the org_name.
*
* @return the org_name
*/
public String getOrg_name() {
return org_name;
}
/**
* Sets the org_name.
*
* @param org_name the new org_name
*/
public void setOrg_name(String org_name) {
this.org_name = org_name;
}
/**
* Gets the role_name.
*
* @return the role_name
*/
public String getRole_name() {
return role_name;
}
/**
* Sets the role_name.
*
* @param role_name the new role_name
*/
public void setRole_name(String role_name) {
this.role_name = role_name;
}
/**
* Gets the role_right.
*
* @return the role_right
*/
public List<SimpleRoleRight> getRole_right() {
return role_right;
}
/**
* Sets the role_right.
*
* @param role_right the new role_right
*/
public void setRole_right(List<SimpleRoleRight> role_right) {
this.role_right = role_right;
}
public static class SimpleRoleRight {
private int create;
private int read;
private int update;
private int delete;
private int access_restriction;
private String kind;
public SimpleRoleRight(int create, int read, int update, int delete, int access_restriction, String kind) {
this.create = create;
this.read = read;
this.update = update;
this.delete = delete;
this.access_restriction = access_restriction;
this.kind = kind;
}
public SimpleRoleRight(Role_right role_right, String kindName) {
this(role_right.getCreate(), role_right.getRead(),
role_right.getUpdate(), role_right.getDelete(),
role_right.getAccess_restriction(), kindName);
}
public int getCreate() {
return create;
}
public int getRead() {
return read;
}
public int getUpdate() {
return update;
}
public int getDelete() {
return delete;
}
public int getAccess_restriction() {
return access_restriction;
}
public String getKind() {
return kind;
}
}
}
package ee.eesti.riha.rest.auth;
/**
* Authentication data that comes from 3rd party service
*
*/
public class AuthInfo3rdParty {
private String isikuKood;
private String asutus;
private String roll;
private String token;
/**
* Instantiates a new auth info.
*/
public AuthInfo3rdParty() {
}
/**
* Instantiates a new auth info.
*
* @param isikuKood the isiku kood
* @param asutus the asutus
* @param roll the roll
*/
public AuthInfo3rdParty(String isikuKood, String asutus, String roll) {
this.isikuKood = isikuKood;
this.asutus = asutus;
this.roll = roll;
}
/**
* Instantiates a new auth info.
*
* @param isikuKood the isiku kood
* @param asutus the asutus
* @param roll the roll
* @param token the token
*/
public AuthInfo3rdParty(String isikuKood, String asutus, String roll, String token) {
this.isikuKood = isikuKood;
this.asutus = asutus;
this.roll = roll;
this.token = token;
}
/**
* Gets the isiku kood.
*
* @return the isiku kood
*/
public String getIsikuKood() {
return isikuKood;
}
/**
* Sets the isiku kood.
*
* @param aIsikuKood the new isiku kood
*/
public void setIsikuKood(String aIsikuKood) {
isikuKood = aIsikuKood;
}
/**
* Gets the asutus.
*
* @return the asutus
*/
public String getAsutus() {
return asutus;
}
/**
* Sets the asutus.
*
* @param aAsutus the new asutus
*/
public void setAsutus(String aAsutus) {
asutus = aAsutus;
}
/**
* Gets the roll.
*
* @return the roll
*/
public String getRoll() {
return roll;
}
/**
* Sets the roll.
*
* @param aRoll the new roll
*/
public void setRoll(String aRoll) {
roll = aRoll;
}
/**
* Gets the token.
*
* @return the token
*/
public String getToken() {
return token;
}
/**
* Sets the token.
*
* @param aToken the new token
*/
public void setToken(String aToken) {
token = aToken;
}
}
package ee.eesti.riha.rest.auth;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
/**
* Service to connect to 3rd party authentication service
*
*/
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
public interface AuthService {
/**
* Checks if token is valid.
*
* @param sessionId the session id
* @return authenticated user if valid
*/
@GET
Object isValid(@QueryParam(value = "sessionId") String sessionId);
}
package ee.eesti.riha.rest.auth;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
// TODO: Auto-generated Javadoc
/**
* Fake implementation of AuthService for testing.
*/
@Component
public class AuthServiceImpl implements AuthService {
private static final Logger LOG = LoggerFactory.getLogger(AuthServiceImpl.class);
/**
* Instantiates a new auth service impl.
*/
public AuthServiceImpl() {
LOG.info("AUTH constructor");
}
/**
* Instantiates a new auth service impl.
*
* @param s the s
*/
public AuthServiceImpl(String s) {
LOG.info("AUTH constructor :: " + s);
}
/*
* (non-Javadoc)
*
* @see ee.eesti.riha.rest.auth.AuthService#isValid(java.lang.String)
*/
@Override
public Object isValid(String token) {
LOG.info("AUTH isValid called");
if (StringUtils.isEmpty(token)) {
return null;
}
// return new Object();
return new AuthInfo("35512121234", "Jaan Mets", "70000833", "test");
}
}
package ee.eesti.riha.rest.auth;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import ee.eesti.riha.rest.util.PropsReader;
// TODO: Auto-generated Javadoc
/**
* The Class AuthServiceProvider.
*/
public final class AuthServiceProvider {
// public static final String AUTH_SERVICE_URL = "http://localhost:1234";
public static final String AUTH_SERVICE_URL = PropsReader.get("AUTH_SERVICE_URL");
private static AuthServiceProvider instance = new AuthServiceProvider();
/**
* Instantiates a new auth service provider.
*/
private AuthServiceProvider() {
}
/**
* Gets the single instance of AuthServiceProvider.
*
* @return single instance of AuthServiceProvider
*/
public static AuthServiceProvider getInstance() {
return instance;
}
private AuthService authService;
/**
* Gets the.
*
* @param url the url
* @return the auth service
*/
private AuthService get(String url) {
if (authService == null) {
authService = create(url);
}
return authService;
}
/**
* Gets the.
*
* @return the auth service
*/
public