Search in sources :

Example 1 with GuiProfiledPrincipal

use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.

the class WebPrismUtil method createAcquition.

public static ProvenanceAcquisitionType createAcquition() {
    MidPointApplication app = MidPointApplication.get();
    ProvenanceAcquisitionType acquisitionType = new ProvenanceAcquisitionType(app.getPrismContext());
    GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
    if (principal != null) {
        FocusType focus = principal.getFocus();
        if (focus != null) {
            acquisitionType.setActorRef(ObjectTypeUtil.createObjectRef(focus, app.getPrismContext()));
        }
    }
    acquisitionType.setChannel(GuiChannel.USER.getUri());
    acquisitionType.setTimestamp(app.getClock().currentTimeXMLGregorianCalendar());
    return acquisitionType;
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ProvenanceAcquisitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProvenanceAcquisitionType) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)

Example 2 with GuiProfiledPrincipal

use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.

the class UserMenuPanel method loadJpegPhotoModel.

private IModel<AbstractResource> loadJpegPhotoModel() {
    return new ReadOnlyModel<>(() -> {
        GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
        if (principal == null) {
            return null;
        }
        CompiledGuiProfile profile = principal.getCompiledGuiProfile();
        byte[] jpegPhoto = profile.getJpegPhoto();
        if (jpegPhoto == null) {
            URL placeholder = UserMenuPanel.class.getClassLoader().getResource("static/img/placeholder.png");
            if (placeholder == null) {
                return null;
            }
            try {
                jpegPhoto = IOUtils.toByteArray(placeholder);
            } catch (IOException e) {
                LOGGER.error("Cannot load placeholder for photo.");
                return null;
            }
        }
        return new ByteArrayResource("image/jpeg", jpegPhoto);
    });
}
Also used : ReadOnlyModel(com.evolveum.midpoint.gui.api.model.ReadOnlyModel) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) IOException(java.io.IOException) ByteArrayResource(org.apache.wicket.request.resource.ByteArrayResource) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile) URL(java.net.URL)

Example 3 with GuiProfiledPrincipal

use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.

the class TaskOperationalButtonsPanel method setupOwner.

private void setupOwner(PrismObjectWrapper<TaskType> taskWrapper) throws SchemaException {
    PrismReferenceWrapper<Referencable> taskOwner = taskWrapper.findReference(ItemPath.create(TaskType.F_OWNER_REF));
    if (taskOwner == null) {
        return;
    }
    PrismReferenceValueWrapperImpl<Referencable> taskOwnerValue = taskOwner.getValue();
    if (taskOwnerValue == null) {
        return;
    }
    if (taskOwnerValue.getNewValue() == null || taskOwnerValue.getNewValue().isEmpty()) {
        GuiProfiledPrincipal guiPrincipal = AuthUtil.getPrincipalUser();
        if (guiPrincipal == null) {
            // BTW something very strange must happened
            return;
        }
        FocusType focus = guiPrincipal.getFocus();
        taskOwnerValue.setRealValue(ObjectTypeUtil.createObjectRef(focus, SchemaConstants.ORG_DEFAULT));
    }
}
Also used : Referencable(com.evolveum.midpoint.prism.Referencable) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)

Example 4 with GuiProfiledPrincipal

use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.

the class WebComponentUtil method getLocale.

public static <F extends FocusType> Locale getLocale() {
    MidPointPrincipal principal = AuthUtil.getPrincipalUser();
    if (principal == null) {
        return MidPointApplication.getDefaultLocale();
    }
    Locale locale = null;
    if (principal instanceof GuiProfiledPrincipal && ((GuiProfiledPrincipal) principal).getCompiledGuiProfile().getLocale() != null) {
        locale = ((GuiProfiledPrincipal) principal).getCompiledGuiProfile().getLocale();
    } else {
        F focus = (F) principal.getFocus();
        if (focus == null) {
            return MidPointApplication.getDefaultLocale();
        }
        String prefLang = focus.getPreferredLanguage();
        if (StringUtils.isBlank(prefLang)) {
            prefLang = focus.getLocale();
        }
        try {
            locale = LocaleUtils.toLocale(prefLang);
        } catch (Exception ex) {
            LOGGER.debug("Error occurred while getting user locale, " + ex.getMessage());
        }
    }
    if (locale == null) {
        if (ThreadContext.getSession() == null) {
            return MidPointApplication.getDefaultLocale();
        }
        locale = Session.get().getLocale();
    }
    if (MidPointApplication.containsLocale(locale)) {
        return locale;
    }
    return MidPointApplication.getDefaultLocale();
}
Also used : GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) InvocationTargetException(java.lang.reflect.InvocationTargetException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 5 with GuiProfiledPrincipal

use of com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal in project midpoint by Evolveum.

the class WebModelServiceUtils method getTimezone.

public static TimeZone getTimezone() {
    GuiProfiledPrincipal principal = AuthUtil.getPrincipalUser();
    if (principal == null) {
        return null;
    }
    FocusType focus = principal.getFocus();
    String timeZone;
    if (focus == null || StringUtils.isEmpty(focus.getTimezone())) {
        timeZone = principal.getCompiledGuiProfile().getDefaultTimezone();
    } else {
        timeZone = focus.getTimezone();
    }
    if (timeZone == null) {
        return null;
    }
    try {
        return TimeZone.getTimeZone(timeZone);
    } catch (Exception ex) {
        LOGGER.debug("Error occurred while getting user time zone, " + ex.getMessage());
        return null;
    }
}
Also used : GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) RestartResponseException(org.apache.wicket.RestartResponseException)

Aggregations

GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)17 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ConnectionEnvironment (com.evolveum.midpoint.security.api.ConnectionEnvironment)3 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)3 Authentication (org.springframework.security.core.Authentication)3 AuthenticationException (org.springframework.security.core.AuthenticationException)3 CompiledGuiProfile (com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)2 EncryptionException (com.evolveum.midpoint.prism.crypto.EncryptionException)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ArrayList (java.util.ArrayList)2 SessionInformation (org.springframework.security.core.session.SessionInformation)2 TerminateSessionEvent (com.evolveum.midpoint.TerminateSessionEvent)1 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)1 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)1 AuthenticationEvaluatorImpl (com.evolveum.midpoint.authentication.impl.evaluator.AuthenticationEvaluatorImpl)1 MailNonceAuthenticationToken (com.evolveum.midpoint.authentication.impl.module.authentication.token.MailNonceAuthenticationToken)1 SecurityQuestionsAuthenticationToken (com.evolveum.midpoint.authentication.impl.module.authentication.token.SecurityQuestionsAuthenticationToken)1 ReadOnlyModel (com.evolveum.midpoint.gui.api.model.ReadOnlyModel)1