From e443168b481bb88fecbad73084147e7e8c882908 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Tue, 10 Dec 2019 07:39:27 +0100 Subject: refactoring to new EGIZ code requirements --- .../auth/eidas/v2/dao/EidasPersonalIdStoreDao.java | 158 +++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/EidasPersonalIdStoreDao.java (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/EidasPersonalIdStoreDao.java') diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/EidasPersonalIdStoreDao.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/EidasPersonalIdStoreDao.java new file mode 100644 index 00000000..c7acdb15 --- /dev/null +++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/dao/EidasPersonalIdStoreDao.java @@ -0,0 +1,158 @@ +/* + * Copyright 2018 A-SIT Plus GmbH + * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ, + * A-SIT Plus GmbH, A-SIT, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "License"); + * You may not use this work except in compliance with the License. + * You may obtain a copy of the License at: + * https://joinup.ec.europa.eu/news/understanding-eupl-v12 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ + +package at.asitplus.eidas.specific.modules.auth.eidas.v2.dao; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import at.gv.egiz.eaaf.core.impl.data.Pair; + +@Deprecated +public class EidasPersonalIdStoreDao { + public static final String NAME = "foreigneIDMap"; + + // Enum with all cols of this table + public enum Cols { + timestamp, transactionId, eidasId, eidasSourceCountry, eidasDestinationCountry, ernbId + } + + public enum T { + ID("INTEGER"), + BIGINT("VARCHAR(265)"), + URI("VARCHAR(256)"), + DATE("Long"), + TEXT("TEXT"), + Long("BIGINT"), + Int("INTEGER"), + BLOB("BLOB"), + CC("CHAR(2)"), + BOOL("INTEGER"); + + private final String type; + + T(String el) { + type = el; + } + + @Override + public String toString() { + return type; + } + } + + // define Cols of the table + public static final List> TABLE_COLS; + + static { + final List> cols = new ArrayList<>(); + cols.add(Pair.newInstance(Cols.timestamp.name(), T.DATE)); + cols.add(Pair.newInstance(Cols.transactionId.name(), T.TEXT)); + cols.add(Pair.newInstance(Cols.eidasId.name(), T.TEXT)); + cols.add(Pair.newInstance(Cols.eidasSourceCountry.name(), T.CC)); + cols.add(Pair.newInstance(Cols.eidasDestinationCountry.name(), T.CC)); + cols.add(Pair.newInstance(Cols.ernbId.name(), T.TEXT)); + + TABLE_COLS = Collections.unmodifiableList(cols); + + } + + public static final String CREATE = "CREATE TABLE " + NAME + + " (" + "id" + " " + T.ID.toString() + + " PRIMARY KEY AUTOINCREMENT, " + buildCreateTableQuery(TABLE_COLS) + ")"; + + public static final String INSERT = "INSERT INTO " + NAME + + "(" + buildInsertQueryKeys(TABLE_COLS) + ")" + + " VALUES (" + buildInsertQueryValues(TABLE_COLS) + ");"; + + public static final String SELECT_BY_ERNB_ID = "SELECT * FROM " + NAME + + " WHERE " + Cols.ernbId.name() + "=?;"; + + public static final String SELECT_BY_EIDAS_RAW_ID = "SELECT * FROM " + NAME + + " WHERE " + Cols.eidasId.name() + "=?" + + " and " + Cols.eidasSourceCountry.name() + "=?" + ";"; + + /** + * Build a part of a SQL query, which contains the cols of a table that should + * be created. + * + * @param cols List of DB col definitions {@link Pair} + * @return Part of a SQL query, which contains cols that should be created + */ + private static String buildCreateTableQuery(List> cols) { + StringBuffer buf = new StringBuffer(); + for (final Pair el : cols) { + buf.append(el.getFirst()); + buf.append(" "); + buf.append(el.getSecond()); + buf.append(","); + + } + String sql = buf.toString(); + return sql.substring(0, sql.length() - 1); + + } + + /** + * Build a part of a SQL query, which contains the cols keys of a table for + * insert operation. + * + * @param cols List of DB col definitions {@link Pair} + * @return Part of a SQL query, which contains cols that should be created + */ + protected static String buildInsertQueryKeys(List> cols) { + + StringBuffer buf = new StringBuffer(); + for (final Pair el : cols) { + buf.append(el.getFirst()); + buf.append(","); + + } + String sql = buf.toString(); + return sql.substring(0, sql.length() - 1); + } + + /** + * Build a part of a SQL query, which contains the cols values of a table for + * insert operation. + * + * @param cols List of DB col definitions {@link Pair} + * @return Part of a SQL query, which contains cols that should be created + */ + protected static String buildInsertQueryValues(List> cols) { + + StringBuffer buf = new StringBuffer(); + Iterator> it = cols.iterator(); + while (it.hasNext()) { + buf.append("?,"); + it.next(); + + } + + String sql = buf.toString(); + return sql.substring(0, sql.length() - 1); + } + +} -- cgit v1.2.3