Skip to content

Commit cf2032c

Browse files
authored
Merge pull request #1198 from WilliamFromTW/master
New Setting "Default Language" when creating user
2 parents 526b385 + 2e68cb6 commit cf2032c

File tree

12 files changed

+239
-41
lines changed

12 files changed

+239
-41
lines changed

.classpath

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<classpathentry kind="lib" path="ext/httpcore-4.3.3.jar" sourcepath="ext/src/httpcore-4.3.3.jar" />
5050
<classpathentry kind="lib" path="ext/commons-logging-1.1.3.jar" sourcepath="ext/src/commons-logging-1.1.3.jar" />
5151
<classpathentry kind="lib" path="ext/commons-codec-1.7.jar" sourcepath="ext/src/commons-codec-1.7.jar" />
52-
<classpathentry kind="lib" path="ext/org.eclipse.jdt.annotation-1.1.0.jar" />
52+
<classpathentry kind="lib" path="ext/org.eclipse.jdt.annotation-1.1.0.jar" sourcepath="ext/src/org.eclipse.jdt.annotation-1.1.0.jar" />
5353
<classpathentry kind="lib" path="ext/org.eclipse.jgit.http.server-4.1.1.201511131810-r.jar" sourcepath="ext/src/org.eclipse.jgit.http.server-4.1.1.201511131810-r.jar" />
5454
<classpathentry kind="lib" path="ext/bcprov-jdk15on-1.52.jar" sourcepath="ext/src/bcprov-jdk15on-1.52.jar" />
5555
<classpathentry kind="lib" path="ext/bcmail-jdk15on-1.52.jar" sourcepath="ext/src/bcmail-jdk15on-1.52.jar" />
@@ -94,10 +94,5 @@
9494
<classpathentry kind="lib" path="ext/mockito-core-1.10.19.jar" sourcepath="ext/src/mockito-core-1.10.19.jar" />
9595
<classpathentry kind="lib" path="ext/objenesis-2.1.jar" sourcepath="ext/src/objenesis-2.1.jar" />
9696
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
97-
<classpathentry kind="src" path="src/main/dagger">
98-
<attributes>
99-
<attribute name="optional" value="true"/>
100-
</attributes>
101-
</classpathentry>
10297
<classpathentry kind="output" path="bin/classes" />
10398
</classpath>

