private void setUpUser() throws Exception { user = new User(); user.setFirstName(userFirstName); user.setMiddleName(""); user.setLastName(userLastName); user.setTitleBefore(""); user.setTitleAfter(""); assertNotNull(perun.getUsersManagerBl().createUser(sess, user)); // create new user in database usersForDeletion.add(user); // save user for deletion after testing }
public Attributes getAllUsersAttributes(User user) { Object o = ldapTemplate.lookup( getUserDN(String.valueOf(user.getId())), new UserAttributesContextMapper()); Attributes attrs = null; if (o != null) attrs = (Attributes) o; return attrs; }
public void deleteUser(User user) throws InternalErrorException { try { ldapTemplate.unbind(getUserDN(String.valueOf(user.getId()))); log.debug("Entry deleted from LDAP: User {}.", user); } catch (NameNotFoundException e) { throw new InternalErrorException(e); } }
// -------------------------------------------------------------------------- // --------------------------BEANS CREATORS--------------------------------- private static User createUser(Map<String, String> beanAttr) { if (beanAttr == null) return null; User user = new User(); user.setId(Integer.valueOf(beanAttr.get("id")).intValue()); user.setTitleBefore(BeansUtils.eraseEscaping(beanAttr.get("titleBefore"))); user.setTitleAfter(BeansUtils.eraseEscaping(beanAttr.get("titleAfter"))); user.setFirstName(BeansUtils.eraseEscaping(beanAttr.get("firstName"))); user.setLastName(BeansUtils.eraseEscaping(beanAttr.get("lastName"))); user.setMiddleName(BeansUtils.eraseEscaping(beanAttr.get("middleName"))); user.setServiceUser(Boolean.valueOf(beanAttr.get("serviceAccount")).booleanValue()); return user; }
public boolean userExist(User user) { Object o = null; try { o = ldapTemplate.lookup( getUserDN(String.valueOf(user.getId())), new UserPerunUserIdContextMapper()); } catch (NameNotFoundException ex) { return false; } return true; }
public boolean isUserMemberOfGroup(PerunSession sess, User user, Group group) throws InternalErrorException { try { return 1 <= jdbc.queryForInt( "select count(1) from groups_members join members on members.id = member_id where members.user_id=? and groups_members.group_id=?", user.getId(), group.getId()); } catch (RuntimeException ex) { throw new InternalErrorException(ex); } }
public boolean userPasswordExists(User user) { Object o = ldapTemplate.lookup( getUserDN(String.valueOf(user.getId())), new UserAttributesContextMapper()); Attributes attrs = null; if (o != null) attrs = (Attributes) o; if (attrs != null) { Attribute a = attrs.get("userPassword"); if (a != null) return true; } return false; }
public boolean userAttributeExist(User user, String ldapAttributeName) throws InternalErrorException { if (ldapAttributeName == null) throw new InternalErrorException("ldapAttributeName can't be null."); Object o = null; try { setLdapAttributeName(ldapAttributeName); o = ldapTemplate.lookup( getUserDN(String.valueOf(user.getId())), new UserPerunUserAttributeContextMapper()); } catch (NameNotFoundException ex) { return false; } if (o == null) return false; return true; }
private User setUpUser1() throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException { User user = new User(); user.setFirstName("James"); user.setMiddleName(""); user.setLastName("Bond"); user.setTitleBefore(""); user.setTitleAfter(""); return perun.getUsersManagerBl().createUser(session, user); }
public void createUser(User user) throws InternalErrorException { // Create a set of attributes Attributes attributes = new BasicAttributes(); // Create the objectclass to add Attribute objClasses = new BasicAttribute("objectClass"); objClasses.add("top"); objClasses.add("person"); objClasses.add("organizationalPerson"); objClasses.add("inetOrgPerson"); objClasses.add("perunUser"); objClasses.add("tenOperEntry"); objClasses.add("inetUser"); String firstName = user.getFirstName(); String lastName = user.getLastName(); if (firstName == null) firstName = ""; if (lastName == null || lastName.isEmpty()) lastName = "N/A"; // Add attributes attributes.put(objClasses); attributes.put("entryStatus", "active"); attributes.put("sn", lastName); attributes.put("cn", firstName + " " + lastName); if (!firstName.isEmpty()) attributes.put("givenName", firstName); attributes.put("perunUserId", String.valueOf(user.getId())); if (user.isServiceUser()) attributes.put("isServiceUser", "1"); else attributes.put("isServiceUser", "0"); if (user.isSponsoredUser()) attributes.put("isSponsoredUser", "1"); else attributes.put("isSponsoredUser", "0"); // Create the entry try { ldapTemplate.bind(getUserDN(String.valueOf(user.getId())), null, attributes); log.debug("New entry created in LDAP: User {} in Group with Id=" + user.getId() + ".", user); } catch (NameNotFoundException e) { throw new InternalErrorException(e); } }
@Override public List<UserExtSource> consolidateIdentityUsingToken(PerunSession sess, String token) throws PerunException { Map<String, Object> originalIdentity = requestCache.get(token); if (originalIdentity == null) { throw new InvalidTokenException( "Your token for joining identities is no longer valid. Please retry from the start."); } User originalUser = (User) originalIdentity.get("user"); User currentUser = sess.getPerunPrincipal().getUser(); if (originalUser == null && currentUser == null) { IdentityUnknownException ex = new IdentityUnknownException( "Neither original or current identity is know to Perun. Please use at least one identity known to Perun."); ex.setLogin((String) originalIdentity.get("actor")); ex.setSource2((String) originalIdentity.get("extSourceName")); ex.setSourceType2((String) originalIdentity.get("extSourceType")); ex.setLogin2(sess.getPerunPrincipal().getActor()); ex.setSource2(sess.getPerunPrincipal().getExtSourceName()); ex.setSourceType2(sess.getPerunPrincipal().getExtSourceType()); throw ex; } if (originalIdentity.get("extSourceName").equals(sess.getPerunPrincipal().getExtSourceName()) && originalIdentity.get("actor").equals(sess.getPerunPrincipal().getActor()) && originalIdentity .get("extSourceType") .equals(sess.getPerunPrincipal().getExtSourceType())) { IdentityIsSameException ex = new IdentityIsSameException( "You tried to join same identity with itself. Please try again but select different identity."); ex.setLogin(sess.getPerunPrincipal().getActor()); ex.setSource(sess.getPerunPrincipal().getExtSourceName()); ex.setSourceType(sess.getPerunPrincipal().getExtSourceType()); throw ex; } if (originalUser != null && currentUser != null && originalUser.equals(currentUser)) { throw new IdentitiesAlreadyJoinedException("You already have both identities joined."); } if (originalUser != null && currentUser != null && !originalUser.equals(currentUser)) { throw new IdentityAlreadyInUseException( "Your identity is already associated with a different user. If you are really the same person, please contact support to help you.", originalUser, currentUser); } // merge original identity into current user if (originalUser == null) { createExtSourceAndUserExtSource( currentUser, (String) originalIdentity.get("actor"), (String) originalIdentity.get("extSourceName"), (String) originalIdentity.get("extSourceType"), (Integer) originalIdentity.get("extSourceLoa")); } // merge current identity into original user if (currentUser == null) { createExtSourceAndUserExtSource( originalUser, sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getExtSourceName(), sess.getPerunPrincipal().getExtSourceType(), sess.getPerunPrincipal().getExtSourceLoa()); } AuthzResolverBlImpl.refreshSession(sess); requestCache.remove(token); return perun.getUsersManager().getUserExtSources(sess, sess.getPerunPrincipal().getUser()); }
public void updateUser(User user, ModificationItem[] modificationItems) { this.updateUserWithUserId(String.valueOf(user.getId()), modificationItems); }