mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
Add default refresh strategy
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
package sonia.scm.security;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.Extension;
|
||||||
|
|
||||||
|
@Extension
|
||||||
|
public class DefaultJwtAccessTokenRefreshStrategy extends PercentageJwtAccessTokenRefreshStrategy {
|
||||||
|
public DefaultJwtAccessTokenRefreshStrategy() {
|
||||||
|
super(0.5F);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package sonia.scm.security;
|
package sonia.scm.security;
|
||||||
|
|
||||||
|
import sonia.scm.plugin.ExtensionPoint;
|
||||||
|
|
||||||
|
@ExtensionPoint
|
||||||
public interface JwtAccessTokenRefreshStrategy {
|
public interface JwtAccessTokenRefreshStrategy {
|
||||||
boolean shouldBeRefreshed(JwtAccessToken oldToken);
|
boolean shouldBeRefreshed(JwtAccessToken oldToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,15 +47,14 @@ public class PercentageJwtAccessTokenRefreshStrategyTest {
|
|||||||
when(creationClock.instant()).thenReturn(TOKEN_CREATION);
|
when(creationClock.instant()).thenReturn(TOKEN_CREATION);
|
||||||
|
|
||||||
tokenBuilder = new JwtAccessTokenBuilderFactory(keyGenerator, keyResolver, Collections.emptySet(), creationClock).create();
|
tokenBuilder = new JwtAccessTokenBuilderFactory(keyGenerator, keyResolver, Collections.emptySet(), creationClock).create();
|
||||||
tokenBuilder
|
tokenBuilder.refreshableFor(1, HOURS);
|
||||||
.refreshableFor(1, HOURS);
|
|
||||||
|
|
||||||
refreshStrategy = new PercentageJwtAccessTokenRefreshStrategy(refreshClock, 0.5F);
|
refreshStrategy = new PercentageJwtAccessTokenRefreshStrategy(refreshClock, 0.5F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotRefreshWhenTokenIsYoung() {
|
public void shouldNotRefreshWhenTokenIsYoung() {
|
||||||
when(refreshClock.instant()).thenReturn(TOKEN_CREATION.plus(1, MINUTES));
|
when(refreshClock.instant()).thenReturn(TOKEN_CREATION.plus(29, MINUTES));
|
||||||
assertThat(refreshStrategy.shouldBeRefreshed(tokenBuilder.build())).isFalse();
|
assertThat(refreshStrategy.shouldBeRefreshed(tokenBuilder.build())).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user