-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support GenerateOneTimeTokenRequestResolver
Closes gh-16291
- Loading branch information
1 parent
036f6f2
commit 714b2c4
Showing
9 changed files
with
274 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...framework/security/web/authentication/ott/DefaultGenerateOneTimeTokenRequestResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2002-2024 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://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.springframework.security.web.authentication.ott; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.security.authentication.ott.GenerateOneTimeTokenRequest; | ||
import org.springframework.util.Assert; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* Default implementation of {@link GenerateOneTimeTokenRequestResolver}. Resolves {@link GenerateOneTimeTokenRequest} from username parameter. | ||
* | ||
* @author Max Batischev | ||
* @since 6.5 | ||
*/ | ||
public final class DefaultGenerateOneTimeTokenRequestResolver implements GenerateOneTimeTokenRequestResolver { | ||
private static final int DEFAULT_EXPIRES_IN = 300; | ||
|
||
private int expiresIn = DEFAULT_EXPIRES_IN; | ||
|
||
@Override | ||
public GenerateOneTimeTokenRequest resolve(HttpServletRequest request) { | ||
String username = request.getParameter("username"); | ||
if (!StringUtils.hasText(username)) { | ||
return null; | ||
} | ||
return new GenerateOneTimeTokenRequest(username, this.expiresIn); | ||
} | ||
|
||
/** | ||
* Sets one-time token expiration time (seconds) | ||
* | ||
* @param expiresIn one-time token expiration time | ||
*/ | ||
public void setExpiresIn(int expiresIn) { | ||
Assert.isTrue(expiresIn > 0, "expiresAt must be > 0"); | ||
this.expiresIn = expiresIn; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../springframework/security/web/authentication/ott/GenerateOneTimeTokenRequestResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2002-2024 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://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.springframework.security.web.authentication.ott; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.security.authentication.ott.GenerateOneTimeTokenRequest; | ||
|
||
/** | ||
* A strategy for resolving a {@link GenerateOneTimeTokenRequest} from the {@link HttpServletRequest}. | ||
* | ||
* @author Max Batischev | ||
* @since 6.5 | ||
*/ | ||
public interface GenerateOneTimeTokenRequestResolver { | ||
|
||
/** | ||
* Resolves {@link GenerateOneTimeTokenRequest} from {@link HttpServletRequest} | ||
* | ||
* @param request {@link HttpServletRequest} to resolve | ||
* @return {@link GenerateOneTimeTokenRequest} | ||
*/ | ||
@Nullable | ||
GenerateOneTimeTokenRequest resolve(HttpServletRequest request); | ||
|
||
} |
Oops, something went wrong.