Search in sources :

Example 11 with IUser

use of com.helger.photon.security.user.IUser in project phoss-smp by phax.

the class BusinessCardServerAPI method createBusinessCard.

@Nonnull
public ESuccess createBusinessCard(@Nonnull final String sServiceGroupID, @Nonnull final PDBusinessCard aBusinessCard, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /businesscard/" + sServiceGroupID;
    final String sAction = "createBusinessCard";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aBusinessCard);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        // Parse and validate identifier
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
        if (aServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sServiceGroupID, m_aAPIProvider.getCurrentURI());
        }
        final IParticipantIdentifier aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aBusinessCard.getParticipantIdentifier().getScheme(), aBusinessCard.getParticipantIdentifier().getValue());
        if (!aServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
            // Business identifiers must be equal
            throw new SMPBadRequestException("Participant Inconsistency. The URL points to '" + aServiceGroupID.getURIEncoded() + "' whereas the BusinessCard contains '" + aPayloadServiceGroupID.getURIEncoded() + "'", m_aAPIProvider.getCurrentURI());
        }
        // Retrieve the service group
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aServiceGroupID);
        if (aServiceGroup == null) {
            // No such service group (on this server)
            throw new SMPNotFoundException("Unknown serviceGroup '" + sServiceGroupID + "'", m_aAPIProvider.getCurrentURI());
        }
        // Check credentials and verify service group is owned by provided user
        final IUser aSMPUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aServiceGroupID, aSMPUser);
        final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
        if (aBusinessCardMgr == null) {
            throw new SMPBadRequestException("This SMP server does not support the BusinessCard API", m_aAPIProvider.getCurrentURI());
        }
        final ICommonsList<SMPBusinessCardEntity> aEntities = new CommonsArrayList<>();
        for (final PDBusinessEntity aEntity : aBusinessCard.businessEntities()) aEntities.add(SMPBusinessCardEntity.createFromGenericObject(aEntity));
        if (aBusinessCardMgr.createOrUpdateSMPBusinessCard(aServiceGroup.getParticipantIdentifier(), aEntities) == null) {
            if (LOGGER.isWarnEnabled())
                LOGGER.warn(sLog + " ERROR");
            STATS_COUNTER_ERROR.increment(sAction);
            return ESuccess.FAILURE;
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return ESuccess.SUCCESS;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPBusinessCardEntity(com.helger.phoss.smp.domain.businesscard.SMPBusinessCardEntity) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) IUser(com.helger.photon.security.user.IUser) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 12 with IUser

use of com.helger.photon.security.user.IUser in project peppol-practical by phax.

the class AjaxExecutorCommentAdd method handleRequest.

public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
    final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
    final String sCommentThreadID = aRequestScope.params().getAsString(PARAM_COMMENT_THREAD_ID);
    final String sCommentID = aRequestScope.params().getAsString(PARAM_COMMENT_ID);
    String sAuthor = aRequestScope.params().getAsString(PARAM_AUTHOR);
    final String sTitle = aRequestScope.params().getAsString(PARAM_TITLE);
    final String sText = aRequestScope.params().getAsString(PARAM_TEXT);
    // Get info on current user
    final IUser aCurrentUser = LoggedInUserManager.getInstance().getCurrentUser();
    final String sCurrentUserID = aCurrentUser != null ? aCurrentUser.getID() : null;
    if (aCurrentUser != null)
        sAuthor = aCurrentUser.getDisplayName();
    if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && StringHelper.hasText(sCommentThreadID) && StringHelper.hasText(sCommentID) && CommentSecurity.canCurrentUserPostComments()) {
        // Create a dummy object
        final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
        final ICommentThread aCommentThread = CommentThreadManager.getInstance().getCommentThreadOfID(aOwner, sCommentThreadID);
        if (aCommentThread != null) {
            final IComment aParentComment = aCommentThread.getCommentOfID(sCommentID);
            if (aParentComment != null) {
                final CommentFormErrors aFormErrors = CommentFormErrors.createForReply(aCommentThread, aParentComment);
                if (StringHelper.hasNoText(sAuthor)) {
                    // No author provided
                    aFormErrors.addFieldError(PARAM_AUTHOR, ECommentText.MSG_ERR_COMMENT_NO_AUTHOR.getDisplayText(aDisplayLocale));
                }
                if (StringHelper.hasNoText(sText)) {
                    // No text provided
                    aFormErrors.addFieldError(PARAM_TEXT, ECommentText.MSG_ERR_COMMENT_NO_TEXT.getDisplayText(aDisplayLocale));
                }
                IHCNode aMessageBox = null;
                if (aFormErrors.isEmpty()) {
                    // Go ahead and save
                    final ESuccess eSuccess = CommentThreadManager.getInstance().addCommentToThread(aOwner, sCommentThreadID, sCommentID, new Comment(aRequestScope.getRemoteHost(), ECommentState.APPROVED, sCurrentUserID, sAuthor, sTitle, sText));
                    if (eSuccess.isSuccess())
                        aMessageBox = success(ECommentText.MSG_COMMENT_SAVE_SUCCESS.getDisplayText(aDisplayLocale));
                    else
                        aMessageBox = error(ECommentText.MSG_COMMENT_SAVE_FAILURE.getDisplayText(aDisplayLocale));
                }
                // List of exiting comments + message box
                aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createForComment(ECommentAction.ADD_COMMENT, aCommentThread, aParentComment), aFormErrors, aMessageBox, true));
                return;
            }
        }
    }
    // Somebody played around with the API
    LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "' for adding to comment '" + sCommentID + "' in thread '" + sCommentThreadID + "'");
    aAjaxResponse.createNotFound();
}
Also used : Locale(java.util.Locale) ESuccess(com.helger.commons.state.ESuccess) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ObjectType(com.helger.commons.type.ObjectType) CommentFormErrors(com.helger.peppol.comment.ui.CommentFormErrors) IComment(com.helger.peppol.comment.domain.IComment) Comment(com.helger.peppol.comment.domain.Comment) IComment(com.helger.peppol.comment.domain.IComment) IUser(com.helger.photon.security.user.IUser) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) IHCNode(com.helger.html.hc.IHCNode)

Example 13 with IUser

use of com.helger.photon.security.user.IUser in project peppol-practical by phax.

the class AjaxExecutorCommentCreateThread method handleRequest.

public void handleRequest(@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final PhotonUnifiedResponse aAjaxResponse) throws Exception {
    final LayoutExecutionContext aLEC = LayoutExecutionContext.createForAjaxOrAction(aRequestScope);
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final String sObjectType = aRequestScope.params().getAsString(PARAM_OBJECT_TYPE);
    final String sObjectID = aRequestScope.params().getAsString(PARAM_OBJECT_ID);
    String sAuthor = aRequestScope.params().getAsString(PARAM_AUTHOR);
    final String sTitle = aRequestScope.params().getAsString(PARAM_TITLE);
    final String sText = aRequestScope.params().getAsString(PARAM_TEXT);
    // Get info on current user
    final IUser aCurrentUser = LoggedInUserManager.getInstance().getCurrentUser();
    final String sCurrentUserID = aCurrentUser != null ? aCurrentUser.getID() : null;
    if (aCurrentUser != null)
        sAuthor = aCurrentUser.getDisplayName();
    if (StringHelper.hasText(sObjectType) && StringHelper.hasText(sObjectID) && CommentSecurity.canCurrentUserPostComments()) {
        // Create a dummy object
        final ITypedObject<String> aOwner = TypedObject.create(new ObjectType(sObjectType), sObjectID);
        final CommentFormErrors aFormErrors = CommentFormErrors.createForNewThread();
        if (StringHelper.hasNoText(sAuthor)) {
            // No author provided
            aFormErrors.addFieldError(PARAM_AUTHOR, ECommentText.MSG_ERR_COMMENT_NO_AUTHOR.getDisplayText(aDisplayLocale));
        }
        if (StringHelper.hasNoText(sText)) {
            // No text provided
            aFormErrors.addFieldError(PARAM_TEXT, ECommentText.MSG_ERR_COMMENT_NO_TEXT.getDisplayText(aDisplayLocale));
        }
        IHCNode aMessageBox = null;
        if (aFormErrors.isEmpty()) {
            // Go ahead and save
            final ICommentThread aNewThread = CommentThreadManager.getInstance().createNewThread(aOwner, new Comment(aRequestScope.getRemoteHost(), ECommentState.APPROVED, sCurrentUserID, sAuthor, sTitle, sText));
            if (aNewThread != null)
                aMessageBox = success(ECommentText.MSG_COMMENT_SAVE_SUCCESS.getDisplayText(aDisplayLocale));
            else
                aMessageBox = error(ECommentText.MSG_COMMENT_SAVE_FAILURE.getDisplayText(aDisplayLocale));
        }
        // List of exiting comments + message box
        aAjaxResponse.html(CommentUI.getCommentList(aLEC, aOwner, CommentAction.createGeneric(ECommentAction.CREATE_THREAD), aFormErrors, aMessageBox, true));
        return;
    }
    // Somebody played around with the API
    LOGGER.warn("Failed to resolve comment object type '" + sObjectType + "' and/or object ID '" + sObjectID + "'");
    aAjaxResponse.createNotFound();
}
Also used : Locale(java.util.Locale) LayoutExecutionContext(com.helger.photon.core.execcontext.LayoutExecutionContext) ObjectType(com.helger.commons.type.ObjectType) CommentFormErrors(com.helger.peppol.comment.ui.CommentFormErrors) Comment(com.helger.peppol.comment.domain.Comment) IUser(com.helger.photon.security.user.IUser) IHCNode(com.helger.html.hc.IHCNode) ICommentThread(com.helger.peppol.comment.domain.ICommentThread)

