本文整理汇总了Java中org.eclipse.jetty.util.security.Credential类的典型用法代码示例。如果您正苦于以下问题:Java Credential类的具体用法?Java Credential怎么用?Java Credential使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credential类属于org.eclipse.jetty.util.security包,在下文中一共展示了Credential类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] {"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new ProxyAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例2: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例3: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[]{"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例4: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[]{"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例5: getUserInfo
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
/**
* get the available information about the user
* <p/>
* for this LoginModule, the credential can be null which will result in a
* binding ldap authentication scenario
* <p/>
* roles are also an optional concept if required
*
* @param username
* @return the userinfo for the username
* @throws Exception
*/
@Override
public UserInfo getUserInfo(String username) throws Exception
{
LdapEntry entry = getEntryWithCredential(username);
if (entry == null)
{
return null;
}
String pwdCredential = getUserCredential(entry);
pwdCredential = convertCredentialLdapToJetty(pwdCredential);
Credential credential = Credential.getCredential(pwdCredential);
List<String> roles = getUserRoles(username, entry.getDn());
return new UserInfo(username, credential, roles);
}
示例6: loadUsers
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private void loadUsers() throws ParseException
{
if (config.users != null)
{
for (String userSpec: config.users)
{
String[] tokens = userSpec.split(":|,");
if (tokens.length < 2)
throw new ParseException("Invalid user spec: " + userSpec, 0);
String username = tokens[0].trim();
String password = tokens[1].trim();
String[] roles = new String[tokens.length-2];
for (int i = 0; i < roles.length; i++)
roles[i] = tokens[i+2].trim();
loginService.putUser(username, Credential.getCredential(password), roles);
}
}
}
示例7: login
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
@Override
public UserIdentity login(String username, Object creds) {
UserIdentity user = null;
// HERE IS THE HARDCODING
boolean validUser = "admin".equals(username) && "s3cr3t".equals(creds);
if (validUser) {
Credential credential = (creds instanceof Credential)?(Credential)creds:Credential.getCredential(creds.toString());
Principal userPrincipal = new MappedLoginService.KnownUser(username,credential);
Subject subject = new Subject();
subject.getPrincipals().add(userPrincipal);
subject.getPrivateCredentials().add(creds);
subject.setReadOnly();
user=identityService.newUserIdentity(subject,userPrincipal, ACCESS_ROLE);
users.put(user.getUserPrincipal().getName(), true);
}
return (user != null) ? user : null;
}
示例8: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例9: BasicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
public BasicAuth() {
HashLoginService loginService = new HashLoginService();
loginService.putUser(Main.configuration.username, Credential.getCredential(Main.configuration.password), new String[]{"user"});
loginService.setName(Main.configuration.realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
// Configure this ConstraintSecurityHandler:
setAuthenticator(new BasicAuthenticator());
setRealmName("myrealm");
addConstraintMapping(cm);
setLoginService(loginService);
}
示例10: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private static final SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[] {"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName(realm);
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例11: newSecurityHandler
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private ConstraintSecurityHandler newSecurityHandler(ResourceHandler handler) {
HashLoginService login = new HashLoginService();
login.putUser(USERNAME, Credential.getCredential(PASSWORD), new String[] { "user" });
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.addConstraintMapping(cm);
csh.setLoginService(login);
csh.setHandler(handler);
return csh;
}
示例12: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
protected SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService l = new HashLoginService();
l.putUser(username, Credential.getCredential(password), new String[]{"user"});
l.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/auth/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("myrealm");
csh.addConstraintMapping(cm);
csh.setLoginService(l);
return csh;
}
示例13: basicAuth
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private static SecurityHandler basicAuth(String username, String password, String realm) {
HashLoginService loginService = new HashLoginService();
loginService.putUser(username, Credential.getCredential(password), new String[]{"user"});
loginService.setName(realm);
Constraint constraint = new Constraint();
constraint.setName(Constraint.__DIGEST_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.setRealmName("realm");
csh.addConstraintMapping(constraintMapping);
csh.setLoginService(loginService);
return csh;
}
示例14: basicAuthentication
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
static final SecurityHandler basicAuthentication(String realm, String username, String password) {
HashLoginService loginService = new HashLoginService();
loginService.setName(realm);
loginService.putUser(username, Credential.getCredential(password), new String[]{"user"});
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[]{"user"});
constraint.setAuthenticate(true);
ConstraintMapping constraintMapping = new ConstraintMapping();
constraintMapping.setConstraint(constraint);
constraintMapping.setPathSpec("/*");
ConstraintSecurityHandler constraintSecurityHandler = new ConstraintSecurityHandler();
constraintSecurityHandler.setAuthenticator(new BasicAuthenticator());
constraintSecurityHandler.setRealmName(realm);
constraintSecurityHandler.addConstraintMapping(constraintMapping);
constraintSecurityHandler.setLoginService(loginService);
return constraintSecurityHandler;
}
示例15: getSecurityHandler
import org.eclipse.jetty.util.security.Credential; //导入依赖的package包/类
private SecurityHandler getSecurityHandler() {
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "admin" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
HashLoginService loginService = new HashLoginService();
loginService.putUser(username, Credential.getCredential(password), new String[] { "admin" });
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setRealmName("please password");
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.addConstraintMapping(cm);
securityHandler.setLoginService(loginService);
securityHandler.setHandler(this);
return securityHandler;
}