Search in sources :

Example 11 with ServiceAccessDeniedException

use of i5.las2peer.api.execution.ServiceAccessDeniedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleAgentService method updateAgentProfile.

@Override
public NoracleAgentProfile updateAgentProfile(String agentName) throws ServiceInvocationException {
    Agent mainAgent = Context.get().getMainAgent();
    String envIdentifier = buildAgentProfileId(mainAgent.getIdentifier());
    Envelope env;
    NoracleAgentProfile profile;
    // look for existing profile, otherwise create one
    try {
        try {
            env = Context.get().requestEnvelope(envIdentifier);
            profile = (NoracleAgentProfile) env.getContent();
        } catch (EnvelopeNotFoundException e) {
            env = Context.get().createEnvelope(envIdentifier);
            profile = new NoracleAgentProfile();
        }
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope access denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not create new envelope for noracle agent profile", e);
    }
    profile.setName(agentName);
    env.setContent(profile);
    env.setPublic();
    try {
        Context.get().storeEnvelope(env, mainAgent);
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope access denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Storing envelope with noracle agent profile failed", e);
    }
    return profile;
}
Also used : AnonymousAgent(i5.las2peer.api.security.AnonymousAgent) Agent(i5.las2peer.api.security.Agent) NoracleAgentProfile(i5.las2peer.services.noracleService.model.NoracleAgentProfile) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope)

Example 12 with ServiceAccessDeniedException

use of i5.las2peer.api.execution.ServiceAccessDeniedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method joinSpace.

public void joinSpace(String spaceId, String spaceSecret) throws ServiceInvocationException {
    if (spaceId == null || spaceId.isEmpty()) {
        throw new InvocationBadArgumentException("No space id given");
    } else if (spaceSecret == null || spaceSecret.isEmpty()) {
        throw new ServiceAccessDeniedException("No space secret given");
    }
    try {
        UserAgentImpl inviteAgent = this.getInviteAgent(spaceId);
        inviteAgent.unlock(spaceSecret);
        GroupAgent memberAgent = this.getMemberAgent(spaceId);
        memberAgent.unlock(inviteAgent);
        memberAgent.addMember(Context.get().getMainAgent());
        Context.get().storeAgent(memberAgent);
    } catch (AgentAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Could not unlock agent", e);
    } catch (Exception e) {
        throw new ServiceInvocationException("Could not join space", e);
    }
}
Also used : UserAgentImpl(i5.las2peer.security.UserAgentImpl) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) CryptoException(i5.las2peer.tools.CryptoException) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) SerializationException(i5.las2peer.serialization.SerializationException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException)

Example 13 with ServiceAccessDeniedException

use of i5.las2peer.api.execution.ServiceAccessDeniedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method getSpace.

@Override
public Space getSpace(String spaceId) throws ServiceInvocationException {
    if (spaceId == null || spaceId.isEmpty()) {
        throw new InvocationBadArgumentException("No space id given");
    }
    Envelope env;
    try {
        env = Context.get().requestEnvelope(getSpaceEnvelopeIdentifier(spaceId));
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Access Denied", e);
    } catch (EnvelopeNotFoundException e) {
        throw new ResourceNotFoundException("Space Not Found", e);
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not deserialize space object", e);
    }
    Space space = (Space) env.getContent();
    return space;
}
Also used : Space(i5.las2peer.services.noracleService.model.Space) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope)

Example 14 with ServiceAccessDeniedException

use of i5.las2peer.api.execution.ServiceAccessDeniedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleQuestionRelationService method getQuestionRelation.

@Override
public QuestionRelation getQuestionRelation(String relationId) throws ServiceInvocationException {
    if (relationId == null || relationId.isEmpty()) {
        throw new InvocationBadArgumentException("No relation id given");
    }
    Envelope env;
    try {
        env = Context.get().requestEnvelope(getQuestionRelationEnvelopeIdentifier(relationId));
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not fetch relation envelope", e);
    } catch (EnvelopeNotFoundException e) {
        throw new ResourceNotFoundException("Relation Not Found");
    }
    QuestionRelation relation = (QuestionRelation) env.getContent();
    return relation;
}
Also used : EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) QuestionRelation(i5.las2peer.services.noracleService.model.QuestionRelation) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope)

Aggregations

EnvelopeAccessDeniedException (i5.las2peer.api.persistency.EnvelopeAccessDeniedException)14 EnvelopeOperationFailedException (i5.las2peer.api.persistency.EnvelopeOperationFailedException)14 Envelope (i5.las2peer.api.persistency.Envelope)13 EnvelopeNotFoundException (i5.las2peer.api.persistency.EnvelopeNotFoundException)12 Agent (i5.las2peer.api.security.Agent)6 AnonymousAgent (i5.las2peer.api.security.AnonymousAgent)6 Question (i5.las2peer.services.noracleService.model.Question)4 QuestionRelation (i5.las2peer.services.noracleService.model.QuestionRelation)3 SpaceSubscription (i5.las2peer.services.noracleService.model.SpaceSubscription)3 SpaceSubscriptionList (i5.las2peer.services.noracleService.model.SpaceSubscriptionList)3 ServiceNameVersion (i5.las2peer.api.p2p.ServiceNameVersion)2 Space (i5.las2peer.services.noracleService.model.Space)2 InternalServiceException (i5.las2peer.api.execution.InternalServiceException)1 InvocationBadArgumentException (i5.las2peer.api.execution.InvocationBadArgumentException)1 ServiceAccessDeniedException (i5.las2peer.api.execution.ServiceAccessDeniedException)1 ServiceInvocationException (i5.las2peer.api.execution.ServiceInvocationException)1 UserAgentImpl (i5.las2peer.security.UserAgentImpl)1 SerializationException (i5.las2peer.serialization.SerializationException)1 NoracleAgentProfile (i5.las2peer.services.noracleService.model.NoracleAgentProfile)1 Vote (i5.las2peer.services.noracleService.model.Vote)1