use of eu.ggnet.dwoss.rights.ee.entity.Operator in project dwoss by gg-net.
the class RightsGeneratorOperation method make.
/**
* Create the given amount of operators and personas and create a Addentional Operator with the Username "Adminuser" und clear text Password Test and All
* Rights.
* <p>
* .* @param countOfOperator
* <p>
* @param countOfOperator
* @param countOfPersona
*/
public void make(int countOfOperator, int countOfPersona) {
List<Persona> personas = new ArrayList<>();
for (int i = 0; i < countOfPersona; i++) {
Persona persona = new Persona();
persona.setName("Persona " + i);
persona.addAll(getRandomRights());
em.persist(persona);
personas.add(persona);
}
for (int j = 0; j < countOfOperator; j++) {
Operator operator = new Operator();
for (AtomicRight atomicRight : getRandomRights()) {
operator.add(atomicRight);
}
operator.setUsername("User " + j);
int till = (int) (Math.random() * countOfPersona - 1);
for (Persona persona : personas.subList(0, till)) {
operator.add(persona);
}
operator.setSalt(RandomStringUtils.randomAlphanumeric(6).getBytes());
operator.setPassword(AuthenticationBean.hashPassword(RandomStringUtils.randomAlphanumeric(15).toCharArray(), operator.getSalt()));
operator.setQuickLoginKey((int) (Math.random() * 999));
em.persist(operator);
}
}
use of eu.ggnet.dwoss.rights.ee.entity.Operator in project dwoss by gg-net.
the class RightsGeneratorOperation method make.
/**
* Generate a operator with all supplied parameters.
*
* @param password the password
* @param quickLoginKey a quicklogin key
* @param username the username and password
* @param activeRights the active rights to use
* @return the persisted operator.
*/
public Operator make(String username, String password, int quickLoginKey, Collection<AtomicRight> activeRights) {
Operator operator = new Operator();
operator.setUsername(username);
operator.setQuickLoginKey(0);
operator.setSalt(RandomStringUtils.randomAlphanumeric(6).getBytes());
operator.setPassword(AuthenticationBean.hashPassword(Objects.requireNonNull(password.toCharArray()), operator.getSalt()));
for (AtomicRight right : activeRights) {
operator.add(right);
}
em.persist(operator);
return operator;
}
use of eu.ggnet.dwoss.rights.ee.entity.Operator in project dwoss by gg-net.
the class AuthenticationBean method login.
/**
* This method returns a {@link Set} of {@link AtomicRight}'s when the {@link Operator} is authorized or throw a {@link UserInfoException} when username
* and/or password is wrong.
* <p>
* @param username the username of the {@link Operator}.
* @param password the password of the {@link Operator}.
* @return {@link Operator} with {@link AtomicRight}'s when the {@link Operator} is authorized.
* @throws UserInfoException is thrown when username and/or password is wrong.
*/
@Override
public eu.ggnet.dwoss.rights.api.Operator login(String username, char[] password) throws UserInfoException {
L.info("Authentication request(user={})", username);
// find users by Username
List<Operator> result = rightsEm.createNamedQuery("Operator.byUsername", Operator.class).setParameter(1, username).getResultList();
if (result.isEmpty())
throw new UserInfoException("User " + username + " ist noch nicht angelegt");
Operator op = result.get(0);
if (!service.isAmbiguous() && !service.isUnsatisfied()) {
if (service.get().authenticate(username, password)) {
eu.ggnet.dwoss.rights.api.Operator login = op.toDto();
L.info("Authentication successful: {}", login);
return login;
}
} else {
if (op.getPassword() != null && op.getSalt() != null && Arrays.equals(op.getPassword(), hashPassword(password, op.getSalt()))) {
eu.ggnet.dwoss.rights.api.Operator login = op.toDto();
L.info("Authentication successful: {}", login);
return login;
}
}
L.info("Authentication denied");
throw new UserInfoException("Authentifizierung nicht gelungen!");
}
use of eu.ggnet.dwoss.rights.ee.entity.Operator in project dwoss by gg-net.
the class AuthenticatorTestIT method testMakeOperatorAndAuthenticate.
/**
* Test of make method, of class RightsGeneratorOperation.
*/
@Test
public void testMakeOperatorAndAuthenticate() {
String password = "xxx123yyy";
String username = "user";
Operator o = rightsGenerator.make(username, password, 0, new ArrayList<>());
List<Operator> operators = agent.findAll(Operator.class);
assertThat(operators).describedAs("Operators of database").hasSize(1);
assertThat(operators.get(0).getId()).describedAs("OperatorId").isEqualTo(o.getId());
try {
authentication.login(username, password.toCharArray());
} catch (UserInfoException ex) {
fail("Authentication failed:" + ex.getMessage());
}
}
use of eu.ggnet.dwoss.rights.ee.entity.Operator in project dwoss by gg-net.
the class RightsManagmentController method handleAddPersonaButton.
@FXML
private void handleAddPersonaButton() {
Operator op = userlist.getSelectionModel().getSelectedItem();
List<Persona> selectedItems = new ArrayList<>(deactivePersonas.getSelectionModel().getSelectedItems());
op.addAllPersona(selectedItems);
resetDeactivePersonas();
resetDeactiveRights();
resetAllRights();
// setSelectedOperator(op);
Dl.remote().lookup(RightsAgent.class).store(op);
}
Aggregations