All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.server.authentication.event.AuthenticationException Maven / Gradle / Ivy

There is a newer version: 7.2.1
Show newest version
/*
 * SonarQube
 * Copyright (C) 2009-2017 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package org.sonar.server.authentication.event;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

/**
 * Exception thrown in case of authentication failure.
 * 

* This exception contains the source of authentication and, if present, the login on which the login attempt occurred. *

*

* Given that {@link #source} and {@link #login} will be logged to file, be very careful not to set the login * when the login is a security token. *

*/ public class AuthenticationException extends RuntimeException { private final AuthenticationEvent.Source source; @CheckForNull private final String login; private final String publicMessage; private AuthenticationException(Builder builder) { super(builder.message); this.source = requireNonNull(builder.source, "source can't be null"); this.login = builder.login; this.publicMessage = builder.publicMessage; } public AuthenticationEvent.Source getSource() { return source; } @CheckForNull public String getLogin() { return login; } @CheckForNull public String getPublicMessage() { return publicMessage; } public static Builder newBuilder() { return new Builder(); } public static class Builder { @CheckForNull private AuthenticationEvent.Source source; @CheckForNull private String login; @CheckForNull private String message; @CheckForNull private String publicMessage; private Builder() { // use static factory method } public Builder setSource(AuthenticationEvent.Source source) { this.source = source; return this; } public Builder setLogin(@Nullable String login) { this.login = login; return this; } public Builder setMessage(String message) { this.message = message; return this; } public Builder setPublicMessage(String publicMessage) { this.publicMessage = publicMessage; return this; } public AuthenticationException build() { return new AuthenticationException(this); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy