Search in sources :

Example 1 with ISResponseData

use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData in project perun by CESNET.

the class MuPasswordManagerModuleTest method changePassword.

@Test
public void changePassword() throws Exception {
    ISResponseData okResponseData = new ISResponseData();
    okResponseData.setStatus(IS_OK_STATUS);
    when(isServiceCallerMock.call(anyString(), anyInt())).thenReturn(okResponseData);
    module.checkPasswordStrength(sess, null, "randomPassword2.");
}
Also used : ISResponseData(cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 2 with ISResponseData

use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData in project perun by CESNET.

the class MuPasswordManagerModuleTest method generatedPasswordContainsOnlyAllowedChars.

@Test
public void generatedPasswordContainsOnlyAllowedChars() throws Exception {
    ISResponseData okResponseData = new ISResponseData();
    okResponseData.setStatus(IS_OK_STATUS);
    when(isServiceCallerMock.call(anyString(), anyInt())).thenReturn(okResponseData);
    // test that password does not contain any invalid character
    Assert.assertFalse(MUPasswordContainsNotAllowedChars.matcher(module.generateRandomPassword(sess, null)).matches());
}
Also used : ISResponseData(cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 3 with ISResponseData

use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData in project perun by CESNET.

the class MuPasswordManagerModuleTest method generatedPasswordHasValidLength.

@Test
public void generatedPasswordHasValidLength() throws Exception {
    ISResponseData okResponseData = new ISResponseData();
    okResponseData.setStatus(IS_OK_STATUS);
    when(isServiceCallerMock.call(anyString(), anyInt())).thenReturn(okResponseData);
    Assert.assertEquals(module.generateRandomPassword(sess, null).length(), randomPasswordLength);
}
Also used : ISResponseData(cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with ISResponseData

use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData in project perun by CESNET.

the class MuPasswordManagerModule method changePasswordWithoutCheck.

private void changePasswordWithoutCheck(PerunSession sess, String login, String password) throws PasswordStrengthException {
    try {
        int requestID = (new Random()).nextInt(1000000) + 1;
        String requestBody = getPwdChangeRequest(sess, login, password, requestID);
        // if error, throws exception, otherwise it's ok
        ISResponseData responseData = isServiceCaller.call(requestBody, requestID);
        if (IS_ERROR_STATUS.equals(responseData.getStatus())) {
            throw new PasswordStrengthException(responseData.getError());
        }
    } catch (IOException e) {
        throw new InternalErrorException(e);
    }
}
Also used : ISResponseData(cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData) Random(java.util.Random) SecureRandom(java.security.SecureRandom) IOException(java.io.IOException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordStrengthException(cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException)

Example 5 with ISResponseData

use of cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData in project perun by CESNET.

the class MuPasswordManagerModule method generateAccount.

@Override
public Map<String, String> generateAccount(PerunSession session, Map<String, String> parameters) throws PasswordStrengthException {
    if (parameters.get(PASSWORD_KEY) != null && !parameters.get(PASSWORD_KEY).isEmpty()) {
        checkPasswordStrength(session, "--not yet known--", parameters.get(PASSWORD_KEY));
    } else {
        parameters.put(PASSWORD_KEY, generateRandomPassword(session, "--not yet known--"));
    }
    try {
        int requestID = (new Random()).nextInt(1000000) + 1;
        String requestBody = getGenerateAccountRequest(session, parameters, requestID);
        ISResponseData responseData = isServiceCaller.call(requestBody, requestID);
        if (!IS_OK_STATUS.equals(responseData.getStatus())) {
            throw new InternalErrorException("IS MU (password manager backend) responded with error to a Request ID: " + requestID + " Error: " + responseData.getError());
        }
        return parseUCO(responseData.getResponse(), requestID);
    } catch (IOException e) {
        throw new InternalErrorException(e);
    }
}
Also used : ISResponseData(cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData) Random(java.util.Random) SecureRandom(java.security.SecureRandom) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) IOException(java.io.IOException)

Aggregations

ISResponseData (cz.metacentrum.perun.core.implApi.modules.pwdmgr.ISResponseData)7 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)4 Test (org.junit.Test)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)3 IOException (java.io.IOException)3 SecureRandom (java.security.SecureRandom)2 Random (java.util.Random)2 IllegalArgumentException (cz.metacentrum.perun.core.api.exceptions.IllegalArgumentException)1 PasswordStrengthException (cz.metacentrum.perun.core.api.exceptions.PasswordStrengthException)1 StringReader (java.io.StringReader)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XPathFactory (javax.xml.xpath.XPathFactory)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1