Search in sources :

Example 1 with JHipsterProperties

use of tech.jhipster.config.JHipsterProperties 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 JHipsterProperties

use of tech.jhipster.config.JHipsterProperties 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 JHipsterProperties

use of tech.jhipster.config.JHipsterProperties 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 JHipsterProperties

use of tech.jhipster.config.JHipsterProperties 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 JHipsterProperties

use of tech.jhipster.config.JHipsterProperties in project jhipster-bom by jhipster.

the class CachingHttpHeadersFilterTest method setup.

@BeforeEach
void setup() {
    request = new MockHttpServletRequest();
    response = spy(new MockHttpServletResponse());
    chain = spy(new MockFilterChain());
    properties = new JHipsterProperties();
    filter = new CachingHttpHeadersFilter(properties);
}
Also used : JHipsterProperties(tech.jhipster.config.JHipsterProperties) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

JHipsterProperties (tech.jhipster.config.JHipsterProperties)9 BeforeEach (org.junit.jupiter.api.BeforeEach)7 SecurityMetersService (de.tum.in.www1.artemis.management.SecurityMetersService)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)5 Key (java.security.Key)3 Test (org.junit.jupiter.api.Test)2 MockServletContext (org.springframework.mock.web.MockServletContext)2 StaticResourcesWebConfiguration (com.auth0.flickr2.config.StaticResourcesWebConfiguration)1 User (de.tum.in.www1.artemis.domain.User)1 MimeMessage (javax.mail.internet.MimeMessage)1 WebServlet (org.h2.server.web.WebServlet)1 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1 MockFilterChain (org.springframework.mock.web.MockFilterChain)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1 ResourceHandlerRegistry (org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry)1