Search in sources :

Example 6 with RememberMeUsernamePasswordCredential

use of org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyRememberMeIp.

@Test
public void verifyRememberMeIp() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(true);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties().setSupportedIpAddresses("192.+"));
    val auth = builder.build();
    assertFalse(auth.getAttributes().containsKey(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 7 with RememberMeUsernamePasswordCredential

use of org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyRememberMeUserAgentAndIp.

@Test
public void verifyRememberMeUserAgentAndIp() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Chrome");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(true);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties().setSupportedUserAgents("Chrome").setSupportedIpAddresses("123.+"));
    val auth = builder.build();
    assertFalse(auth.getAttributes().containsKey(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 8 with RememberMeUsernamePasswordCredential

use of org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential in project cas by apereo.

the class RememberMePasswordCredentialTests method verifyGettersAndSetters.

@Test
public void verifyGettersAndSetters() {
    val c = new RememberMeUsernamePasswordCredential();
    c.setPassword("password");
    c.setUsername("username");
    c.setRememberMe(true);
    assertEquals("username", c.getUsername());
    assertEquals("password", c.getPassword());
    assertTrue(c.isRememberMe());
}
Also used : lombok.val(lombok.val) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 9 with RememberMeUsernamePasswordCredential

use of org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential in project cas by apereo.

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyRememberMeUserAgent.

@Test
public void verifyRememberMeUserAgent() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "Chrome");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(true);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties().setSupportedUserAgents("Chrome"));
    val auth = builder.build();
    assertEquals(true, auth.getAttributes().get(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME).get(0));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 10 with RememberMeUsernamePasswordCredential

use of org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential in project cas by apereo.

the class ShiroAuthenticationHandlerTests method checkAuthenticationSuccessful.

@Test
public void checkAuthenticationSuccessful() throws Exception {
    val shiro = new ShiroAuthenticationHandler(StringUtils.EMPTY, null, PrincipalFactoryUtils.newPrincipalFactory(), new HashSet<>(0), new HashSet<>(0));
    shiro.loadShiroConfiguration(new ClassPathResource("shiro.ini"));
    val creds = new RememberMeUsernamePasswordCredential();
    creds.setRememberMe(true);
    creds.setUsername("casuser");
    creds.setPassword("Mellon");
    assertNotNull(shiro.authenticate(creds));
}
Also used : lombok.val(lombok.val) ClassPathResource(org.springframework.core.io.ClassPathResource) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)12 RememberMeUsernamePasswordCredential (org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential)12 Test (org.junit.jupiter.api.Test)11 RememberMeAuthenticationProperties (org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties)5 ClassPathResource (org.springframework.core.io.ClassPathResource)4 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 ArrayList (java.util.ArrayList)1 AccountLockedException (javax.security.auth.login.AccountLockedException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)1 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)1 ExpiredCredentialsException (org.apache.shiro.authc.ExpiredCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 AccountDisabledException (org.apereo.cas.authentication.exceptions.AccountDisabledException)1