/******************************************************************************* * 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.commons.db.dao.session; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Lob; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.PreUpdate; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import org.hibernate.annotations.DynamicUpdate; @Entity @DynamicUpdate(value=true) @Table(name = "authenticatedsessionstore") @NamedQueries({ @NamedQuery(name="getSessionWithID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.sessionid = :sessionid"), @NamedQuery(name="getSessionWithSSOID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.SSOsessionid = :sessionid"), @NamedQuery(name="getSessionWithPendingRequestID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.pendingRequestID = :sessionid"), @NamedQuery(name="getMOAISessionsWithTimeOut", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore where authenticatedsessionstore.created < :timeoutcreate or authenticatedsessionstore.updated < :timeoutupdate"), @NamedQuery(name="getMOAISessionWithUserNameID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore join fetch authenticatedsessionstore.activeOAsessions activeOAsessions where activeOAsessions.userNameID = :usernameid and activeOAsessions.attributeQueryUsed is false"), @NamedQuery(name="getActiveOAWithSessionIDandOAIDandProtocol", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore join fetch authenticatedsessionstore.activeOAsessions activeOAsessions where activeOAsessions.oaurlprefix = :oaID and activeOAsessions.protocolType = :protocol and authenticatedsessionstore.sessionid = :sessionID"), @NamedQuery(name="getMOASessionWithNameIDandOAID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore join fetch authenticatedsessionstore.activeOAsessions activeOAsessions where activeOAsessions.oaurlprefix = :oaID and activeOAsessions.userNameID = :nameID"), @NamedQuery(name="getInterfederatedIDPForAttributeQueryWithSessionID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore join fetch authenticatedsessionstore.inderfederation inderfederations where inderfederations.attributesRequested is false and authenticatedsessionstore.sessionid = :sessionID"), @NamedQuery(name="getInterfederatedIDPForSSOWithSessionID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore join fetch authenticatedsessionstore.inderfederation inderfederations where inderfederations.attributesRequested is true and inderfederations.storeSSOInformation is true and authenticatedsessionstore.sessionid = :sessionID order by inderfederations.QAALevel DESC"), @NamedQuery(name="getInterfederatedIDPForSSOWithSessionIDIDPID", query = "select authenticatedsessionstore from AuthenticatedSessionStore authenticatedsessionstore join fetch authenticatedsessionstore.inderfederation inderfederations where inderfederations.attributesRequested is true and authenticatedsessionstore.sessionid = :sessionID and inderfederations.idpurlprefix = :idpID"), @NamedQuery(name="getAllActiveOAsForSessionID", query = "select activeOAsessions from AuthenticatedSessionStore authenticatedsessionstore join authenticatedsessionstore.activeOAsessions activeOAsessions where authenticatedsessionstore.sessionid = :sessionID "), @NamedQuery(name="getAllActiveIDPsForSessionID", query = "select inderfederation from AuthenticatedSessionStore authenticatedsessionstore join authenticatedsessionstore.inderfederation inderfederation where authenticatedsessionstore.sessionid = :sessionID ") }) public class AuthenticatedSessionStore implements Serializable{ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", unique=true, nullable=false) private long id; @Column(name = "sessionid", unique=true, nullable=false) private String sessionid; @Column(name = "SSOsessionid") private String SSOsessionid; @Column(name = "authSession", nullable=false) @Lob private byte [] authSession; @Column(name = "iv", nullable=true) @Lob private byte [] iv; @Column(name = "isAuthenticated", nullable=false) private boolean isAuthenticated = false; @Column(name = "isSSOSession", nullable=false) private boolean isSSOSession = false; @Column(name = "isInterfederatedSSOSession", nullable=false) private boolean isInterfederatedSSOSession = false; @Column(name = "pendingRequestID", nullable=true) private String pendingRequestID = ""; @Column(name = "additionalInformation", nullable=true) @Lob private String additionalInformation; @Column(name = "additionalInformationBytes", nullable=true) @Lob private byte[] additionalInformationBytes; @Column(name = "created", updatable=false, nullable=false) @Temporal(TemporalType.TIMESTAMP) private Date created; @Column(name = "updated") @Temporal(TemporalType.TIMESTAMP) private Date updated; @OneToMany(mappedBy="moasession", cascade=CascadeType.ALL) private List activeOAsessions = null; @OneToMany(mappedBy="moasession", cascade=CascadeType.ALL) private List oldssosessionids = null; @OneToMany(mappedBy="moasession", cascade=CascadeType.ALL, fetch=FetchType.EAGER) private List inderfederation = null; @PreUpdate protected void lastUpdate() { this.updated = new Date(); } public long getId() { return id; } public void setId(long id) { this.id = id; } /** * Get the internal ID of this MOASession * * @return moaSessionID, but never null */ public String getSessionid() { return sessionid; } /** * Set the internal ID of this MOASession. * * @param sessionid The internal ID of this MOASession, but never null **/ public void setSessionid(String sessionid) { this.sessionid = sessionid; } /** * Get the Single Sign-On SessionID of this MOASession * * @return SSO SessionID */ public String getSSOsessionid() { return SSOsessionid; } /** * Set the Single Sign-On SessionID for this MOASession * * @param sSOsessionid SSO SessionID */ public void setSSOsessionid(String sSOsessionid) { SSOsessionid = sSOsessionid; } /** * Get the serialized (and encrypted) AuthenticatedData DAO, which contains the user * identification and authentication information. * * @return serialized (and encryped) authenticationData, but never null */ public byte[] getSession() { return authSession; } /** * Set the AuthenticationData DAO, as serialized (and encrypted) blob.

* * This method should only be used, since MOASesion is not authenticated * this.isAuthenticated() == false. If the MOASession is already authenticated, * the corresponding user authentication data should not be changed any more. * * @param session the serialized (and encryped) authenticationData */ public void setSession(byte[] session) { this.authSession = session; } /** * Indicates this MOASession is already authenticated.

* * A authenticated MOASession contains all information, which are * needed build protocol specific authentication information. * Therefore, a user has already performed a full identification and * authentication process. * * @return true, if this MOASession is authenticated, otherwise false */ public boolean isAuthenticated() { return isAuthenticated; } /** * Mark a MOASession as authenticated.

* * A MOASession had to be marked as authenticated, if the user * identification and authentication process is completed. * * @param isAuthenticated */ public void setAuthenticated(boolean isAuthenticated) { this.isAuthenticated = isAuthenticated; } /** * Indicates this MOASession as a Single Sign-On session * * @return true if it is a SSO session, otherwise false */ public boolean isSSOSession() { return isSSOSession; } /** * Mark this MOASession as a Single Sign-On session * * @param isSSOSession true, if this MOASession is a SSO session, otherwise false */ public void setSSOSession(boolean isSSOSession) { this.isSSOSession = isSSOSession; } /** * Get a timestamp when this MOASession was created * * @return timestamp */ public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } /** * Get a timestamp, when this MOASession was updated last time * * @return timestamp */ public Date getUpdated() { return updated; } public void setUpdated(Date updated) { this.updated = updated; } /** * Get a List of Service Providers, which has received a authentication information by using * Single Sign-On * * @return */ public List getActiveOAsessions() { return activeOAsessions; } public void setActiveOAsessions(List activeOAsessions) { if (activeOAsessions == null) { this.activeOAsessions = new ArrayList(); } this.activeOAsessions = activeOAsessions; } /** * Get a List of old Single Sign-On SessionIDs, which are already used for this MOASession. * Every SSO SessionID can only be used once. * * @return */ public List getOldssosessionids() { return oldssosessionids; } public void setOldssosessionids(List oldssosessionids) { this.oldssosessionids = oldssosessionids; } /** * Get a List of federated IDPs which are already used in this Session * * @return the inderfederation */ public List getInderfederation() { return inderfederation; } /** * @param inderfederation the inderfederation to set */ public void setInderfederation(List inderfederation) { this.inderfederation = inderfederation; } /** * Get the initial vector for AuthenticationData encryption * * @return the iv */ public byte[] getIv() { return iv; } /** * Set the inital vector for AuthenticationData encryption * * @param iv the iv to set */ public void setIv(byte[] iv) { this.iv = iv; } /** * Indicates this MOASession as an federated session * * @return true if it is a federated session, otherwise false */ public boolean isInterfederatedSSOSession() { return isInterfederatedSSOSession; } /** * Mark this MOASession as an federated session * * @param isInterfederatedSSOSession true, if this MOASession is a federated session */ public void setInterfederatedSSOSession(boolean isInterfederatedSSOSession) { this.isInterfederatedSSOSession = isInterfederatedSSOSession; } @Deprecated public String getAdditionalInformation() { return additionalInformation; } @Deprecated public void setAdditionalInformation(String additionalInformation) { this.additionalInformation = additionalInformation; } public byte[] getAdditionalInformationBytes() { return additionalInformationBytes; } public void setAdditionalInformationBytes(byte[] additionalInformationBytes) { this.additionalInformationBytes = additionalInformationBytes; } // /** // * @return the additionalInformation // */ // @Deprecated // public String getAdditionalInformation() { // try { // if (this.additionalInformationBytes != null) // return new String(this.additionalInformationBytes, "UTF-8"); // else // return null; // // } catch (UnsupportedEncodingException e) { // throw new RuntimeException("Something is very strange, because UTF-8 encoding IS NOT supported", e); // // } // } // @Deprecated // public void setAdditionalInformation(String additionalInformation) { // try { // if (StringUtils.isNotEmpty(additionalInformation)) // this.additionalInformationBytes = additionalInformation.getBytes("UTF-8"); // // } catch (UnsupportedEncodingException e) { // throw new RuntimeException("Something is very strange, because UTF-8 encoding IS NOT supported", e); // // } // } }