Search in sources :

Example 26 with UsernamePasswordToken

use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.

the class JDBCRealmTest method testUnSaltedWrongPassword.

@Test
public void testUnSaltedWrongPassword() throws Exception {
    String testMethodName = name.getMethodName();
    JdbcRealm realm = realmMap.get(testMethodName);
    createDefaultSchema(testMethodName, false);
    realm.setSaltStyle(JdbcRealm.SaltStyle.NO_SALT);
    Subject.Builder builder = new Subject.Builder(securityManager);
    Subject currentUser = builder.buildSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, "passwrd");
    try {
        currentUser.login(token);
    } catch (IncorrectCredentialsException ex) {
    // Expected
    }
}
Also used : IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 27 with UsernamePasswordToken

use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.

the class JDBCRealmTest method testUnSaltedMultipleRows.

@Test
public void testUnSaltedMultipleRows() throws Exception {
    String testMethodName = name.getMethodName();
    JdbcRealm realm = realmMap.get(testMethodName);
    createDefaultSchema(testMethodName, false);
    realm.setSaltStyle(JdbcRealm.SaltStyle.NO_SALT);
    Connection conn = dsMap.get(testMethodName).getConnection();
    Statement sql = conn.createStatement();
    sql.executeUpdate("insert into users values ('" + username + "', 'dupe')");
    Subject.Builder builder = new Subject.Builder(securityManager);
    Subject currentUser = builder.buildSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, "passwrd");
    try {
        currentUser.login(token);
    } catch (AuthenticationException ex) {
    // Expected
    }
}
Also used : AuthenticationException(org.apache.shiro.authc.AuthenticationException) Statement(java.sql.Statement) Connection(java.sql.Connection) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 28 with UsernamePasswordToken

use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.

the class JDBCRealmTest method testExternalWrongPassword.

@Test
public void testExternalWrongPassword() throws Exception {
    String testMethodName = name.getMethodName();
    JdbcRealm realm = realmMap.get(testMethodName);
    createDefaultSchema(testMethodName, true);
    realm.setSaltStyle(JdbcRealm.SaltStyle.EXTERNAL);
    Subject.Builder builder = new Subject.Builder(securityManager);
    Subject currentUser = builder.buildSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, "passwrd");
    try {
        currentUser.login(token);
    } catch (IncorrectCredentialsException ex) {
    // Expected
    }
}
Also used : IncorrectCredentialsException(org.apache.shiro.authc.IncorrectCredentialsException) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 29 with UsernamePasswordToken

use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.

the class JDBCRealmTest method testUnSaltedSuccess.

@Test
public void testUnSaltedSuccess() throws Exception {
    String testMethodName = name.getMethodName();
    JdbcRealm realm = realmMap.get(testMethodName);
    createDefaultSchema(testMethodName, false);
    realm.setSaltStyle(JdbcRealm.SaltStyle.NO_SALT);
    Subject.Builder builder = new Subject.Builder(securityManager);
    Subject currentUser = builder.buildSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword);
    currentUser.login(token);
    currentUser.logout();
}
Also used : Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Example 30 with UsernamePasswordToken

use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.

the class JDBCRealmTest method testSaltColumnSuccess.

@Test
public void testSaltColumnSuccess() throws Exception {
    String testMethodName = name.getMethodName();
    JdbcRealm realm = realmMap.get(testMethodName);
    createSaltColumnSchema(testMethodName);
    realm.setSaltStyle(JdbcRealm.SaltStyle.COLUMN);
    Subject.Builder builder = new Subject.Builder(securityManager);
    Subject currentUser = builder.buildSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword);
    currentUser.login(token);
    currentUser.logout();
}
Also used : Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Aggregations

UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)114 Subject (org.apache.shiro.subject.Subject)50 Test (org.junit.Test)30 AuthenticationException (org.apache.shiro.authc.AuthenticationException)28 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)27 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)17 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Test (org.testng.annotations.Test)11 LockedAccountException (org.apache.shiro.authc.LockedAccountException)10 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)7 DelegatingSubject (org.apache.shiro.subject.support.DelegatingSubject)7 Session (org.apache.shiro.session.Session)6 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)4 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)4