1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* $Revision$
* $Date$
*
* Copyright (C) 2005-2008 Jive Software. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.openfire.clearspace;
import org.jivesoftware.openfire.auth.AuthProvider;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.auth.ConnectionException;
import org.jivesoftware.openfire.auth.InternalUnauthenticatedException;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET;
import org.jivesoftware.openfire.net.SASLAuthentication;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.packet.JID;
/**
* The ClearspaceAuthProvider uses the PermissionService web service inside of Clearspace
* to retrieve authenticate users. It current version of Clearspace only supports plain authentication.
*
* @author Gabriel Guardincerri
*/
public class ClearspaceAuthProvider implements AuthProvider {
// Service url prefix
protected static final String URL_PREFIX = "permissionService/";
public ClearspaceAuthProvider() {
// Add SASL mechanism for use with Clearspace's group chat integration
SASLAuthentication.addSupportedMechanism("CLEARSPACE");
}
/**
* Clearspace currently supports only plain authentication.
*
* @return true
*/
public boolean isPlainSupported() {
return true;
}
/**
* Clearspace currently doesn't support digest authentication.
*
* @return false
*/
public boolean isDigestSupported() {
return false;
}
/**
* Authenticates the user using permissionService/authenticate service of Clearspace.
* Throws an UnauthorizedException if the user or password are incorrect.
*
* @param username the username.
* @param password the password.
* @throws UnauthorizedException if the username of password are incorrect.
*/
public void authenticate(String username, String password) throws UnauthorizedException,
ConnectionException, InternalUnauthenticatedException {
try {
// Un-escape username.
username = JID.unescapeNode(username);
// Encode potentially non-ASCII characters
username = URLUTF8Encoder.encode(username);
String path = URL_PREFIX + "authenticate/" + username + "/" + password;
ClearspaceManager.getInstance().executeRequest(GET, path);
} catch (UnauthorizedException ue) {
throw ue;
} catch (org.jivesoftware.openfire.clearspace.ConnectionException e) {
if (e.getErrorType() == org.jivesoftware.openfire.clearspace.ConnectionException.ErrorType.AUTHENTICATION) {
throw new InternalUnauthenticatedException("Bad credentials to use Clearspace webservices", e);
} else {
throw new ConnectionException("Error connection to Clearspace webservices", e);
}
} catch (Exception e) {
// It is not supported exception, wrap it into an UnsupportedOperationException
throw new UnauthorizedException("Unexpected error", e);
}
}
/**
* This method is not supported.
*
* @param username the username
* @param token the token
* @param digest the digest
* @throws UnauthorizedException never throws it
* @throws UnsupportedOperationException always throws it
*/
public void authenticate(String username, String token, String digest) throws UnauthorizedException {
throw new UnsupportedOperationException("Digest not supported");
}
/**
* This method is not supported.
*
* @throws UnsupportedOperationException always throws it
*/
public String getPassword(String username) throws UserNotFoundException, UnsupportedOperationException {
throw new UnsupportedOperationException("Password retrieval not supported");
}
/**
* This method is not supported.
*
* @throws UnsupportedOperationException always throws it
*/
public void setPassword(String username, String password) throws UserNotFoundException, UnsupportedOperationException {
throw new UnsupportedOperationException("Change Password not supported");
}
/**
* This method is not supported.
*
* @throws UnsupportedOperationException always throws it
*/
public boolean supportsPasswordRetrieval() {
return false;
}
}