Search in sources :

Example 6 with Protector

use of com.evolveum.midpoint.prism.crypto.Protector in project midpoint by Evolveum.

the class PageMyPasswordQuestions method createUsersSecurityQuestionsList.

public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
    LOGGER.debug("Security Questions Loading for user: " + user.getOid());
    if (user.asObjectable().getCredentials() != null && user.asObjectable().getCredentials().getSecurityQuestions() != null) {
        List<SecurityQuestionAnswerType> secQuestAnsList = user.asObjectable().getCredentials().getSecurityQuestions().getQuestionAnswer();
        if (secQuestAnsList != null) {
            LOGGER.debug("User SecurityQuestion ANswer List is Not null");
            List<SecurityQuestionAnswerDTO> secQuestAnswListDTO = new ArrayList<SecurityQuestionAnswerDTO>();
            for (Iterator iterator = secQuestAnsList.iterator(); iterator.hasNext(); ) {
                SecurityQuestionAnswerType securityQuestionAnswerType = (SecurityQuestionAnswerType) iterator.next();
                Protector protector = getPrismContext().getDefaultProtector();
                String decoded = "";
                if (securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
                    try {
                        decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());
                    } catch (EncryptionException e) {
                        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't decrypt user answer", e);
                    }
                }
                //LOGGER.debug("SecAnswerIdentifier:"+securityQuestionAnswerType.getQuestionIdentifier());
                secQuestAnswListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
            }
            return secQuestAnswListDTO;
        }
    }
    return null;
}
Also used : SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) SecurityQuestionAnswerType(com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Example 7 with Protector

use of com.evolveum.midpoint.prism.crypto.Protector in project midpoint by Evolveum.

the class UserMenuPanel method createUsersSecurityQuestionsList.

public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
    SecurityQuestionsCredentialsType credentialsPolicyType = user.asObjectable().getCredentials().getSecurityQuestions();
    if (credentialsPolicyType == null) {
        return null;
    }
    List<SecurityQuestionAnswerType> secQuestAnsList = credentialsPolicyType.getQuestionAnswer();
    if (secQuestAnsList != null) {
        List<SecurityQuestionAnswerDTO> secQuestAnswListDTO = new ArrayList<SecurityQuestionAnswerDTO>();
        for (Iterator iterator = secQuestAnsList.iterator(); iterator.hasNext(); ) {
            SecurityQuestionAnswerType securityQuestionAnswerType = (SecurityQuestionAnswerType) iterator.next();
            Protector protector = ((PageBase) getPage()).getPrismContext().getDefaultProtector();
            if (securityQuestionAnswerType.getQuestionAnswer() != null && securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
                try {
                    String decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());
                    secQuestAnswListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
                } catch (EncryptionException e) {
                    // TODO do we need to thrown exception here?
                    LOGGER.error("Could not get security questions. Error: " + e.getMessage(), e);
                    continue;
                }
            }
        }
        return secQuestAnswListDTO;
    } else {
        return null;
    }
}
Also used : SecurityQuestionAnswerDTO(com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Example 8 with Protector

use of com.evolveum.midpoint.prism.crypto.Protector in project midpoint by Evolveum.

the class AbstractScriptTest method setupFactory.

@BeforeClass
public void setupFactory() {
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    ObjectResolver resolver = new DirectoryFileObjectResolver(OBJECTS_DIR);
    Protector protector = new ProtectorImpl();
    Collection<FunctionLibrary> functions = new ArrayList<FunctionLibrary>();
    functions.add(FunctionLibraryUtil.createBasicFunctionLibrary(prismContext, protector));
    scriptExpressionfactory = new ScriptExpressionFactory(resolver, prismContext, protector);
    scriptExpressionfactory.setFunctions(functions);
    evaluator = createEvaluator(prismContext, protector);
    String languageUrl = evaluator.getLanguageUrl();
    System.out.println("Expression test for " + evaluator.getLanguageName() + ": registering " + evaluator + " with URL " + languageUrl);
    scriptExpressionfactory.registerEvaluator(languageUrl, evaluator);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) ObjectResolver(com.evolveum.midpoint.schema.util.ObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.test.util.DirectoryFileObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.test.util.DirectoryFileObjectResolver) ArrayList(java.util.ArrayList) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl) Protector(com.evolveum.midpoint.prism.crypto.Protector) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with Protector

