1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal; |
21 |
|
|
22 |
|
import java.security.Principal; |
23 |
|
import java.util.logging.Level; |
24 |
|
|
25 |
|
import org.restlet.Context; |
26 |
|
import org.restlet.security.SecretVerifier; |
27 |
|
import org.xwiki.component.manager.ComponentManager; |
28 |
|
|
29 |
|
import com.xpn.xwiki.XWiki; |
30 |
|
import com.xpn.xwiki.XWikiContext; |
31 |
|
import com.xpn.xwiki.XWikiException; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 15% |
Uncovered Elements: 17 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
39 |
|
public class XWikiSecretVerifier extends SecretVerifier |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private ComponentManager componentManager; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
private Context context; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
@param |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
58 |
18 |
public XWikiSecretVerifier(Context context, ComponentManager manager)... |
59 |
|
{ |
60 |
18 |
this.context = context; |
61 |
18 |
this.componentManager = manager; |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.33 |
|
64 |
0 |
@Override... |
65 |
|
public boolean verify(String identifier, char[] secret) throws IllegalArgumentException |
66 |
|
{ |
67 |
0 |
XWikiContext xwikiContext = Utils.getXWikiContext(this.componentManager); |
68 |
0 |
XWiki xwiki = Utils.getXWiki(this.componentManager); |
69 |
|
|
70 |
0 |
try { |
71 |
0 |
Principal principal = (secret == null) ? null : xwiki.getAuthService().authenticate(identifier, |
72 |
|
new String(secret), xwikiContext); |
73 |
0 |
if (principal != null) { |
74 |
0 |
String xwikiUser = principal.getName(); |
75 |
|
|
76 |
0 |
xwikiContext.setUser(xwikiUser); |
77 |
|
|
78 |
0 |
this.context.getLogger().log(Level.FINE, String.format("Authenticated as '%s'.", identifier)); |
79 |
|
|
80 |
0 |
return true; |
81 |
|
} |
82 |
|
} catch (XWikiException e) { |
83 |
0 |
this.context.getLogger().log(Level.WARNING, "Exception occurred while authenticating.", e); |
84 |
|
} |
85 |
|
|
86 |
0 |
this.context.getLogger().log(Level.WARNING, String.format("Cannot authenticate '%s'.", identifier)); |
87 |
|
|
88 |
0 |
return false; |
89 |
|
} |
90 |
|
|
91 |
|
} |