mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-10 15:11:22 +00:00
GUACAMOLE-96: Migrate to TOTP-specific field type for authentication code.
This commit is contained in:
@@ -28,8 +28,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import org.apache.guacamole.GuacamoleClientException;
|
||||
import org.apache.guacamole.GuacamoleException;
|
||||
import org.apache.guacamole.GuacamoleUnsupportedException;
|
||||
import org.apache.guacamole.auth.totp.form.AuthenticationCodeField;
|
||||
import org.apache.guacamole.form.Field;
|
||||
import org.apache.guacamole.form.TextField;
|
||||
import org.apache.guacamole.net.auth.AuthenticatedUser;
|
||||
import org.apache.guacamole.net.auth.Credentials;
|
||||
import org.apache.guacamole.net.auth.User;
|
||||
@@ -61,26 +61,6 @@ public class UserVerificationService {
|
||||
*/
|
||||
private static final String TOTP_KEY_CONFIRMED_ATTRIBUTE_NAME = "guac-totp-key-confirmed";
|
||||
|
||||
/**
|
||||
* The name of the HTTP parameter which will contain the TOTP code provided
|
||||
* by the user to verify their identity.
|
||||
*/
|
||||
private static final String TOTP_PARAMETER_NAME = "guac-totp";
|
||||
|
||||
/**
|
||||
* The field which should be exposed to the user to request that they
|
||||
* provide their TOTP code.
|
||||
*/
|
||||
private static final Field TOTP_FIELD = new TextField(TOTP_PARAMETER_NAME);
|
||||
|
||||
/**
|
||||
* CredentialsInfo object describing the credentials expected for a user
|
||||
* who has verified their identity with TOTP.
|
||||
*/
|
||||
private static final CredentialsInfo TOTP_CREDENTIALS = new CredentialsInfo(
|
||||
Collections.singletonList(TOTP_FIELD)
|
||||
);
|
||||
|
||||
/**
|
||||
* BaseEncoding instance which decoded/encodes base32.
|
||||
*/
|
||||
@@ -234,14 +214,16 @@ public class UserVerificationService {
|
||||
HttpServletRequest request = credentials.getRequest();
|
||||
|
||||
// Retrieve TOTP from request
|
||||
String code = request.getParameter(TOTP_PARAMETER_NAME);
|
||||
String code = request.getParameter(AuthenticationCodeField.PARAMETER_NAME);
|
||||
|
||||
// If no TOTP provided, request one
|
||||
if (code == null) {
|
||||
|
||||
// FIXME: Handle key.isConfirmed() for initial prompt
|
||||
throw new GuacamoleInsufficientCredentialsException(
|
||||
"LOGIN.INFO_TOTP_REQUIRED", TOTP_CREDENTIALS);
|
||||
"LOGIN.INFO_TOTP_REQUIRED", new CredentialsInfo(
|
||||
Collections.<Field>singletonList(new AuthenticationCodeField())
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.apache.guacamole.auth.totp.form;
|
||||
|
||||
import org.apache.guacamole.form.Field;
|
||||
|
||||
/**
|
||||
* Field which prompts the user for an authentication code generated via TOTP.
|
||||
*/
|
||||
public class AuthenticationCodeField extends Field {
|
||||
|
||||
/**
|
||||
* The name of the HTTP parameter which will contain the TOTP code provided
|
||||
* by the user to verify their identity.
|
||||
*/
|
||||
public static final String PARAMETER_NAME = "guac-totp";
|
||||
|
||||
/**
|
||||
* The unique name associated with this field type.
|
||||
*/
|
||||
private static final String FIELD_TYPE_NAME = "GUAC_TOTP_CODE";
|
||||
|
||||
/**
|
||||
* Creates a new field which prompts the user for an authentication code
|
||||
* generated via TOTP.
|
||||
*/
|
||||
public AuthenticationCodeField() {
|
||||
super(PARAMETER_NAME, FIELD_TYPE_NAME);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user