use of com.evolveum.midpoint.prism.crypto.Protector in project midpoint by Evolveum.

the class TestScriptCaching method setupFactory.

@BeforeClass
public void setupFactory() {
    System.out.println("Setting up expression factory and evaluator");
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    ObjectResolver resolver = new DirectoryFileObjectResolver(OBJECTS_DIR);
    Protector protector = new ProtectorImpl();
    Collection<FunctionLibrary> functions = new ArrayList<FunctionLibrary>();
    functions.add(FunctionLibraryUtil.createBasicFunctionLibrary(prismContext, protector));
    scriptExpressionfactory = new ScriptExpressionFactory(resolver, prismContext, protector);
    scriptExpressionfactory.setFunctions(functions);
    evaluator = new Jsr223ScriptEvaluator("groovy", prismContext, protector);
    String languageUrl = evaluator.getLanguageUrl();
    scriptExpressionfactory.registerEvaluator(languageUrl, evaluator);
}
Also used : Jsr223ScriptEvaluator(com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator) ObjectResolver(com.evolveum.midpoint.schema.util.ObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.test.util.DirectoryFileObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.test.util.DirectoryFileObjectResolver) ArrayList(java.util.ArrayList) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl) Protector(com.evolveum.midpoint.prism.crypto.Protector) BeforeClass(org.testng.annotations.BeforeClass)

Example 10 with Protector

use of com.evolveum.midpoint.prism.crypto.Protector in project midpoint by Evolveum.

the class TestExpressionFunctions method createBasicFunctions.

private BasicExpressionFunctions createBasicFunctions() throws SchemaException, SAXException, IOException {
    PrismContext prismContext = PrismTestUtil.createInitializedPrismContext();
    Protector protector = new ProtectorImpl();
    return new BasicExpressionFunctions(prismContext, protector);
}
Also used : BasicExpressionFunctions(com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions) PrismContext(com.evolveum.midpoint.prism.PrismContext) ProtectorImpl(com.evolveum.midpoint.prism.crypto.ProtectorImpl) Protector(com.evolveum.midpoint.prism.crypto.Protector)

Aggregations

Protector (com.evolveum.midpoint.prism.crypto.Protector)10 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)5 PrismContext (com.evolveum.midpoint.prism.PrismContext)4 ProtectorImpl (com.evolveum.midpoint.prism.crypto.ProtectorImpl)4 ArrayList (java.util.ArrayList)4 SecurityQuestionAnswerDTO (com.evolveum.midpoint.web.page.admin.home.dto.SecurityQuestionAnswerDTO)3 FunctionLibrary (com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary)2 TestProtector (com.evolveum.midpoint.prism.crypto.TestProtector)2 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)2 ObjectResolver (com.evolveum.midpoint.schema.util.ObjectResolver)2 DirectoryFileObjectResolver (com.evolveum.midpoint.test.util.DirectoryFileObjectResolver)2 SecurityQuestionAnswerType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionAnswerType)2 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)2 Iterator (java.util.Iterator)2 BeforeClass (org.testng.annotations.BeforeClass)2 Test (org.testng.annotations.Test)2 BasicExpressionFunctions (com.evolveum.midpoint.model.common.expression.functions.BasicExpressionFunctions)1 Jsr223ScriptEvaluator (com.evolveum.midpoint.model.common.expression.script.jsr223.Jsr223ScriptEvaluator)1 SecurityQuestionsCredentialsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType)1 KeyStore (java.security.KeyStore)1