Example 14 with IUser

use of com.helger.photon.security.user.IUser in project peppol-practical by phax.

the class LayoutAreaContentProviderSecure method _getNavbar.

@Nonnull
private static IHCNode _getNavbar(@Nonnull final LayoutExecutionContext aLEC) {
    final Locale aDisplayLocale = aLEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    final ISimpleURL aLinkToStartPage = aLEC.getLinkToMenuItem(aLEC.getMenuTree().getDefaultMenuItemID());
    final BootstrapNavbar aNavbar = new BootstrapNavbar();
    aNavbar.addBrand(new HCNodeList().addChild(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO1).addChild(AppHelper.getApplicationTitle())).addChild(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO2).addChild(" Administration")), aLinkToStartPage);
    final BootstrapNavbarToggleable aToggleable = aNavbar.addAndReturnToggleable();
    final IUser aUser = LoggedInUserManager.getInstance().getCurrentUser();
    aToggleable.addAndReturnText().addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2).addChild("Welcome ").addChild(new HCStrong().addChild(SecurityHelper.getUserDisplayName(aUser, aDisplayLocale)));
    aToggleable.addChild(new BootstrapButton().setOnClick(LinkHelper.getURLWithContext(AbstractPublicApplicationServlet.SERVLET_DEFAULT_PATH)).addChild("Public area").addClass(CBootstrapCSS.MX_2));
    aToggleable.addChild(new BootstrapButton().setOnClick(LinkHelper.getURLWithContext(aRequestScope, LogoutServlet.SERVLET_DEFAULT_PATH)).addChild(EPhotonCoreText.LOGIN_LOGOUT.getDisplayText(aDisplayLocale)).addClass(CBootstrapCSS.MX_2));
    return aNavbar;
}
Also used : Locale(java.util.Locale) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCSpan(com.helger.html.hc.html.textlevel.HCSpan) HCStrong(com.helger.html.hc.html.textlevel.HCStrong) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapNavbar(com.helger.photon.bootstrap4.navbar.BootstrapNavbar) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapNavbarToggleable(com.helger.photon.bootstrap4.navbar.BootstrapNavbarToggleable) IUser(com.helger.photon.security.user.IUser) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Nonnull(javax.annotation.Nonnull)

Example 15 with IUser

use of com.helger.photon.security.user.IUser in project peppol-practical by phax.

the class AppCommonUI method getDTAndUser.

@Nullable
public static IHCNode getDTAndUser(@Nonnull final IWebPageExecutionContext aWPEC, @Nullable final LocalDateTime aDateTime, @Nullable final String sUserID) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    String sDateTime = null;
    if (aDateTime != null)
        sDateTime = PDTToString.getAsString(aDateTime, aDisplayLocale);
    IHCNode aUserName = null;
    if (sUserID != null) {
        final IUser aUser = PhotonSecurityManager.getUserMgr().getUserOfID(sUserID);
        aUserName = createViewLink(aWPEC, aUser);
    }
    if (sDateTime != null) {
        if (aUserName != null) {
            // Date and user
            return new HCNodeList().addChildren(new HCTextNode("on " + sDateTime + " by "), aUserName);
        }
        // Date only
        return new HCTextNode("on  " + sDateTime);
    }
    if (aUserName != null) {
        // User only
        return new HCNodeList().addChildren(new HCTextNode("by "), aUserName);
    }
    // Neither nor
    return null;
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) IUser(com.helger.photon.security.user.IUser) PDTToString(com.helger.commons.datetime.PDTToString) HCTextNode(com.helger.html.hc.impl.HCTextNode) IHCNode(com.helger.html.hc.IHCNode) Nullable(javax.annotation.Nullable)

Aggregations

IUser (com.helger.photon.security.user.IUser)44 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)25 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)22 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)20 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)19 Nonnull (javax.annotation.Nonnull)18 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)17 Locale (java.util.Locale)14 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)11 IRequestWebScopeWithoutResponse (com.helger.web.scope.IRequestWebScopeWithoutResponse)9 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)8 HCStrong (com.helger.html.hc.html.textlevel.HCStrong)7 HCNodeList (com.helger.html.hc.impl.HCNodeList)7 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)7 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)7 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)7 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)7 IUserManager (com.helger.photon.security.user.IUserManager)7 IMicroDocument (com.helger.xml.microdom.IMicroDocument)6