Skip to content

Deprecate Authentication#setAuthenticated #16838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -131,7 +131,9 @@ public interface Authentication extends Principal, Serializable {
* trusted (by passing <code>true</code> as the argument) is rejected due to the
* implementation being immutable or implementing its own alternative approach to
* {@link #isAuthenticated()}
* @deprecated in favor of implementing {@link #isAuthenticated()}
*/
@Deprecated
void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;

}
51 changes: 51 additions & 0 deletions docs/modules/ROOT/pages/migration/authentication.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,54 @@ fun introspector(): OpaqueTokenIntrospector {
}
----
======

== Deprecated Authentication#setAuthenticated

The `Authentication#setAuthenticated` method has been deprecated in favor of implementing the `isAuthenticated()` method.

Previously, implementations might use `setAuthenticated` to mark an authentication token as valid:

[source,java]
----
Authentication auth = // create authentication
auth.setAuthenticated(true); // DEPRECATED
----

Instead, implementations should override the `isAuthenticated()` method to determine authentication validity:

[tabs]
======
Java::
+
[source,java,role="primary"]
----
public class MyAuthentication implements Authentication {

// Other methods...

@Override
public boolean isAuthenticated() {
// Custom logic to determine if this authentication is valid
return this.validated;
}
}
----

Kotlin::
+
[source,kotlin,role="secondary"]
----
class MyAuthentication : Authentication {

// Other methods...

override fun isAuthenticated(): Boolean {
// Custom logic to determine if this authentication is valid
return this.validated
}
}
----
======

Note that existing implementations will still need to support `setAuthenticated` for backward compatibility,
but new code should avoid calling this method.