Search in sources :

Example 1 with SecurityMetersService

use of de.tum.in.www1.artemis.management.SecurityMetersService in project ArTEMiS by ls1intum.

the class TokenProviderSecurityMetersTests method setup.

@BeforeEach
public void setup() {
    JHipsterProperties jHipsterProperties = new JHipsterProperties();
    String base64Secret = "fd54a45s65fds737b9aafcb3412e07ed99b267f33413274720ddbb7f6c5e64e9f14075f2d7ed041592f0b7657baf8";
    jHipsterProperties.getSecurity().getAuthentication().getJwt().setBase64Secret(base64Secret);
    meterRegistry = new SimpleMeterRegistry();
    SecurityMetersService securityMetersService = new SecurityMetersService(meterRegistry);
    tokenProvider = new TokenProvider(jHipsterProperties, securityMetersService);
    Key key = Keys.hmacShaKeyFor(Decoders.BASE64.decode(base64Secret));
    ReflectionTestUtils.setField(tokenProvider, "key", key);
    ReflectionTestUtils.setField(tokenProvider, "tokenValidityInMilliseconds", ONE_MINUTE);
}
Also used : JHipsterProperties(tech.jhipster.config.JHipsterProperties) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SecurityMetersService(de.tum.in.www1.artemis.management.SecurityMetersService) Key(java.security.Key) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SecurityMetersService

use of de.tum.in.www1.artemis.management.SecurityMetersService in project ArTEMiS by ls1intum.

the class JWTFilterTest method setup.

@BeforeEach
public void setup() {
    JHipsterProperties jHipsterProperties = new JHipsterProperties();
    String base64Secret = "fd54a45s65fds737b9aafcb3412e07ed99b267f33413274720ddbb7f6c5e64e9f14075f2d7ed041592f0b7657baf8";
    jHipsterProperties.getSecurity().getAuthentication().getJwt().setBase64Secret(base64Secret);
    SecurityMetersService securityMetersService = new SecurityMetersService(new SimpleMeterRegistry());
    tokenProvider = new TokenProvider(jHipsterProperties, securityMetersService);
    ReflectionTestUtils.setField(tokenProvider, "key", Keys.hmacShaKeyFor(Decoders.BASE64.decode(base64Secret)));
    ReflectionTestUtils.setField(tokenProvider, "tokenValidityInMilliseconds", 60000);
    jwtFilter = new JWTFilter(tokenProvider);
    SecurityContextHolder.getContext().setAuthentication(null);
}
Also used : JHipsterProperties(tech.jhipster.config.JHipsterProperties) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SecurityMetersService(de.tum.in.www1.artemis.management.SecurityMetersService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with SecurityMetersService

use of de.tum.in.www1.artemis.management.SecurityMetersService in project ArTEMiS by ls1intum.

the class TokenProviderTest method setup.

@BeforeEach
public void setup() {
    JHipsterProperties jHipsterProperties = new JHipsterProperties();
    String base64Secret = "fd54a45s65fds737b9aafcb3412e07ed99b267f33413274720ddbb7f6c5e64e9f14075f2d7ed041592f0b7657baf8";
    jHipsterProperties.getSecurity().getAuthentication().getJwt().setBase64Secret(base64Secret);
    SecurityMetersService securityMetersService = new SecurityMetersService(new SimpleMeterRegistry());
    tokenProvider = new TokenProvider(jHipsterProperties, securityMetersService);
    key = Keys.hmacShaKeyFor(Decoders.BASE64.decode(base64Secret));
    ReflectionTestUtils.setField(tokenProvider, "key", key);
    ReflectionTestUtils.setField(tokenProvider, "tokenValidityInMilliseconds", ONE_MINUTE);
}
Also used : JHipsterProperties(tech.jhipster.config.JHipsterProperties) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SecurityMetersService(de.tum.in.www1.artemis.management.SecurityMetersService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SecurityMetersService

use of de.tum.in.www1.artemis.management.SecurityMetersService in project ArTEMiS by ls1intum.

the class TokenProviderTest method testKeyIsSetFromBase64SecretWhenSecretIsEmpty.

@Test
void testKeyIsSetFromBase64SecretWhenSecretIsEmpty() {
    final String base64Secret = "fd54a45s65fds737b9aafcb3412e07ed99b267f33413274720ddbb7f6c5e64e9f14075f2d7ed041592f0b7657baf8";
    JHipsterProperties jHipsterProperties = new JHipsterProperties();
    jHipsterProperties.getSecurity().getAuthentication().getJwt().setBase64Secret(base64Secret);
    SecurityMetersService securityMetersService = new SecurityMetersService(new SimpleMeterRegistry());
    TokenProvider tokenProvider = new TokenProvider(jHipsterProperties, securityMetersService);
    tokenProvider.init();
    Key key = (Key) ReflectionTestUtils.getField(tokenProvider, "key");
    assertThat(key).isNotNull().isEqualTo(Keys.hmacShaKeyFor(Decoders.BASE64.decode(base64Secret)));
}
Also used : JHipsterProperties(tech.jhipster.config.JHipsterProperties) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SecurityMetersService(de.tum.in.www1.artemis.management.SecurityMetersService) Key(java.security.Key) Test(org.junit.jupiter.api.Test)

Example 5 with SecurityMetersService

use of de.tum.in.www1.artemis.management.SecurityMetersService in project ArTEMiS by ls1intum.

the class TokenProviderTest method testKeyIsSetFromSecretWhenSecretIsNotEmpty.

@Test
void testKeyIsSetFromSecretWhenSecretIsNotEmpty() {
    final String secret = "NwskoUmKHZtzGRKJKVjsJF7BtQMMxNWi";
    JHipsterProperties jHipsterProperties = new JHipsterProperties();
    jHipsterProperties.getSecurity().getAuthentication().getJwt().setSecret(secret);
    SecurityMetersService securityMetersService = new SecurityMetersService(new SimpleMeterRegistry());
    TokenProvider tokenProvider = new TokenProvider(jHipsterProperties, securityMetersService);
    tokenProvider.init();
    Key key = (Key) ReflectionTestUtils.getField(tokenProvider, "key");
    assertThat(key).isNotNull().isEqualTo(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8)));
}
Also used : JHipsterProperties(tech.jhipster.config.JHipsterProperties) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) SecurityMetersService(de.tum.in.www1.artemis.management.SecurityMetersService) Key(java.security.Key) Test(org.junit.jupiter.api.Test)

Aggregations

SecurityMetersService (de.tum.in.www1.artemis.management.SecurityMetersService)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)5 JHipsterProperties (tech.jhipster.config.JHipsterProperties)5 Key (java.security.Key)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Test (org.junit.jupiter.api.Test)2