Package org.structr.core.entity

Examples of org.structr.core.entity.Principal


      logger.log(Level.SEVERE, "This command needs a principalId");
      getWebSocket().send(MessageBuilder.status().code(400).build(), true);

    }

    Principal principal = (Principal) getNode(principalId);

    if (principal == null) {

      logger.log(Level.SEVERE, "No principal found with id {0}", new Object[]{principalId});
      getWebSocket().send(MessageBuilder.status().code(400).build(), true);
View Full Code Here


  }

  private void authenticate(final String sessionId) {

    Principal user = AuthHelper.getPrincipalForSessionId(sessionId);

    if (user != null) {

      this.setAuthenticated(sessionId, user);
    }
View Full Code Here

  }

  public boolean isAuthenticated() {

    final Principal user = getCurrentUser();
    return (user != null && (user.getProperty(Principal.isAdmin) || user.getProperty(User.backendUser)));

  }
View Full Code Here

    boolean existingUser = false;

    if (propertySet.containsKey(User.eMail.jsonName())) {

      final Principal user;

      final String emailString  = (String) propertySet.get(User.eMail.jsonName());

      if (StringUtils.isEmpty(emailString)) {
        return new RestMethodResult(HttpServletResponse.SC_BAD_REQUEST);
      }

      localeString = (String) propertySet.get(MailTemplate.locale.jsonName());
      confKey = UUID.randomUUID().toString();

      Result result = StructrApp.getInstance().nodeQuery(User.class).and(User.eMail, emailString).getResult();
      if (!result.isEmpty()) {

        final App app = StructrApp.getInstance(securityContext);
        user = (Principal) result.get(0);

        // For existing users, update confirmation key
        user.setProperty(User.confirmationKey, confKey);

        existingUser = true;


      } else {
View Full Code Here

   * @param userClass
   * @return user
   */
  public static Principal createUser(final SecurityContext securityContext, final PropertyKey credentialKey, final String credentialValue, final Map<String, Object> propertySet, final boolean autoCreate, final Class userClass) {

    Principal user = null;

    try {

      // First, search for a person with that e-mail address
      user = AuthHelper.getPrincipalForCredential(credentialKey, credentialValue);

      if (user != null) {

        user = new NodeFactory<Principal>(securityContext).instantiate(user.getNode());

        // convert to user
        user.unlockReadOnlyPropertiesOnce();
        user.setProperty(AbstractNode.type, User.class.getSimpleName());
        user.setProperty(User.confirmationKey, confKey);

      } else if (autoCreate) {

        // Clear properties set by us from the user-defined props
        propertySet.remove(credentialKey.jsonName());
View Full Code Here

    String emailOrUsername = StringUtils.isNotEmpty(email) ? email : name;

    if (StringUtils.isNotEmpty(emailOrUsername) && StringUtils.isNotEmpty(password)) {

      Principal user = (Principal) securityContext.getAuthenticator().doLogin(securityContext.getRequest(), emailOrUsername, password);

      if (user != null) {

        logger.log(Level.INFO, "Login successfull: {0}", new Object[]{ user });
View Full Code Here

      }

      // special keyword "me"
      if ("me".equals(part)) {

        Principal me = (Principal) securityContext.getUser(false);

        if (me != null) {

          _data = me;
View Full Code Here

  @Override
  public void processMessage(WebSocketMessage webSocketData) {

    final String username = (String) webSocketData.getNodeData().get("username");
    final String password = (String) webSocketData.getNodeData().get("password");
    Principal user;

    if ((username != null) && (password != null)) {

      try {

        StructrWebSocket socket = this.getWebSocket();
        Authenticator auth = socket.getAuthenticator();

        user = auth.doLogin(socket.getRequest(), username, password);

        if (user != null) {

          final String sessionId = webSocketData.getSessionId();
          if (sessionId == null) {

            logger.log(Level.INFO, "Could not login {0}: No sessionId found", new Object[]{username, password});
            getWebSocket().send(MessageBuilder.status().code(403).build(), true);

          }

          // Clear possible existing sessions
          AuthHelper.clearSession(sessionId);

          user.addSessionId(sessionId);

          // store token in response data
          webSocketData.getNodeData().clear();
          webSocketData.setSessionId(sessionId);
          webSocketData.getNodeData().put("username", user.getProperty(AbstractNode.name));

          // authenticate socket
          this.getWebSocket().setAuthenticated(sessionId, user);

          // send data..
View Full Code Here

  }
 
  public T execute(PropertyMap attributes) throws FrameworkException {

    GraphDatabaseService graphDb = (GraphDatabaseService) arguments.get("graphDb");
    Principal user               = securityContext.getUser(false);
    T node                       = null;

    if (graphDb != null) {

      Date now                            = new Date();

      // Determine node type
      PropertyMap properties     = new PropertyMap(attributes);
      Object typeObject          = properties.get(AbstractNode.type);
      Class nodeType             = typeObject != null ? SchemaHelper.getEntityClassForRawType(typeObject.toString()) : StructrApp.getConfiguration().getFactoryDefinition().getGenericNodeType();
      NodeFactory<T> nodeFactory = new NodeFactory<>(securityContext);
      boolean isCreation         = true;

      // Create node with type
      node = (T) nodeFactory.instantiateWithType(graphDb.createNode(), nodeType, isCreation);
      if(node != null) {
       
        TransactionCommand.nodeCreated(node);

        // set type
        if (nodeType != null) {
         
          node.unlockReadOnlyPropertiesOnce();
          node.setProperty(GraphObject.type, nodeType.getSimpleName());
        }

        // set UUID
        node.unlockReadOnlyPropertiesOnce();
        node.setProperty(GraphObject.id, getNextUuid());

        // set created date
        node.unlockReadOnlyPropertiesOnce();
        node.setProperty(AbstractNode.createdDate, now);

        // set last modified date
        node.unlockReadOnlyPropertiesOnce();
        node.setProperty(AbstractNode.lastModifiedDate, now);

        // properties.remove(AbstractNode.type);
       
        if ((user != null) && user instanceof AbstractNode) {

          // Create new relationship to user and grant permissions to user or group
          Principal owner = (Principal)user;

          App app = StructrApp.getInstance(securityContext);
         
          app.create(owner, (NodeInterface)node, PrincipalOwnsNode.class);
         
View Full Code Here

      }

      // special keyword "me"
      if ("me".equals(part)) {

        Principal me = (Principal) securityContext.getUser(false);

        if (me != null) {

          _data = me;
View Full Code Here

TOP

Related Classes of org.structr.core.entity.Principal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.