/******************************************************************************* * Copyright 2014 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * 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.gv.egovernment.moa.id.configuration.auth; import java.util.Date; import at.gv.egovernment.moa.id.commons.db.dao.config.UserDatabase; import at.gv.egovernment.moa.id.configuration.Constants; import at.gv.egovernment.moa.id.configuration.data.UserDatabaseFrom; import at.gv.egovernment.moa.id.configuration.helper.DateTimeHelper; public class AuthenticatedUser { private boolean isAuthenticated = false; private boolean isAdmin = false; private boolean isPVP2Login = false; private boolean isMandateUser = false; private long userID; private String givenName; private String familyName; private String institute; private String userName; private Date lastLogin; private Date sessionExpired; private boolean onlyBusinessService = false; private String businessServiceType; private String businessServiceNumber; private String nameID = null; private String nameIDFormat = null; private AuthenticatedUser() { } public static AuthenticatedUser generateDefaultUser(Date sessionExpired) { AuthenticatedUser user = new AuthenticatedUser(); user.familyName = "TestUser"; user.givenName = "Max"; user.userName = "maxtestuser"; user.userID = 0; user.institute = new String(); user.isAdmin = true; user.isAuthenticated = true; user.isMandateUser = false; user.isPVP2Login = false; user.lastLogin = new Date(); user.sessionExpired = sessionExpired; return user; } public static AuthenticatedUser generateUserRequestUser(UserDatabaseFrom form, String nameID, String nameIDFormat, Date sessionExpired) { AuthenticatedUser user = new AuthenticatedUser(); user.familyName = form.getFamilyName(); user.givenName = form.getGivenName(); user.userName = form.getUsername(); user.userID = 0; user.institute = form.getInstitut(); user.isAdmin = false; user.isAuthenticated = false; user.isMandateUser = form.isIsmandateuser(); user.isPVP2Login = form.isPVPGenerated(); user.lastLogin = new Date(); user.sessionExpired = sessionExpired; user.nameID = nameID; user.nameIDFormat = nameIDFormat; return user; } public AuthenticatedUser(UserDatabase userdb, boolean isAuthenticated, boolean isMandateUser, boolean isPVP2Login, String nameID, String nameIDFormat, Date sessionExpired) { this.familyName = userdb.getFamilyname(); this.givenName = userdb.getGivenname(); this.userName = userdb.getUsername(); this.userID = Long.valueOf(userdb.getHjid()); this.institute = userdb.getInstitut(); this.isAdmin = userdb.isIsAdmin(); this.isAuthenticated = isAuthenticated; this.isMandateUser = isMandateUser; this.isPVP2Login = isPVP2Login; this.lastLogin = new Date(); this.sessionExpired = sessionExpired; this.nameID = nameID; this.nameIDFormat = nameIDFormat; if (!this.isAdmin) generateUserSpecificConfigurationOptions(userdb); } private void generateUserSpecificConfigurationOptions(UserDatabase userdb) { if (userdb.isIsMandateUser() != null && userdb.isIsMandateUser()) { String bpk = userdb.getBpk(); if (bpk.startsWith(Constants.IDENIFICATIONTYPE_BASEID_FN) || bpk.startsWith(Constants.IDENIFICATIONTYPE_BASEID_ZVR) || bpk.startsWith(Constants.IDENIFICATIONTYPE_STORK)) { onlyBusinessService = true; String[] split = bpk.split("\\+"); this.businessServiceType = split[1].substring(1); if (bpk.startsWith(Constants.IDENIFICATIONTYPE_BASEID_FN)) this.businessServiceNumber = at.gv.egovernment.moa.util.StringUtils.deleteLeadingZeros(split[2]); else this.businessServiceNumber = split[2]; } else onlyBusinessService = false; } } public String getFormatedLastLogin() { return DateTimeHelper.getDateTime(lastLogin); } /** * @return the isAuthenticated */ public boolean isAuthenticated() { return isAuthenticated; } /** * @return the isAdmin */ public boolean isAdmin() { return isAdmin; } /** * @return the userID */ public long getUserID() { return userID; } /** * @return the givenName */ public String getGivenName() { return givenName; } /** * @return the familyName */ public String getFamilyName() { return familyName; } /** * @return the lastLogin */ public Date getLastLogin() { return lastLogin; } /** * @return the userName */ public String getUserName() { return userName; } /** * @return the institute */ public String getInstitute() { return institute; } /** * @return the isPVP2Login */ public boolean isPVP2Login() { return isPVP2Login; } /** * @return the isMandateUser */ public boolean isMandateUser() { return isMandateUser; } /** * @return the onlyBusinessService */ public boolean isOnlyBusinessService() { return onlyBusinessService; } /** * @return the businessServiceType */ public String getBusinessServiceType() { return businessServiceType; } /** * @return the businessServiceNumber */ public String getBusinessServiceNumber() { return businessServiceNumber; } /** * @param lastLogin the lastLogin to set */ public void setLastLogin(Date lastLogin) { this.lastLogin = lastLogin; } /** * @return the nameID */ public String getNameID() { return nameID; } /** * @return the nameIDFormat */ public String getNameIDFormat() { return nameIDFormat; } /** * @return the sessionExpired */ public Date getSessionExpired() { return sessionExpired; } }