1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 76 (76) |
Complexity: 26 |
Complexity Density: 0.54 |
|
34 |
|
public class GroovyAuthServiceImpl extends XWikiAuthServiceImpl |
35 |
|
{ |
36 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(GroovyAuthServiceImpl.class); |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 6 |
Complexity Density: 0.67 |
|
38 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 8 |
Complexity Density: 0.53 |
|
59 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
88 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
103 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
119 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
134 |
0 |
@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 |
|
} |