From b254147e749282209ffc625f4931e748a5e8be7c Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 5 May 2014 16:16:30 +0200 Subject: refectore AuthenticatedUser --- .../id/configuration/auth/AuthenticatedUser.java | 172 ++++++++++++--------- .../configuration/filter/AuthenticationFilter.java | 2 +- .../configuration/struts/action/IndexAction.java | 44 +----- 3 files changed, 106 insertions(+), 112 deletions(-) (limited to 'id') diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java index b7da86db7..330ed7036 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/auth/AuthenticatedUser.java @@ -24,6 +24,9 @@ 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 { @@ -39,27 +42,89 @@ public class AuthenticatedUser { private String institute; private String userName; private Date lastLogin; - - public AuthenticatedUser() { + + private boolean onlyBusinessService = false; + private String businessServiceType; + private String businessServiceNumber; + + private AuthenticatedUser() { } - public AuthenticatedUser(long userID, String givenName, String familyName, String institute, - String userName, boolean isAuthenticated, boolean isAdmin, boolean isMandateUser, + public static AuthenticatedUser generateDefaultUser() { + + 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(); + + return user; + } + + public static AuthenticatedUser generateUserRequestUser(UserDatabaseFrom form) { + + 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(); + + return user; + } + + public AuthenticatedUser(UserDatabase userdb, boolean isAuthenticated, boolean isMandateUser, boolean isPVP2Login) { - this.familyName = familyName; - this.givenName = givenName; - this.userName = userName; - this.userID = userID; - this.institute = institute; - this.isAdmin = isAdmin; + this.familyName = userdb.getFamilyname(); + this.givenName = userdb.getGivenname(); + this.userName = userdb.getUsername(); + this.userID = userdb.getHjid(); + this.institute = userdb.getInstitut(); + this.isAdmin = userdb.isIsAdmin(); this.isAuthenticated = isAuthenticated; this.isMandateUser = isMandateUser; this.isPVP2Login = isPVP2Login; this.lastLogin = new Date(); + + 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); } @@ -71,13 +136,6 @@ public class AuthenticatedUser { return isAuthenticated; } - /** - * @param isAuthenticated the isAuthenticated to set - */ - public void setAuthenticated(boolean isAuthenticated) { - this.isAuthenticated = isAuthenticated; - } - /** * @return the isAdmin */ @@ -85,13 +143,6 @@ public class AuthenticatedUser { return isAdmin; } - /** - * @param isAdmin the isAdmin to set - */ - public void setAdmin(boolean isAdmin) { - this.isAdmin = isAdmin; - } - /** * @return the userID */ @@ -99,13 +150,6 @@ public class AuthenticatedUser { return userID; } - /** - * @param userID the userID to set - */ - public void setUserID(long userID) { - this.userID = userID; - } - /** * @return the givenName */ @@ -113,13 +157,6 @@ public class AuthenticatedUser { return givenName; } - /** - * @param givenName the givenName to set - */ - public void setGivenName(String givenName) { - this.givenName = givenName; - } - /** * @return the familyName */ @@ -127,26 +164,12 @@ public class AuthenticatedUser { return familyName; } - /** - * @param familyName the familyName to set - */ - public void setFamilyName(String familyName) { - this.familyName = familyName; - } - /** * @return the lastLogin */ public Date getLastLogin() { return lastLogin; } - - /** - * @param lastLogin the lastLogin to set - */ - public void setLastLogin(Date lastLogin) { - this.lastLogin = lastLogin; - } /** * @return the userName @@ -156,54 +179,57 @@ public class AuthenticatedUser { } /** - * @param userName the userName to set + * @return the institute */ - public void setUserName(String userName) { - this.userName = userName; + public String getInstitute() { + return institute; } /** - * @return the institute + * @return the isPVP2Login */ - public String getInstitute() { - return institute; + public boolean isPVP2Login() { + return isPVP2Login; } /** - * @param institute the institute to set + * @return the isMandateUser */ - public void setInstitute(String institute) { - this.institute = institute; + public boolean isMandateUser() { + return isMandateUser; } /** - * @return the isPVP2Login + * @return the onlyBusinessService */ - public boolean isPVP2Login() { - return isPVP2Login; + public boolean isOnlyBusinessService() { + return onlyBusinessService; } /** - * @param isPVP2Login the isPVP2Login to set + * @return the businessServiceType */ - public void setPVP2Login(boolean isPVP2Login) { - this.isPVP2Login = isPVP2Login; + public String getBusinessServiceType() { + return businessServiceType; } /** - * @return the isMandateUser + * @return the businessServiceNumber */ - public boolean isMandateUser() { - return isMandateUser; + public String getBusinessServiceNumber() { + return businessServiceNumber; } /** - * @param isMandateUser the isMandateUser to set + * @param lastLogin the lastLogin to set */ - public void setMandateUser(boolean isMandateUser) { - this.isMandateUser = isMandateUser; + public void setLastLogin(Date lastLogin) { + this.lastLogin = lastLogin; } + + + } diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java index 0d52234bc..190773bf0 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/filter/AuthenticationFilter.java @@ -150,7 +150,7 @@ public class AuthenticationFilter implements Filter{ if (authuser == null) { - authuser = new AuthenticatedUser(0, "Max", "TestUser", null, "maxtestuser", true, true, false, false); + authuser = AuthenticatedUser.generateDefaultUser(); //authuser = new AuthenticatedUser(1, "Max", "TestUser", true, false); httpServletRequest.getSession().setAttribute(Constants.SESSION_AUTH, authuser); } diff --git a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java index d24fd114f..e019b70bb 100644 --- a/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java +++ b/id/ConfigWebTool/src/main/java/at/gv/egovernment/moa/id/configuration/struts/action/IndexAction.java @@ -77,8 +77,6 @@ import org.opensaml.xml.security.x509.X509Credential; import org.opensaml.xml.signature.Signature; import org.opensaml.xml.signature.impl.ExplicitKeySignatureTrustEngine; -import com.opensymphony.xwork2.ActionSupport; - import at.gv.egovernment.moa.id.commons.db.ConfigurationDBRead; import at.gv.egovernment.moa.id.commons.db.ConfigurationDBUtils; import at.gv.egovernment.moa.id.commons.db.dao.config.OnlineApplication; @@ -215,14 +213,8 @@ public class IndexAction extends BasicAction { if (dbuser.isIsMandateUser() != null) ismandateuser = dbuser.isIsMandateUser(); - AuthenticatedUser authuser = new AuthenticatedUser( - dbuser.getHjid(), - dbuser.getGivenname(), - dbuser.getFamilyname(), - dbuser.getInstitut(), - dbuser.getUsername(), + AuthenticatedUser authuser = new AuthenticatedUser(dbuser, true, - dbuser.isIsAdmin(), ismandateuser, false); @@ -424,16 +416,7 @@ public class IndexAction extends BasicAction { user.setIsusernamepasswordallowed(false); user.setIsmandateuser(false); user.setPVPGenerated(true); - - authUser = new AuthenticatedUser(); - authUser.setAdmin(false); - authUser.setAuthenticated(false); - authUser.setLastLogin(null); - authUser.setUserID(-1); - authUser.setUserName(null); - authUser.setPVP2Login(true); - authUser.setMandateUser(false); - + //loop through the nodes to get what we want List attributeStatements = saml2assertion.getAttributeStatements(); for (int i = 0; i < attributeStatements.size(); i++) @@ -445,26 +428,24 @@ public class IndexAction extends BasicAction { if (strAttributeName.equals(PVPConstants.PRINCIPAL_NAME_NAME)) { user.setFamilyName(attributes.get(x).getAttributeValues().get(0).getDOM().getTextContent()); - authUser.setFamilyName(user.getFamilyName()); } if (strAttributeName.equals(PVPConstants.GIVEN_NAME_NAME)) { user.setGivenName(attributes.get(x).getAttributeValues().get(0).getDOM().getTextContent()); - authUser.setGivenName(user.getGivenName()); } if (strAttributeName.equals(PVPConstants.MANDATE_TYPE_NAME)) { - authUser.setMandateUser(true); user.setIsmandateuser(true); } if (strAttributeName.equals(PVPConstants.MANDATE_LEG_PER_FULL_NAME_NAME)) { user.setInstitut(attributes.get(x).getAttributeValues().get(0).getDOM().getTextContent()); - authUser.setInstitute(user.getInstitut()); } } } + authUser = AuthenticatedUser.generateUserRequestUser(user); + //set Random value formID = Random.nextRandom(); session.setAttribute(Constants.SESSION_FORMID, formID); @@ -484,14 +465,8 @@ public class IndexAction extends BasicAction { session.setAttribute(Constants.SESSION_FORMID, formID); user = new UserDatabaseFrom(dbuser); - authUser = new AuthenticatedUser( - dbuser.getHjid(), - dbuser.getGivenname(), - dbuser.getFamilyname(), - dbuser.getInstitut(), - dbuser.getUsername(), + authUser = new AuthenticatedUser(dbuser, false, - false, dbuser.isIsMandateUser(), true); session.setAttribute(Constants.SESSION_FORM, user); @@ -511,14 +486,7 @@ public class IndexAction extends BasicAction { if (dbuser.isIsMandateUser() != null) ismandateuser = dbuser.isIsMandateUser(); - authUser = new AuthenticatedUser( - dbuser.getHjid(), - dbuser.getGivenname(), - dbuser.getFamilyname(), - dbuser.getInstitut(), - dbuser.getUsername(), - true, - dbuser.isIsAdmin(), + authUser = new AuthenticatedUser(dbuser, true, ismandateuser, true); -- cgit v1.2.3