Commit df6998e1 authored by Valentin Suhnjov's avatar Valentin Suhnjov

RIHAKB-130. Remove authentication classes

parent 882ead99
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;
}
/**
* 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;
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 AuthService get() {
return get(AUTH_SERVICE_URL);
// use fake
// return get(null);
}
/**
* Sets the.
*
* @param aAuthService the auth service
*/
public void set(AuthService aAuthService) {
this.authService = aAuthService;
}
/**
* Creates the.
*
* @param url the url
* @return the auth service
*/
private static AuthService create(String url) {
if (StringUtils.isEmpty(url)) {
return new AuthServiceImpl();
} else {
return JAXRSClientFactory.create(url, AuthService.class);
}
}
}
......@@ -28,17 +28,6 @@ public class SecureApiGenericDAOImpl<T, K> implements SecureApiGenericDAO<T, K>
private static final Logger LOG = LoggerFactory.getLogger(SecureApiGenericDAOImpl.class);
// LOGIC
// get Main_resource if Main_resource or by main_resource_id if other table
// get kindId from main_resource
// get access restriction from main_resource
// get access restrictions from parent main_resources
// get max access restriction
// get Role_rights: DEFAULT, AUTHENTICATED, authInfo.getRoll()
// filter Role_rights by kindId && accessRestriction
// calculate Role_right from role_Rights
// call canCreate(<Calculated Role_right>, <AuthInfo>, <Main_resource owner>}
@Override
public List<T> find(Class<T> clazz, Integer limit, Integer offset, List<FilterComponent> filterComponents,
String sort) throws RihaRestException {
......
......@@ -6,7 +6,6 @@ import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;
import ee.eesti.riha.rest.auth.AuthServiceImpl;
import ee.eesti.riha.rest.logic.Finals;
import ee.eesti.riha.rest.service.ApiCGIService;
import ee.eesti.riha.rest.service.ApiClassicService;
......
package ee.eesti.riha.rest.auth;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.TestHelper;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*: **/test-applicationContext.xml")
public class Test3rdPartyAuthService {
AuthServiceProvider authServiceProvider = AuthServiceProvider.getInstance();
@Test
public void testResponseHasNotChanged() throws IOException {
AuthService authService = authServiceProvider.get();
String sessionId = "123asd";
InputStream is = (InputStream) authService.isValid(sessionId);
JsonObject jsonObj = TestHelper.getObjectFromClient(is, JsonObject.class);
assertNotNull(jsonObj);
System.out.println(jsonObj);
assertTrue(jsonObj.has("isikuKood"));
assertTrue(jsonObj.has("roll"));
assertTrue(jsonObj.has("asutus"));
Set<Entry<String, JsonElement>> entries = jsonObj.entrySet();
assertEquals(3, entries.size());
}
}
......@@ -17,7 +17,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.google.gson.JsonObject;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.error.RihaRestException;
import ee.eesti.riha.rest.integration.TestFinals;
import ee.eesti.riha.rest.logic.util.JsonHelper;
......@@ -41,10 +40,6 @@ public class TestSecureApiGenericDAO<T, K> {
@Autowired
UtilitiesDAO<T> utilitiesDAO;
AuthInfo authInfo = new AuthInfo("123", "ORG", "ADMIN", "asd123123");
AuthInfo superAuthInfo = new AuthInfo("123", "ORG", "ROLL_RIHA_ADMINISTRAATOR", "asd123123");
AuthInfo betterAuthInfo = new AuthInfo("123", "ORG", "ROLL_RIHA_HALDUR", "asd123123");
private static final String INFOSYSTEM = "infosystem";
static Integer infosystemId = null;
......
......@@ -26,7 +26,6 @@ import com.google.gson.JsonObject;
import ee.eesti.riha.rest.MyTestRunner;
import ee.eesti.riha.rest.TestHelper;
import ee.eesti.riha.rest.auth.AuthServiceImpl;
import ee.eesti.riha.rest.error.ErrorCodes;
import ee.eesti.riha.rest.error.RihaRestError;
import ee.eesti.riha.rest.integration.IntegrationTestHelper;
......
......@@ -23,9 +23,7 @@ import com.google.gson.reflect.TypeToken;
import ee.eesti.riha.rest.MyTestRunner;
import ee.eesti.riha.rest.TestHelper;
import ee.eesti.riha.rest.auth.AuthServiceImpl;
import ee.eesti.riha.rest.dao.KindRepository;
import ee.eesti.riha.rest.dao.TestApiGenericDAOMain_resource;
import ee.eesti.riha.rest.error.ErrorCodes;
import ee.eesti.riha.rest.error.PartialError;
import ee.eesti.riha.rest.error.RihaRestError;
......
......@@ -9,7 +9,6 @@ import org.springframework.test.annotation.Timed;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import ee.eesti.riha.rest.auth.AuthInfo;
import ee.eesti.riha.rest.dao.SecureApiGenericDAO;
import ee.eesti.riha.rest.model.Main_resource;
......@@ -29,9 +28,6 @@ public class TestCount {
@Autowired
SecureApiGenericDAO<Main_resource, Integer> secureDao; // FIXME remove excess templating
@Autowired
AuthInfo authInfo;
@Test
@Timed(millis = 500)
public void test() throws Exception {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment