Search in sources :

Example 1 with Mirror

use of net.vidageek.mirror.dsl.Mirror in project mamute by caelum.

the class RulesInterceptor method intercept.

@Override
public void intercept(InterceptorStack stack, ControllerMethod method, Object obj) throws InterceptionException {
    ClassController<KarmaCalculator> mirrorOnKarma = new Mirror().on(KarmaCalculator.class);
    List<Field> karmaCalculatorFields = mirrorOnKarma.reflectAll().fields();
    for (Field field : karmaCalculatorFields) {
        result.include(field.getName(), mirrorOnKarma.get().field(field));
    }
    PermissionRules[] rules = PermissionRules.values();
    for (PermissionRules rule : rules) {
        long karma = environmentKarma.get(rule);
        result.include(rule.name(), karma);
    }
    stack.next(method, obj);
}
Also used : Field(java.lang.reflect.Field) KarmaCalculator(org.mamute.reputation.rules.KarmaCalculator) Mirror(net.vidageek.mirror.dsl.Mirror) PermissionRules(org.mamute.auth.rules.PermissionRules)

Example 2 with Mirror

use of net.vidageek.mirror.dsl.Mirror in project mamute by caelum.

the class UserDAOTest method should_search_by_email_and_legacy_password_and_update_password.

@Test
public void should_search_by_email_and_legacy_password_and_update_password() {
    String password = "654321";
    User gui = user("Guilherme Sonar", "gui@email.com.br");
    LoginMethod brutalLogin = LoginMethod.brutalLogin(gui, "gui@email.com.br", password);
    new Mirror().on(brutalLogin).set().field("token").withValue(MD5.crypt(password));
    gui.add(brutalLogin);
    users.save(gui);
    session.save(brutalLogin);
    assertNull(users.findByMailAndPassword("gui@email.com.br", password));
    User found = users.findByMailAndLegacyPasswordAndUpdatePassword("gui@email.com.br", password);
    assertEquals(gui, found);
    assertEquals(Digester.encrypt(password), found.getBrutalLogin().getToken());
    assertNull(users.findByMailAndPassword("joao.silveira@email.com.br", password));
    assertNull(users.findByMailAndPassword("gui@email.com.br", "123456"));
}
Also used : User(org.mamute.model.User) LoginMethod(org.mamute.model.LoginMethod) Mirror(net.vidageek.mirror.dsl.Mirror) Test(org.junit.Test)

Aggregations

Mirror (net.vidageek.mirror.dsl.Mirror)2 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1 PermissionRules (org.mamute.auth.rules.PermissionRules)1 LoginMethod (org.mamute.model.LoginMethod)1 User (org.mamute.model.User)1 KarmaCalculator (org.mamute.reputation.rules.KarmaCalculator)1