@Override public int compareTo(PerunBean perunBean) { if(perunBean == null) throw new NullPointerException("PerunBean to compare with is null."); if(perunBean instanceof ExtSource) { ExtSource extSource = (ExtSource) perunBean; int compare; //Compare on last Name if (this.getName()== null && extSource.getName() != null) compare = -1; else if (extSource.getName() == null && this.getName() != null) compare = 1; else if (this.getName() == null && extSource.getName() == null) compare = 0; else compare = this.getName().compareToIgnoreCase(extSource.getName()); if(compare != 0) return compare; //Compare on type if (this.getType()== null && extSource.getType() != null) compare = -1; else if (extSource.getType() == null && this.getType() != null) compare = 1; else if (this.getType()== null && extSource.getType() == null) compare = 0; else compare = this.getType().compareToIgnoreCase(extSource.getType()); if(compare != 0) return compare; //Compare to id if not return (this.getId() - perunBean.getId()); } else { return (this.getId() - perunBean.getId()); } } }
private static ExtSource createExtSource(Map<String, String> beanAttr) { if(beanAttr==null) return null; ExtSource extSource = new ExtSource(); extSource.setId(Integer.valueOf(beanAttr.get("id"))); extSource.setName(BeansUtils.eraseEscaping(beanAttr.get("name"))); extSource.setType(BeansUtils.eraseEscaping(beanAttr.get("type"))); return extSource; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !getClass().equals(o.getClass())) return false; UserExtSource that = (UserExtSource) o; if (login != null ? !login.equals(that.login) : that.login != null) return false; if (extSource != null ? !extSource.equals(that.extSource) : that.extSource != null) return false; return true; }
for (UserExtSource ues : u.getUserExtSources()) { if (ues.getExtSource().getType().equals(ExtSourcesManagerEntry.EXTSOURCE_X509)) { es.add(ues.getExtSource()); } else if (ues.getExtSource().getType().equals(ExtSourcesManagerEntry.EXTSOURCE_IDP)) { if (ues.getExtSource().getName().equals("https://extidp.cesnet.cz/idp/shibboleth")) { ues.getExtSource().setName("https://extidp.cesnet.cz/idp/shibboleth&authnContextClassRef=urn:cesnet:extidp:authn:"+type); if (uesAttr.getValue() != null && !((String) uesAttr.getValue()).isEmpty()) { ues.getExtSource().setId(0); ues.getExtSource().setName((String) uesAttr.getValue()); } else if (ues.getExtSource().getType().equals(ExtSourcesManagerEntry.EXTSOURCE_KERBEROS)) { es.add(ues.getExtSource());
for(UserExtSource ues: userExtSources) { if(ues != null && ues.getExtSource() != null) { String type = ues.getExtSource().getType(); if(type != null) { if(type.equals(ExtSourcesManager.EXTSOURCE_IDP)) {
for (UserExtSource es : ues) { if (es.getExtSource().getName().equalsIgnoreCase("LDAPMU")) { } else if (es.getExtSource().getName().equalsIgnoreCase("https://idp2.ics.muni.cz/idp/shibboleth")){ authorId = es.getLogin().substring(0, es.getLogin().indexOf("@")); // get only UCO from UCO@mail.muni.cz break;
/** * Creates ExtSource and UserExtSource if necessary for the purpose of joining users identities. * * @param user User to add UES to * @param actor Actor to add * @param extSourceName ExtSource name to add * @param extSourceType ExtSource type to add * @param loa loa in ext source * @return created UserExtSource * @throws PerunException when anything fails */ private UserExtSource createExtSourceAndUserExtSource(User user, String actor, String extSourceName, String extSourceType, int loa) throws PerunException { ExtSource extSource = new ExtSource(extSourceName, extSourceType); try { extSource = perun.getExtSourcesManagerBl().getExtSourceByName(registrarSession, extSourceName); } catch (ExtSourceNotExistsException ex) { extSource = perun.getExtSourcesManager().createExtSource(registrarSession, extSource, null); } UserExtSource ues = new UserExtSource(); ues.setLogin(actor); ues.setLoa(loa); ues.setExtSource(extSource); return perun.getUsersManager().addUserExtSource(registrarSession, user, ues); }
@Override public int compareTo(PerunBean perunBean) { if(perunBean == null) throw new NullPointerException("PerunBean to compare with is null."); if(perunBean instanceof UserExtSource) { UserExtSource userExtSource = (UserExtSource) perunBean; int compare; //Compare on extSource if (this.getExtSource() == null && userExtSource.getExtSource() != null) compare = -1; else if (userExtSource.getExtSource() == null && this.getExtSource() != null) compare = 1; else if (this.getExtSource() == null && userExtSource.getExtSource() == null) compare = 0; else compare = this.getExtSource().compareTo(userExtSource.getExtSource()); if(compare != 0) return compare; //Compare on login if (this.getLogin()== null && userExtSource.getLogin() != null) compare = -1; else if (userExtSource.getLogin() == null && this.getLogin() != null) compare = 1; else if (this.getLogin()== null && userExtSource.getLogin() == null) compare = 0; else compare = this.getLogin().compareToIgnoreCase(userExtSource.getLogin()); if(compare != 0) return compare; //Compare to id if not return (this.getId() - perunBean.getId()); } else { return (this.getId() - perunBean.getId()); } } }
if(this.userExtSource.getExtSource() != null && this.userExtSource.getExtSource().getType() != null) { String extLogin; if(this.userExtSource.getExtSource().getType().equals(ExtSourcesManager.EXTSOURCE_IDP)) { extLogin = this.userExtSource.getLogin(); if(extLogin == null) extLogin = ""; if(this.userExtSource.getExtSource() != null && this.userExtSource.getExtSource().getType() != null) { String extLogin; if(this.userExtSource.getExtSource().getType().equals(ExtSourcesManager.EXTSOURCE_IDP)) { extLogin = this.userExtSource.getLogin(); if(extLogin == null) extLogin = "";
@Override public void canBeApproved(PerunSession session, Application app) throws PerunException { // check if submitted from trusted IdP if (!Objects.equals("https://www.structuralbiology.eu/idp/shibboleth", app.getExtSourceName())) { // submitted by untrusted IdP PerunBl perun = (PerunBl) session.getPerun(); User user = null; // check if user is known if (app.getUser() != null) { user = app.getUser(); } else { try { user = perun.getUsersManagerBl().getUserByExtSourceNameAndExtLogin(session, app.getExtSourceName(), app.getCreatedBy()); } catch (Exception ex) { // unable to find user -> untrusted IdP throw new CantBeApprovedException("Application can't be approved automatically. User doesn't have identity from \"www.structuralbiology.eu\". Please check users identity before manual/force approval.", "", "", "", true); } } List<UserExtSource> ueses = perun.getUsersManagerBl().getUserExtSources(session, user); for (UserExtSource ues : ueses) { if (Objects.equals("https://www.structuralbiology.eu/idp/shibboleth", ues.getExtSource().getName())) { // user has trusted identity return; } } throw new CantBeApprovedException("Application can't be approved automatically. User doesn't have identity from \"www.structuralbiology.eu\". Please check users identity before manual/force approval.", "", "", "", true); } // submitted from trusted IdP }
@Override public String serializeToString() { StringBuilder str = new StringBuilder(); return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", name=<").append(getName() == null ? "\\0" : BeansUtils.createEscaping(getName())).append(">").append( ", type=<").append(getType() == null ? "\\0" : BeansUtils.createEscaping(getType())).append(">").append( ']').toString(); }