Search in sources :

Example 1 with UserAgentImpl

use of i5.las2peer.security.UserAgentImpl in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method getSubscribers.

@Override
public SpaceSubscribersList getSubscribers(String spaceId) throws ServiceInvocationException {
    if (spaceId == null || spaceId.isEmpty()) {
        throw new InvocationBadArgumentException("No space id given");
    }
    try {
        UserAgentImpl inviteAgent = this.getInviteAgent(spaceId);
        GroupAgent memberAgent = this.getMemberAgent(spaceId);
        memberAgent.unlock(Context.get().getMainAgent());
        String[] memberIds = memberAgent.getMemberList();
        SpaceSubscribersList subscribers = new SpaceSubscribersList();
        for (int i = 0; i < memberIds.length; i++) {
            if (!memberIds[i].equals(inviteAgent.getIdentifier())) {
                UserAgentImpl agent = (UserAgentImpl) Context.get().fetchAgent(memberIds[i]);
                NoracleAgentProfile profile = new NoracleAgentProfile();
                profile.setName(agent.getLoginName());
                subscribers.add(profile);
            }
        }
        return subscribers;
    } catch (Exception e) {
        throw new ServiceInvocationException("Could not fetch list", e);
    }
}
Also used : NoracleAgentProfile(i5.las2peer.services.noracleService.model.NoracleAgentProfile) UserAgentImpl(i5.las2peer.security.UserAgentImpl) SpaceSubscribersList(i5.las2peer.services.noracleService.model.SpaceSubscribersList) 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 2 with UserAgentImpl

use of i5.las2peer.security.UserAgentImpl in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method getInviteAgent.

private UserAgentImpl getInviteAgent(String spaceId) throws AgentNotFoundException, AgentOperationFailedException, EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException {
    String inviteAgentEnvelopeId = getInviteMappingIdentifier(spaceId);
    Envelope inviteAgentMapping = Context.get().requestEnvelope(inviteAgentEnvelopeId);
    String inviteAgentId = (String) inviteAgentMapping.getContent();
    UserAgentImpl inviteAgent = (UserAgentImpl) Context.get().fetchAgent(inviteAgentId);
    return inviteAgent;
}
Also used : Envelope(i5.las2peer.api.persistency.Envelope) UserAgentImpl(i5.las2peer.security.UserAgentImpl)

Example 3 with UserAgentImpl

use of i5.las2peer.security.UserAgentImpl 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)

Aggregations

UserAgentImpl (i5.las2peer.security.UserAgentImpl)3 EnvelopeAccessDeniedException (i5.las2peer.api.persistency.EnvelopeAccessDeniedException)2 EnvelopeNotFoundException (i5.las2peer.api.persistency.EnvelopeNotFoundException)2 EnvelopeOperationFailedException (i5.las2peer.api.persistency.EnvelopeOperationFailedException)2 SerializationException (i5.las2peer.serialization.SerializationException)2 CryptoException (i5.las2peer.tools.CryptoException)2 Envelope (i5.las2peer.api.persistency.Envelope)1 NoracleAgentProfile (i5.las2peer.services.noracleService.model.NoracleAgentProfile)1 SpaceSubscribersList (i5.las2peer.services.noracleService.model.SpaceSubscribersList)1