mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-10-29 08:05:31 +00:00
GUAC-586: Clarify auth result and include data source. Consistently refer to usernames as "username", not "user IDs".
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.glyptodon.guacamole.net.basic.rest.auth;
|
||||
|
||||
/**
|
||||
* A simple object to represent an auth token/userID pair in the API.
|
||||
*
|
||||
* @author James Muehlner
|
||||
*/
|
||||
public class APIAuthToken {
|
||||
|
||||
/**
|
||||
* The auth token.
|
||||
*/
|
||||
private final String authToken;
|
||||
|
||||
|
||||
/**
|
||||
* The user ID.
|
||||
*/
|
||||
private final String userID;
|
||||
|
||||
/**
|
||||
* Get the auth token.
|
||||
* @return The auth token.
|
||||
*/
|
||||
public String getAuthToken() {
|
||||
return authToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user ID.
|
||||
* @return The user ID.
|
||||
*/
|
||||
public String getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new APIAuthToken Object with the given auth token.
|
||||
*
|
||||
* @param authToken The auth token to create the new APIAuthToken with.
|
||||
* @param userID The ID of the user owning the given token.
|
||||
*/
|
||||
public APIAuthToken(String authToken, String userID) {
|
||||
this.authToken = authToken;
|
||||
this.userID = userID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.glyptodon.guacamole.net.basic.rest.auth;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple object which describes the result of an authentication operation,
|
||||
* including the resulting token.
|
||||
*
|
||||
* @author James Muehlner
|
||||
* @author Michael Jumper
|
||||
*/
|
||||
public class APIAuthenticationResult {
|
||||
|
||||
/**
|
||||
* The unique token generated for the user that authenticated.
|
||||
*/
|
||||
private final String authToken;
|
||||
|
||||
/**
|
||||
* The username of the user that authenticated.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* The unique identifier of the data source from which this user account
|
||||
* came. Although this user account may exist across several data sources
|
||||
* (AuthenticationProviders), this will be the unique identifier of the
|
||||
* AuthenticationProvider that authenticated this user for the current
|
||||
* session.
|
||||
*/
|
||||
private final String dataSource;
|
||||
|
||||
/**
|
||||
* The identifiers of all data sources available to this user.
|
||||
*/
|
||||
private final List<String> availableDataSources;
|
||||
|
||||
/**
|
||||
* Returns the unique authentication token which identifies the current
|
||||
* session.
|
||||
*
|
||||
* @return
|
||||
* The user's authentication token.
|
||||
*/
|
||||
public String getAuthToken() {
|
||||
return authToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user identified by the authentication token associated with
|
||||
* the current session.
|
||||
*
|
||||
* @return
|
||||
* The user identified by this authentication token.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique identifier of the data source associated with the user
|
||||
* account associated with the current session.
|
||||
*
|
||||
* @return
|
||||
* The unique identifier of the data source associated with the user
|
||||
* account associated with the current session.
|
||||
*/
|
||||
public String getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifiers of all data sources available to the user
|
||||
* associated with the current session.
|
||||
*
|
||||
* @return
|
||||
* The identifiers of all data sources available to the user associated
|
||||
* with the current session.
|
||||
*/
|
||||
public List<String> getAvailableDataSources() {
|
||||
return availableDataSources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new APIAuthenticationResult object containing the given data.
|
||||
*
|
||||
* @param authToken
|
||||
* The unique token generated for the user that authenticated, to be
|
||||
* used for the duration of their session.
|
||||
*
|
||||
* @param username
|
||||
* The username of the user owning the given token.
|
||||
*
|
||||
* @param dataSource
|
||||
* The unique identifier of the AuthenticationProvider which
|
||||
* authenticated the user.
|
||||
*
|
||||
* @param availableDataSources
|
||||
* The unique identifier of all AuthenticationProviders to which the
|
||||
* user now has access.
|
||||
*/
|
||||
public APIAuthenticationResult(String authToken, String username,
|
||||
String dataSource, List<String> availableDataSources) {
|
||||
this.authToken = authToken;
|
||||
this.username = username;
|
||||
this.dataSource = dataSource;
|
||||
this.availableDataSources = Collections.unmodifiableList(availableDataSources);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -456,12 +456,16 @@ public class TokenRESTService {
|
||||
* map, even if those parameters are no longer accessible within the
|
||||
* now-fully-consumed HTTP request.
|
||||
*
|
||||
* @return The auth token for the newly logged-in user.
|
||||
* @throws GuacamoleException If an error prevents successful login.
|
||||
* @return
|
||||
* An authentication response object containing the possible-new auth
|
||||
* token, as well as other related data.
|
||||
*
|
||||
* @throws GuacamoleException
|
||||
* If an error prevents successful authentication.
|
||||
*/
|
||||
@POST
|
||||
@AuthProviderRESTExposure
|
||||
public APIAuthToken createToken(@FormParam("username") String username,
|
||||
public APIAuthenticationResult createToken(@FormParam("username") String username,
|
||||
@FormParam("password") String password,
|
||||
@FormParam("token") String token,
|
||||
@Context HttpServletRequest consumedRequest,
|
||||
@@ -500,8 +504,18 @@ public class TokenRESTService {
|
||||
logger.debug("Login was successful for user \"{}\".", authenticatedUser.getIdentifier());
|
||||
}
|
||||
|
||||
// Build list of all available auth providers
|
||||
List<String> authProviderIdentifiers = new ArrayList<String>(userContexts.size());
|
||||
for (UserContext userContext : userContexts)
|
||||
authProviderIdentifiers.add(userContext.getAuthenticationProvider().getIdentifier());
|
||||
|
||||
// Return possibly-new auth token
|
||||
return new APIAuthToken(authToken, authenticatedUser.getIdentifier());
|
||||
return new APIAuthenticationResult(
|
||||
authToken,
|
||||
authenticatedUser.getIdentifier(),
|
||||
authenticatedUser.getAuthenticationProvider().getIdentifier(),
|
||||
authProviderIdentifiers
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user