Search in sources :

Example 1 with RememberMeUsernamePasswordCredential

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

the class ShiroAuthenticationHandlerTests method checkAuthenticationSuccessfulMissingPermission.

@Test
public void checkAuthenticationSuccessfulMissingPermission() {
    val shiro = new ShiroAuthenticationHandler(StringUtils.EMPTY, null, PrincipalFactoryUtils.newPrincipalFactory(), new HashSet<>(0), Collections.singleton("dosomething"));
    shiro.loadShiroConfiguration(new ClassPathResource("shiro.ini"));
    val creds = new RememberMeUsernamePasswordCredential();
    creds.setRememberMe(true);
    creds.setUsername("casuser");
    creds.setPassword("Mellon");
    assertThrows(FailedLoginException.class, () -> 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)

Example 2 with RememberMeUsernamePasswordCredential

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

the class ShiroAuthenticationHandlerTests method checkAuthenticationAccountStatusHandling.

@Test
public void checkAuthenticationAccountStatusHandling() {
    val creds = new RememberMeUsernamePasswordCredential();
    creds.setUsername("casuser");
    creds.setPassword("Mellon");
    assertThrows(AccountNotFoundException.class, () -> buildShiroHandlerWithAccountStatus(UnknownAccountException.class).authenticate(creds));
    assertThrows(AccountLockedException.class, () -> buildShiroHandlerWithAccountStatus(LockedAccountException.class).authenticate(creds));
    assertThrows(CredentialExpiredException.class, () -> buildShiroHandlerWithAccountStatus(ExpiredCredentialsException.class).authenticate(creds));
    assertThrows(AccountDisabledException.class, () -> buildShiroHandlerWithAccountStatus(DisabledAccountException.class).authenticate(creds));
    assertThrows(FailedLoginException.class, () -> buildShiroHandlerWithAccountStatus(AuthenticationException.class).authenticate(creds));
}
Also used : lombok.val(lombok.val) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 3 with RememberMeUsernamePasswordCredential

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

the class ShiroAuthenticationHandlerTests method checkAuthenticationSuccessfulMissingRole.

@Test
public void checkAuthenticationSuccessfulMissingRole() {
    val shiro = new ShiroAuthenticationHandler(StringUtils.EMPTY, null, PrincipalFactoryUtils.newPrincipalFactory(), Collections.singleton("student"), new HashSet<>(0));
    shiro.loadShiroConfiguration(new ClassPathResource("shiro.ini"));
    val creds = new RememberMeUsernamePasswordCredential();
    creds.setRememberMe(true);
    creds.setUsername("casuser");
    creds.setPassword("Mellon");
    assertThrows(FailedLoginException.class, () -> 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)

Example 4 with RememberMeUsernamePasswordCredential

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

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyWithTrueRememberMeCredentials.

@Test
public void verifyWithTrueRememberMeCredentials() {
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(true);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties());
    val auth = builder.build();
    assertEquals(true, auth.getAttributes().get(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME).get(0));
}
Also used : lombok.val(lombok.val) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) RememberMeUsernamePasswordCredential(org.apereo.cas.authentication.credential.RememberMeUsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 5 with RememberMeUsernamePasswordCredential

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

the class RememberMeAuthenticationMetaDataPopulatorTests method verifyWithFalseRememberMeCredentials.

@Test
public void verifyWithFalseRememberMeCredentials() {
    val c = new RememberMeUsernamePasswordCredential();
    c.setRememberMe(false);
    val builder = newBuilder(c, new RememberMeAuthenticationProperties());
    val auth = builder.build();
    assertNull(auth.getAttributes().get(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME));
}
Also used : lombok.val(lombok.val) RememberMeAuthenticationProperties(org.apereo.cas.configuration.model.core.ticket.RememberMeAuthenticationProperties) 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