gitblit.iml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,9 @@
491491
<root url="jar://$MODULE_DIR$/ext/org.eclipse.jdt.annotation-1.1.0.jar!/" />
492492
</CLASSES>
493493
<JAVADOC />
494-
<SOURCES />
494+
<SOURCES>
495+
<root url="jar://$MODULE_DIR$/ext/src/org.eclipse.jdt.annotation-1.1.0.jar!/" />
496+
</SOURCES>
495497
</library>
496498
</orderEntry>
497499
<orderEntry type="module-library">
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
********************************************************************************
2+
Gitblit 伺服器 $serverHostname 所需之 SSL 用戶端憑證
3+
********************************************************************************
4+
5+
$userDisplayname 您好,
6+
7+
伺服器 $serverHostname 所需要的私鑰,公鑰以及Gitblit簽證檔案(CA)存放於 $username.p12, PKCS#12 certificate store[1] 以及 $username.pem.
8+
9+
兩種證書皆受密碼保護.
10+
密碼提示: $storePasswordHint
11+
12+
13+
Git 憑證匯入步驟
14+
=============================================
15+
16+
附件之 PEM 檔案可以直接匯入至您的git程式裡.
17+
18+
git config [--global] http.sslCert path/to/$username.pem
19+
20+
PEM檔案受密碼保護,因此匯入過程會提示多次. 如果您偏好不使用密碼,您需要另外匯出無密碼之私鑰後,再匯入git程式裡.
21+
22+
openssl rsa -in path/to/$username.pem -out path/to/$username.key
23+
git config [--global] http.sslKey path/to/$username.key
24+
25+
此外,您應該妥善保管已經解除密碼保護之私鑰.
26+
27+
註:
28+
如果沒有匯出私鑰, 有些早期git版本將會發生匯入失敗問題,例如:Ubuntu 12.04 with git 1.7.9.5.
29+
30+
31+
Firefox 憑證匯入步驟
32+
=============================================
33+
34+
Firefox 有自己的證書管理介面.
35+
36+
1. 點選 "選項->進階->憑證"
37+
2. 點選 "檢視憑證清單"
38+
3. 切換至 "您的憑證"
39+
4. 點選 "匯入(M)"
40+
5. 選擇電腦中的憑證檔案 $username.p12
41+
6. 輸入憑證檔案所需的密碼
42+
7. 切換至"憑證機構"
43+
8. 找到 "Gitblit Certificate Authority" 憑證
44+
9. 點選"編輯信任(E)"
45+
10.選擇信任網站.
46+
47+
48+
Chrome/IE (Windows) 憑證匯入步驟
49+
=============================================
50+
51+
在Windows作業系統下, Chrome 與 IE 共用相同的憑證設定.
52+
53+
IE
54+
------------------------------------
55+
1. 選擇 "網際網路選項->內容"
56+
2. 點選"憑證"
57+
58+
Chrome
59+
------------------------------------
60+
1. 選擇 "設定->顯示進階設定->HTTP/SSL"
61+
2. 點選"管理憑證"
62+
63+
共同步驟 (Windows)
64+
------------------------------------
65+
3. 切換至 "個人"
66+
4. 點選"匯入(I)"
67+
5. 依照指示匯入.
68+
請切換匯入檔案類型為p12並且找到 $username.p12 這個憑證檔案
69+
6. 輸入憑證檔案保護密碼
70+
7. 由於主要發放憑證單位(CA)與個人憑證檔案皆儲存於 $username.p12, 因此匯入時候,必須選擇 "自動根據憑證類型來選擇憑證存放區".
71+
如果選擇預設值匯入, 將不會安裝主要發放憑證單位(CA)
72+
73+
74+
Chrome (Linux) Installation Instructions
75+
=============================================
76+
77+
On Linux, Chrome maintains it's own certificate store.
78+
79+
1. Navigate to Settings->Show Advanced Settings->HTTP/SSL
80+
2. Click the "Manage Certificates..." button
81+
3. Navigate your filesystem and select $username.p12
82+
4. At the password prompt enter the certificate store password
83+
You have now imported your private key, public certificate, and the CA certificate
84+
but now we must manually set the trust settings of the CA certificate.
85+
5. Switch to the "Authorities" tab
86+
6. Scroll down and find "Gitblit-> Gitblit Certificate Authority"
87+
7. Select it and click "Edit Trust..."
88+
8. Check "This certificate can identify websites" and click OK.
89+
90+
91+
Chrome/Safari (Mac OS X) Installation Instructions
92+
=============================================
93+
94+
On Mac OS X, Chrome and Safari both use Keychain Access to store certificates
95+
so configuring one will automatically apply for both.
96+
97+
1. Double-click $username.pem
98+
2. At the password prompt enter the certificate store password
99+
You have now imported your private key, public certificate, and the CA certificate
100+
but now we must manually set the trust settings of the CA certificate.
101+
3. Find the Gitblit Certificate Authority certificate, it should have a red
102+
indicator meaning untrusted, and double-click it.
103+
4. Open the "Trust" disclosure triangle and change "When using this certificate"
104+
to "Always Trust".
105+
5. Close the certificate view and enter your system password to save the changes
106+
to your keychain.
107+
108+
109+
[1] PKCS#12 is one of the standard container formats for sharing private keys and
110+
public certificates.
111+
[2] http://www.openssl.org
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$userDisplayname 您好
2+
3+
伺服器 $serverHostname 所需要的私鑰,公鑰以及Gitblit簽證檔案(CA)已經全部打包並且以zip壓縮檔方式寄給您.
4+
5+
此外,檔案還附上各瀏覽器設定步驟供您參考.

src/main/java/com/gitblit/authority/GitblitAuthority.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
import java.util.Date;
4949
import java.util.HashMap;
5050
import java.util.List;
51+
import java.util.Locale;
5152
import java.util.Map;
53+
import java.util.ResourceBundle;
5254

