View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.business.accesscontrol;
35  
36  import java.io.Serializable;
37  import java.util.HashMap;
38  import java.util.Map;
39  
40  public class AccessControlSessionData implements Serializable
41  {
42      private static final long serialVersionUID = 6559917546035608330L;
43  
44      private static final String SESSION_KEY = "access_control_data";
45  
46      private final int _nIdResource;
47      private final String _strTypeResource;
48      private String _strReturnQueryString;
49      private boolean _bAccessControlResult;
50      private Map<Integer, Serializable> _persistentData = new HashMap<>( );
51  
52      
53      /**
54       * Constructor
55       * @param nIdResource
56       * @param strTypeResource
57       */
58      public AccessControlSessionData( int nIdResource, String strTypeResource )
59      {
60          _nIdResource = nIdResource;
61          _strTypeResource = strTypeResource;
62      }
63  
64      /**
65       * @return the strReturnQueryString
66       */
67      public String getReturnQueryString( )
68      {
69          return _strReturnQueryString;
70      }
71  
72      /**
73       * @param strReturnQueryString
74       *            the strReturnQueryString to set
75       */
76      public void setReturnQueryString( String strReturnQueryString )
77      {
78          _strReturnQueryString = strReturnQueryString;
79      }
80  
81      /**
82       * @return the bAccessControlResult
83       */
84      public boolean isAccessControlResult( )
85      {
86          return _bAccessControlResult;
87      }
88  
89      /**
90       * @param bAccessControlResult
91       *            the bAccessControlResult to set
92       */
93      public void setAccessControlResult( boolean bAccessControlResult )
94      {
95          _bAccessControlResult = bAccessControlResult;
96      }
97      
98      /**
99       * Add param to persistent data map.
100      * @param key the id of the controller that handles the persistent data
101      * @param value
102      */
103     public void addPersistentParam( int key, Serializable value )
104     {
105         _persistentData.put( key, value );
106     }
107     
108     /**
109      * Get persistent data
110      * @return
111      */
112     public Map<Integer, Serializable> getPersistentData( )
113     {
114         return _persistentData;
115     }
116 
117     /**
118      * @return the nIdResource
119      */
120     public int getIdResource( )
121     {
122         return _nIdResource;
123     }
124 
125     /**
126      * @return the strTypeResource
127      */
128     public String getTypeResource( )
129     {
130         return _strTypeResource;
131     }
132     
133     /**
134      * Get the session key for this ession data
135      * @return
136      */
137     public String getSessionKey( )
138     {
139         return getSessionKey( _nIdResource, _strTypeResource );
140     }
141     
142     /**
143      * Get the session key for the given parameters
144      * @param nIdResource
145      * @param strResourceType
146      * @return
147      */
148     public static final String getSessionKey( int nIdResource, String strResourceType )
149     {
150         return SESSION_KEY + "_" + nIdResource + "_" + strResourceType;
151     }
152 }