1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.user.impl.xwiki

File GroovyAuthServiceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

22
48
6
1
148
118
26
0.54
8
6
4.33

Classes

Class Line # Actions
GroovyAuthServiceImpl 34 48 0% 26 76
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.user.impl.xwiki;
21   
22    import java.security.Principal;
23   
24    import org.apache.commons.lang3.StringUtils;
25    import org.slf4j.Logger;
26    import org.slf4j.LoggerFactory;
27   
28    import com.xpn.xwiki.XWikiContext;
29    import com.xpn.xwiki.XWikiException;
30    import com.xpn.xwiki.doc.XWikiDocument;
31    import com.xpn.xwiki.user.api.XWikiAuthService;
32    import com.xpn.xwiki.user.api.XWikiUser;
33   
 
34    public class GroovyAuthServiceImpl extends XWikiAuthServiceImpl
35    {
36    private static final Logger LOGGER = LoggerFactory.getLogger(GroovyAuthServiceImpl.class);
37   
 
38  0 toggle @Override
39    protected String getParam(String name, XWikiContext context)
40    {
41  0 String param = "";
42  0 try {
43  0 param = context.getWiki().getXWikiPreference(name, context);
44    } catch (Exception e) {
45    }
46  0 if (param == null || "".equals(param)) {
47  0 try {
48  0 param =
49    context.getWiki().Param("xwiki.authentication." + StringUtils.replace(name, "groovy_", "groovy."));
50    } catch (Exception e) {
51    }
52    }
53  0 if (param == null) {
54  0 param = "";
55    }
56  0 return param;
57    }
58   
 
59  0 toggle public XWikiAuthService getAuthService(XWikiContext context)
60    {
61  0 String authservicepage = getParam("groovy_pagename", context);
62  0 if ((authservicepage == null) || authservicepage.trim().equals("")) {
63  0 if (LOGGER.isErrorEnabled()) {
64  0 LOGGER.error("No page specified for auth service implementation");
65    }
66  0 return null;
67    }
68   
69  0 try {
70  0 XWikiDocument doc = context.getWiki().getDocument(authservicepage, context);
71  0 if (context.getWiki().getRightService().hasProgrammingRights(doc, context)) {
72  0 return (XWikiAuthService) context.getWiki().parseGroovyFromString(doc.getContent(), context);
73    } else {
74  0 if (LOGGER.isErrorEnabled()) {
75  0 LOGGER.error("Auth service implementation page " + authservicepage
76    + " missing programming rights, requires ownership by authorized user.");
77    }
78  0 return null;
79    }
80    } catch (XWikiException e) {
81  0 if (LOGGER.isErrorEnabled()) {
82  0 LOGGER.error("Exception while parsing groovy authentication service code", e);
83    }
84  0 return null;
85    }
86    }
87   
 
88  0 toggle @Override
89    public XWikiUser checkAuth(XWikiContext context) throws XWikiException
90    {
91  0 XWikiAuthService authservice = getAuthService(context);
92  0 if (authservice == null) {
93  0 return super.checkAuth(context);
94    } else {
95  0 try {
96  0 return authservice.checkAuth(context);
97    } catch (Exception e) {
98  0 return super.checkAuth(context);
99    }
100    }
101    }
102   
 
103  0 toggle @Override
104    public XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context)
105    throws XWikiException
106    {
107  0 XWikiAuthService authservice = getAuthService(context);
108  0 if (authservice == null) {
109  0 return super.checkAuth(username, password, rememberme, context);
110    } else {
111  0 try {
112  0 return authservice.checkAuth(username, password, rememberme, context);
113    } catch (Exception e) {
114  0 return super.checkAuth(username, password, rememberme, context);
115    }
116    }
117    }
118   
 
119  0 toggle @Override
120    public void showLogin(XWikiContext context) throws XWikiException
121    {
122  0 XWikiAuthService authservice = getAuthService(context);
123  0 if (authservice == null) {
124  0 super.showLogin(context);
125    } else {
126  0 try {
127  0 authservice.showLogin(context);
128    } catch (Exception e) {
129  0 super.showLogin(context);
130    }
131    }
132    }
133   
 
134  0 toggle @Override
135    public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException
136    {
137  0 XWikiAuthService authservice = getAuthService(context);
138  0 if (authservice == null) {
139  0 return super.authenticate(username, password, context);
140    } else {
141  0 try {
142  0 return authservice.authenticate(username, password, context);
143    } catch (Exception e) {
144  0 return super.authenticate(username, password, context);
145    }
146    }
147    }
148    }