5355
import javax.mail.Message;
5456
import javax.swing.ImageIcon;
@@ -98,6 +100,7 @@
98100
import com.gitblit.utils.X509Utils.RevocationReason;
99101
import com.gitblit.utils.X509Utils.X509Log;
100102
import com.gitblit.utils.X509Utils.X509Metadata;
103+
import com.gitblit.wicket.GitBlitWebSession;
101104

102105
/**
103106
* Simple GUI tool for administering Gitblit client certificates.
@@ -447,7 +450,7 @@ public boolean newCertificate(UserCertificateModel ucm, X509Metadata metadata, b
447450
}
448451

449452
File caKeystoreFile = new File(folder, X509Utils.CA_KEY_STORE);
450-
File zip = X509Utils.newClientBundle(metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);
453+
File zip = X509Utils.newClientBundle(user,metadata, caKeystoreFile, caKeystorePassword, GitblitAuthority.this);
451454

452455
// save latest expiration date
453456
if (ucm.expires == null || metadata.notAfter.before(ucm.expires)) {
@@ -850,9 +853,19 @@ private boolean sendEmail(UserModel user, X509Metadata metadata, File zip) {
850853
try {
851854
if (mail.isReady()) {
852855
Mailing mailing = Mailing.newPlain();
853-
mailing.subject = "Your Gitblit client certificate for " + metadata.serverHostname;
856+
if( user.getPreferences().getLocale()!=null )
857+
mailing.subject = MessageFormat.format(ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp",user.getPreferences().getLocale()).getString("gb.emailClientCertificateSubject"), metadata.serverHostname);
858+
else
859+
mailing.subject = MessageFormat.format(ResourceBundle.getBundle("com.gitblit.wicket.GitBlitWebApp", Locale.ENGLISH).getString("gb.emailClientCertificateSubject") , metadata.serverHostname);
854860
mailing.setRecipients(user.emailAddress);
855-
String body = X509Utils.processTemplate(new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl"), metadata);
861+
File fileMailTmp = null;
862+
String body = null;
863+
if( (fileMailTmp = new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl"+"_"+user.getPreferences().getLocale())).exists())
864+
body = X509Utils.processTemplate(fileMailTmp, metadata);
865+
else{
866+
fileMailTmp = new File(folder, X509Utils.CERTS + File.separator + "mail.tmpl");
867+
body = X509Utils.processTemplate(fileMailTmp, metadata);
868+
}
856869
if (StringUtils.isEmpty(body)) {
857870
body = MessageFormat.format("Hi {0}\n\nHere is your client certificate bundle.\nInside the zip file are installation instructions.", user.getDisplayName());
858871
}

src/main/java/com/gitblit/utils/X509Utils.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,25 @@ public static void addTrustedCertificate(String alias, X509Certificate cert, Fil
743743
*/
744744
public static File newClientBundle(X509Metadata clientMetadata, File caKeystoreFile,
745745
String caKeystorePassword, X509Log x509log) {
746+
return newClientBundle(null,clientMetadata,caKeystoreFile,caKeystorePassword,x509log);
747+
}
748+
749+
/**
750+
* Creates a new client certificate PKCS#12 and PEM store. Any existing
751+
* stores are destroyed. After generation, the certificates are bundled
752+
* into a zip file with a personalized README file.
753+
*
754+
* The zip file reference is returned.
755+
*
756+
* @param user
757+
* @param clientMetadata a container for dynamic parameters needed for generation
758+
* @param caKeystoreFile
759+
* @param caKeystorePassword
760+
* @param x509log
761+
* @return a zip file containing the P12, PEM, and personalized README
762+
*/
763+
public static File newClientBundle(com.gitblit.models.UserModel user,X509Metadata clientMetadata, File caKeystoreFile,
764+
String caKeystorePassword, X509Log x509log) {
746765
try {
747766
// read the Gitblit CA key and certificate
748767
KeyStore store = openKeyStore(caKeystoreFile, caKeystorePassword);
@@ -755,8 +774,17 @@ public static File newClientBundle(X509Metadata clientMetadata, File caKeystoreF
755774
x509log.log(MessageFormat.format("New client certificate {0,number,0} [{1}]", cert.getSerialNumber(), cert.getSubjectDN().getName()));
756775

757776
// process template message
758-
String readme = processTemplate(new File(caKeystoreFile.getParentFile(), "instructions.tmpl"), clientMetadata);
759-
777+
String readme = null;
778+
String sInstructionsFileName = "instructions.tmpl";
779+
if( user == null )
780+
readme = processTemplate(new File(caKeystoreFile.getParentFile(),sInstructionsFileName), clientMetadata);
781+
else{
782+
File fileInstructionsTmp = null;
783+
if( (fileInstructionsTmp = new File(caKeystoreFile.getParentFile(),sInstructionsFileName+"_"+user.getPreferences().getLocale())).exists() )
784+
readme = processTemplate(fileInstructionsTmp,clientMetadata);
785+
else
786+
readme = processTemplate(new File(caKeystoreFile.getParentFile(),sInstructionsFileName),clientMetadata);
787+
}
760788
// Create a zip bundle with the p12, pem, and a personalized readme
761789
File zipFile = new File(targetFolder, clientMetadata.commonName + ".zip");
762790
if (zipFile.exists()) {

src/main/java/com/gitblit/wicket/GitBlitWebApp.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,3 +783,4 @@ gb.deletePatchsetSuccess = Deleted Patchset {0}.
783783
gb.deletePatchsetFailure = Error deleting Patchset {0}.
784784
gb.referencedByCommit = Referenced by commit.
785785
gb.referencedByTicket = Referenced by ticket.
786+
gb.emailClientCertificateSubject = Your Gitblit client certificate for {0}

src/main/java/com/gitblit/wicket/GitBlitWebApp_zh_TW.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,4 @@ gb.deletePatchsetSuccess = \u5df2\u522a\u9664 Patchset {0}.
781781
gb.deletePatchsetFailure = \u522a\u9664 Patchset {0} \u932f\u8aa4.
782782
gb.referencedByCommit = Referenced by commit.
783783
gb.referencedByTicket = Referenced by ticket.
784+
gb.emailClientCertificateSubject = \u4F3A\u670D\u5668 {0} \u9023\u7DDA\u6191\u8B49

src/main/java/com/gitblit/wicket/pages/EditUserPage.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
<tr><th><wicket:message key="gb.confirmPassword"></wicket:message></th><td class="edit"><input type="password" wicket:id="confirmPassword" size="30" tabindex="3" /></td></tr>
3232
<tr><th><wicket:message key="gb.displayName"></wicket:message></th><td class="edit"><input type="text" wicket:id="displayName" size="30" tabindex="4" /></td></tr>
3333
<tr><th><wicket:message key="gb.emailAddress"></wicket:message></th><td class="edit"><input type="text" wicket:id="emailAddress" size="30" tabindex="5" /></td></tr>
34-
<tr><th><wicket:message key="gb.canAdmin"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canAdmin" tabindex="6" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canAdminDescription"></wicket:message></span></label></td></tr>
35-
<tr><th><wicket:message key="gb.canCreate"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canCreate" tabindex="7" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canCreateDescription"></wicket:message></span></label></td></tr>
36-
<tr><th><wicket:message key="gb.canFork"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canFork" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canForkDescription"></wicket:message></span></label></td></tr>
37-
<tr><th><wicket:message key="gb.excludeFromFederation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="excludeFromFederation" tabindex="9" /> &nbsp;<span class="help-inline"><wicket:message key="gb.excludeFromFederationDescription"></wicket:message></span></label></td></tr>
38-
<tr><th><wicket:message key="gb.disableUser"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="disabled" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.disableUserDescription"></wicket:message></span></label></td></tr>
34+
<tr><th><wicket:message key="gb.languagePreference"></wicket:message></th><td class="edit"><select wicket:id="language" ></select></td></tr>
35+
<tr><th><wicket:message key="gb.canAdmin"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canAdmin" tabindex="7" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canAdminDescription"></wicket:message></span></label></td></tr>
36+
<tr><th><wicket:message key="gb.canCreate"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canCreate" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canCreateDescription"></wicket:message></span></label></td></tr>
37+
<tr><th><wicket:message key="gb.canFork"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canFork" tabindex="9" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canForkDescription"></wicket:message></span></label></td></tr>
38+
<tr><th><wicket:message key="gb.excludeFromFederation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="excludeFromFederation" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.excludeFromFederationDescription"></wicket:message></span></label></td></tr>
39+
<tr><th><wicket:message key="gb.disableUser"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="disabled" tabindex="11" /> &nbsp;<span class="help-inline"><wicket:message key="gb.disableUserDescription"></wicket:message></span></label></td></tr>
3940
</tbody>
4041
</table>
4142
</div>

src/main/java/com/gitblit/wicket/pages/EditUserPage.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@
2020
import java.util.Collections;
2121
import java.util.Iterator;
2222
import java.util.List;
23+
import java.util.Locale;
2324

2425
import org.apache.wicket.PageParameters;
2526
import org.apache.wicket.behavior.SimpleAttributeModifier;
2627
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
2728
import org.apache.wicket.markup.html.form.Button;
2829
import org.apache.wicket.markup.html.form.CheckBox;
30+
import org.apache.wicket.markup.html.form.DropDownChoice;
2931
import org.apache.wicket.markup.html.form.Form;
3032
import org.apache.wicket.markup.html.form.TextField;
3133
import org.apache.wicket.model.CompoundPropertyModel;
34+
import org.apache.wicket.model.IModel;
3235
import org.apache.wicket.model.Model;
3336
import org.apache.wicket.model.util.CollectionModel;
3437
import org.apache.wicket.model.util.ListModel;
@@ -108,6 +111,30 @@ protected void setupPage(final UserModel userModel) {
108111
final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(
109112
new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users()
110113
.getAllTeamNames()), new StringChoiceRenderer(), 10, false);
114+
Locale locale = userModel.getPreferences().getLocale();
115+
if (locale == null) {
116+
locale = Locale.ENGLISH;
117+
}
118+
119+
List<Language> languages = UserPage.getLanguages();
120+
Language preferredLanguage = null;
121+
if (locale != null) {
122+
String localeCode = locale.getLanguage();
123+
if (!StringUtils.isEmpty(locale.getCountry())) {
124+
localeCode += "_" + locale.getCountry();
125+
}
126+
127+
for (Language lang : languages) {
128+
if (lang.code.equals(localeCode)) {
129+
// language_COUNTRY match
130+
preferredLanguage = lang;
131+
} else if (preferredLanguage != null && lang.code.startsWith(locale.getLanguage())) {
132+
// language match
133+
preferredLanguage = lang;
134+
}
135+
}
136+
}
137+
final IModel<Language> language = Model.of(preferredLanguage);
111138
Form<UserModel> form = new Form<UserModel>("editForm", model) {
112139

113140
private static final long serialVersionUID = 1L;
@@ -123,6 +150,10 @@ protected void onSubmit() {
123150
error(getString("gb.pleaseSetUsername"));
124151
return;
125152
}
153+
Language lang = language.getObject();
154+
if (lang != null) {
155+
userModel.getPreferences().setLocale(lang.code);
156+
}
126157
// force username to lower-case
127158
userModel.username = userModel.username.toLowerCase();
128159
String username = userModel.username;
@@ -251,7 +282,10 @@ protected void onSubmit() {
251282
form.add(confirmPasswordField.setEnabled(editCredentials));
252283
form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
253284
form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
285+
254286

287+
DropDownChoice<Language> choice = new DropDownChoice<Language>("language",language,languages );
288+
form.add( choice.setEnabled(languages.size()>0) );
255289
if (userModel.canAdmin() && !userModel.canAdmin) {
256290
// user inherits Admin permission
257291
// display a disabled-yet-checked checkbox
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.gitblit.wicket.pages;
2+
3+
import java.io.Serializable;
4+
5+
public class Language implements Serializable {
6+
7+
private static final long serialVersionUID = 1L;
8+
9+
final String name;
10+
final String code;
11+
12+
public Language(String name, String code) {
13+
this.name = name;
14+
this.code = code;
15+
}
16+
17+
@Override
18+
public String toString() {
19+
return name + " (" + code + ")";
20+
}
21+
}

0 commit comments

Comments
 (0)