View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
17   *
18   * $Id: MoriaAuthnAttempt.java,v 1.10 2004/12/15 20:51:31 jk Exp $
19   */
20  
21  package no.feide.moria.store;
22  
23  import java.util.HashMap;
24  
25  /***
26   * This class is used for holding state through an authentication. From
27   * initialization by the service through to final retrieval of user data.
28   *
29   * @author Bjørn Ola Smievoll <b.o@smievoll.no>
30   * @version $Revision: 1.10 $
31   */
32  public final class MoriaAuthnAttempt implements MoriaStoreData {
33  
34      /***
35       * The inital attributes requested by the initiating service.
36       */
37      private final String[] requestedAttributes;
38  
39      /***
40       * The initial part of the url the user is to be redirected to.
41       */
42      private final String returnURLPrefix;
43  
44      /***
45       * The final part of the url the user is to be redirected to.
46       */
47      private final String returnURLPostfix;
48  
49      /***
50       * Whether or not single sign-on (SSO) is to be used when user arrives
51       * at login servlet.
52       */
53      private final boolean forceInterativeAuthentication;
54  
55      /***
56       * Transient attributes returned from a directory that are not to be cached.
57       */
58      private HashMap transientAttributes;
59  
60      /***
61       * Principal for the client that requests the authentication attempt.
62       */
63      private final String servicePrincipal;
64  
65      /***
66       * Constructs an instance. Usually based on data given in an initial request
67       * by a remote service.
68       *
69       * @param requestedAttributes
70       *          the attributes the remote service requires
71       * @param returnURLPrefix
72       *          the initial part of the url the user is to be redirected to
73       * @param returnURLPostfix
74       *          the final part of the url the user is to be redirected to. May be null
75       * @param forceInteractiveAuthentication
76       *          whether or not SSO is to be used
77       * @param servicePrincipal
78       *          the name of the service initiating this authentication attempt.
79       */
80      public MoriaAuthnAttempt(final String[] requestedAttributes, final String returnURLPrefix, final String returnURLPostfix,
81              final boolean forceInteractiveAuthentication, final String servicePrincipal) {
82          this.requestedAttributes = requestedAttributes;
83          this.returnURLPrefix = returnURLPrefix;
84          this.returnURLPostfix = returnURLPostfix;
85          this.forceInterativeAuthentication = forceInteractiveAuthentication;
86          this.servicePrincipal = servicePrincipal;
87      }
88  
89      /***
90       * Gets the string array containing the requested attributes.
91       *
92       * @return The attributes requested by the invoking service.
93       */
94      public String[] getRequestedAttributes() {
95          return (String[]) requestedAttributes.clone();
96      }
97  
98      /***
99       * Gets the transient attributes.
100      *
101      * @return The short-lived user attributes.
102      */
103     public HashMap getTransientAttributes() {
104         return (HashMap) transientAttributes.clone();
105     }
106 
107     /***
108      * Sets the user data that have been retrieved from a directory for this
109      * authentication attempt.
110      *
111      * @param transientAttributes The short-lived user attributes.
112      */
113     void setTransientAttributes(final HashMap transientAttributes) {
114         this.transientAttributes = transientAttributes;
115     }
116 
117     /***
118      * Gets the initial part of the return url.
119      *
120      * @return The return url prefix.
121      */
122     public String getReturnURLPrefix() {
123         return returnURLPrefix;
124     }
125 
126     /***
127      * Gets the end part of the return url.
128      *
129      * @return The return url postfix.
130      */
131     public String getReturnURLPostfix() {
132         return returnURLPostfix;
133     }
134 
135     /***
136      * Gets the servicePrincipal.
137      *
138      * @return The service principal name.
139      */
140     public String getServicePrincipal() {
141         return servicePrincipal;
142     }
143 
144     /***
145      * Checks whether or not single sign-on (SSO) should be refused even if
146      * possible.
147      *
148      * @return True for forced authentication.
149      */
150     public boolean isForceInterativeAuthentication() {
151         return forceInterativeAuthentication;
152     }
153 }