use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.
the class JDBCRealmTest method testPermissionNotPresent.
@Test
public void testPermissionNotPresent() throws Exception {
String testMethodName = name.getMethodName();
JdbcRealm realm = realmMap.get(testMethodName);
createDefaultSchema(testMethodName, false);
realm.setSaltStyle(JdbcRealm.SaltStyle.NO_SALT);
realm.setPermissionsLookupEnabled(true);
Subject.Builder builder = new Subject.Builder(securityManager);
Subject currentUser = builder.buildSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword);
currentUser.login(token);
Assert.assertFalse(currentUser.isPermitted("testDomain:testTarget:specialAction"));
}
use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.
the class JDBCRealmTest method testPermissionPresent.
@Test
public void testPermissionPresent() throws Exception {
String testMethodName = name.getMethodName();
JdbcRealm realm = realmMap.get(testMethodName);
createDefaultSchema(testMethodName, false);
realm.setSaltStyle(JdbcRealm.SaltStyle.NO_SALT);
realm.setPermissionsLookupEnabled(true);
Subject.Builder builder = new Subject.Builder(securityManager);
Subject currentUser = builder.buildSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, plainTextPassword);
currentUser.login(token);
Assert.assertTrue(currentUser.isPermitted(testPermissionString));
}
use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.
the class DefaultLdapRealmTest method testGetAuthenticationInfoNamingException.
@Test(expected = AuthenticationException.class)
public void testGetAuthenticationInfoNamingException() throws NamingException {
realm.setUserDnTemplate("uid={0},ou=users,dc=mycompany,dc=com");
LdapContextFactory factory = createMock(LdapContextFactory.class);
realm.setContextFactory(factory);
expect(factory.getLdapContext(isA(Object.class), isA(Object.class))).andThrow(new NamingException("Communication error."));
replay(factory);
realm.getAuthenticationInfo(new UsernamePasswordToken("jsmith", "secret"));
}
use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.
the class DefaultLdapRealmTest method testUserDnTemplateSubstitution.
@Test
public void testUserDnTemplateSubstitution() throws NamingException {
realm.setUserDnTemplate("uid={0},ou=users,dc=mycompany,dc=com");
LdapContextFactory factory = createMock(LdapContextFactory.class);
realm.setContextFactory(factory);
Object expectedPrincipal = "uid=jsmith,ou=users,dc=mycompany,dc=com";
expect(factory.getLdapContext(eq(expectedPrincipal), isA(Object.class))).andReturn(createNiceMock(LdapContext.class));
replay(factory);
realm.getAuthenticationInfo(new UsernamePasswordToken("jsmith", "secret"));
verify(factory);
}
use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.
the class IniRealmTest method testIniFile.
@Test
public void testIniFile() {
IniRealm realm = new IniRealm();
realm.setResourcePath("classpath:org/apache/shiro/realm/text/IniRealmTest.simple.ini");
realm.init();
assertTrue(realm.roleExists("admin"));
UsernamePasswordToken token = new UsernamePasswordToken("user1", "user1");
AuthenticationInfo info = realm.getAuthenticationInfo(token);
assertNotNull(info);
assertTrue(realm.hasRole(info.getPrincipals(), "admin"));
}
Aggregations