public SSOUser newUser(String name, Long domainId) { SSOUserImpl user = new SSOUserImpl(); user.setDomainId(domainId); user.setName(name); return user; }
public SSOClient getClient(SSOSite site, SSOUser remoteUser) throws SSOException { PasswordCredential pwdCred = getCredentials(remoteUser); return new SSOClientImpl(site,pwdCred); }
public void configFormAuthentication(String formUserField, String formPwdField) { this.isFormAuthentication = true; this.setChallengeResponseAuthentication(false); this.formPwdField = formPwdField; this.formUserField = formUserField; }
public SSOUser addUser(SSOSite site, JetspeedPrincipal ownerPrincipal, String ssoUsername, String ssoUserPassword) throws SSOException { SSOUser newUser = null; try{ // step 1. create new SSO user newUser = ssoUserManagerSPI.addUser(ssoUsername, site.getSecurityDomainId(), ownerPrincipal); // step 2. store new user's credentials setPassword(newUser, ssoUserPassword); // step 3. relate owner to SSO user addAssociation(newUser, ownerPrincipal); } catch (SecurityException secex){ // revert changes, if applicable if (newUser != null){ removeUser(newUser); } throw new SSOException("Unable to add new SSO User "+ssoUsername,secex); } return newUser; }
public SSOSite addSite(SSOSite site) throws SSOException { return this.addSite(getDefaultDomainId(), site); }
public static String unscramble(String pwd) { byte[] bytes = pwd.getBytes(); bytes = Base64.decodeBase64(bytes); String chars = new String(bytes); String unscrambled = new String(xor(chars.toCharArray(), scrambler)); return unscrambled; }
@SuppressWarnings("unchecked") public Collection<SSOSite> getSitesForPrincipal(JetspeedPrincipal localPrincipal) throws SSOException { Collection<SSOSite> sitesFound = null; if (localPrincipal != null){ Collection<SSOUser> ssoUsers = getRemoteUsers(localPrincipal); if (ssoUsers != null && ssoUsers.size() > 0){ sitesFound = ssoSiteManagerSPI.getSites(ssoUsers); } } return sitesFound != null ? sitesFound : Collections.EMPTY_SET; }
public boolean login() throws SSOException { GetMethod get = new GetMethod(site.getURL().toString()); int status = login(get); get.releaseConnection(); return status >= 200 && status < 300; }
site.getRealm(), url.getHost(), new UsernamePasswordCredentials(credential.getUserName(), SSOUtils.unscramble(credential.getPassword())) ); siteURL.append("?").append(site.getFormUserField()).append("=").append(credential.getUserName()).append("&").append(site.getFormPwdField()).append("=").append(SSOUtils.unscramble(credential.getPassword()));
public SSOSite newSite(String name, String url){ return new SSOSiteImpl(name,url); }
public String get(String destUrl, boolean refreshProxy) throws SSOException { StringWriter sw = new StringWriter(); write(destUrl,refreshProxy,sw); return sw.toString(); }
public Collection<SSOSite> getSitesForSubject(Subject subject) throws SSOException { Map<Integer,SSOSite> siteIdToSite = new HashMap<Integer,SSOSite>(); for (Principal p : subject.getPrincipals()){ if (p instanceof JetspeedPrincipal){ try { Collection<SSOSite> sitesForThisPrincipal = getSitesForPrincipal((JetspeedPrincipal)p); for (SSOSite site : sitesForThisPrincipal) { if (!siteIdToSite.containsKey(site.getId())){ siteIdToSite.put(site.getId(), site); } } } catch (SSOException se){ } } } return siteIdToSite.values(); }
String ruPassword = SSOUtils.scramble(ruCredential.getPassword()); JSSSOSiteRemoteUser siteRemoteUser = new JSSSOSiteRemoteUser(); siteRemoteUser.setPrincipalName(rupName);
public static String scramble(String pwd) { // xor-ing persistent String values is dangerous because of the (uncommon) way Java encodes UTF-8 0x00 (and some other characters). // See: http://en.wikipedia.org/wiki/UTF-8#Java // On some database platforms, like PostgreSQL this can lead to something like: // org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00 // To prevent this, the resulting xored password is encoded in Base64 String xored = new String(xor(pwd.toCharArray(), scrambler)); byte[] bytes = Base64.encodeBase64(xored.getBytes()); String scrambled = new String(bytes); return scrambled; }
public Collection<SSOUser> getRemoteUsers(SSOSite site, Subject subject) throws SSOException { Map<Long,SSOUser> resultUsers = new HashMap<Long,SSOUser>(); for (Principal p : subject.getPrincipals()){ if (p instanceof JetspeedPrincipal){ try{ Collection<SSOUser> usersForThisPrincipal = getRemoteUsers(site,(JetspeedPrincipal)p); for (SSOUser user : usersForThisPrincipal) { if (!resultUsers.containsKey(user.getId())){ resultUsers.put(user.getId(), user); } } } catch (SSOException se){ throw new SSOException(se); } } } return resultUsers.values(); }
ssoManager.addUser(s, principal, rName, SSOUtils.unscramble(rPassword));