1   /*
2    * Copyright 2000-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.wsrp4j.util;
18  
19  import javax.portlet.PortletRequest;
20  
21  public class AuthenticationInfoHelper {
22      /**
23       * No authentication was done
24       **/
25      public static final String WSRP_NONE = "wsrp:none";
26  
27      /**
28       * End-User identified themselves using password/username scenario
29       **/
30      public static final String WSRP_PASSWD = "wsrp:password";
31  
32      /**
33       * End-User presented a security certificate
34       **/
35      public static final String WSRP_CERT = "wsrp:certificate";
36  
37      /**
38       * Get a string representation of the user authentification
39       * as defined in the WSRP spec. from a passed authentification
40       * info defined in the portlet spec. If the passed value could not
41       * be matched the same string is returned. 
42       * 
43       * @param jsrAuthInfo Authentification info as defined in the portlet spec
44       * @return The authentification info as defined in the WSRP spec. or the
45       *          argument if no match could be made.
46       **/
47      public static String getWsrpFromPortlet(String jsrAuthInfo) {
48          if (jsrAuthInfo == null) {
49              return WSRP_NONE;
50          }
51          else if (jsrAuthInfo == PortletRequest.BASIC_AUTH
52                  || jsrAuthInfo == PortletRequest.FORM_AUTH
53                  || jsrAuthInfo.equals(PortletRequest.BASIC_AUTH)
54                  || jsrAuthInfo.equals(PortletRequest.FORM_AUTH)) {
55              return WSRP_PASSWD;
56  
57          }
58          else if (jsrAuthInfo == PortletRequest.CLIENT_CERT_AUTH
59                  || jsrAuthInfo.equals(PortletRequest.CLIENT_CERT_AUTH)) {
60  
61              return WSRP_CERT;
62  
63          }
64          else {
65  
66              return jsrAuthInfo;
67          }
68      }
69  
70      /**
71       * Get the authentification info as defined in the portlet spec
72       * from a passed authentification info defined in the WSRP spec..
73       * If wsrp:none is passed <code>null</code> is returned. In case the
74       * passed info could not be matched the same string is returned.
75       * 
76       * @param wsrpInfo
77       * @return     
78       **/
79      public static String getPortletFromWsrp(String wsrpInfo) {
80          if (wsrpInfo.equals(WSRP_PASSWD)) {
81              return PortletRequest.FORM_AUTH;
82  
83          }
84          else if (wsrpInfo.equals(WSRP_CERT)) {
85              return PortletRequest.CLIENT_CERT_AUTH;
86  
87          }
88          else if (wsrpInfo.equals(WSRP_NONE)) {
89  
90              return null;
91  
92          }
93          else {
94  
95              return wsrpInfo;
96          }
97      }
98  }