本文整理汇总了Java中org.jboss.seam.security.Identity类的典型用法代码示例。如果您正苦于以下问题:Java Identity类的具体用法?Java Identity怎么用?Java Identity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Identity类属于org.jboss.seam.security包,在下文中一共展示了Identity类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testLoginComponent
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Test
public void testLoginComponent() throws Exception
{
Identity identity = Identity.instance();
assertFalse(identity.isLoggedIn());
identity.setUsername("gavin");
identity.setPassword("foobar");
identity.login();
User user = (User)Component.getInstance("user");
assertEquals("Gavin King", user.getName());
assertEquals("gavin", user.getUsername());
assertEquals("foobar", user.getPassword());
assertTrue(identity.isLoggedIn());
identity.logout();
assertFalse(identity.isLoggedIn());
identity.setUsername("gavin");
identity.setPassword("tiger");
identity.login();
assertFalse(identity.isLoggedIn());
}
开发者ID:seam2,项目名称:seam-examples-migrated-off-seam2,代码行数:23,代码来源:LoginTest.java
示例2: testLogin
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Test
public void testLogin() throws Exception
{
Identity identity = Identity.instance();
assertFalse(identity.isLoggedIn());
identity.setUsername("gavin");
identity.setPassword("foobar");
identity.login();
User user = (User)Component.getInstance("user");
assertEquals("Gavin King", user.getName());
assertEquals("gavin", user.getUsername());
assertEquals("foobar", user.getPassword());
assertFalse(Manager.instance().isLongRunningConversation());
assertTrue(identity.isLoggedIn());
identity.logout();
assertTrue(Session.instance().isInvalid());
assertFalse(identity.isLoggedIn());
}
开发者ID:seam2,项目名称:seam-examples-migrated-off-seam2,代码行数:24,代码来源:LoginTest.java
示例3: authenticatedCheck
import org.jboss.seam.security.Identity; //导入依赖的package包/类
public @Secures @Private boolean authenticatedCheck(Identity identity)
{
boolean perm = identity != null &&
identity.getUser() != null &&
identity.isLoggedIn();
log.debugv( "Private permission for user {0} is {1}", identity.getUser(), perm );
return perm;
}
开发者ID:Inspiredsoft,项目名称:parco,代码行数:11,代码来源:SecurityRules.java
示例4: changePassword
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@End
public String changePassword() {
List<User> users = this.entityManager
.createQuery("from User u where u.username=:username")
.setParameter("username",
Identity.instance().getCredentials().getUsername())
.getResultList();
User user = null;
if (users != null && users.size() == 1) {
user = users.get(0);
}
if (!user.getPassword().equals(this.getOldPassword())) {
FacesMessages.instance().add("La vecchia password e' sbagliata");
return "changePassword";
}
if (this.getNewPassword().equals(this.getOldPassword())) {
FacesMessages.instance().add(
"La nuova password deve essere diversa dalla vecchia");
return "changePassword";
}
if (!this.getConfirmPassword().equals(this.getNewPassword())) {
FacesMessages.instance().add("Le password non coincidono");
return "changePassword";
}
user.setPassword(this.getNewPassword());
this.entityManager.merge(user);
FacesMessages.instance().add("Password aggiornata");
return "home";
}
开发者ID:lablita,项目名称:ridire-cpi,代码行数:31,代码来源:ChangePassword.java
示例5: updateStatement
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Factory("statement")
public Statement updateStatement() {
statement = null;
String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
if (statementId != null) {
if (person != null && Identity.instance().hasPermission("metropolitalia","view-admin-interface")) {
byId(statementId);
return statement;
}
}
if (statement == null && viewId.equals("/recognize.xhtml")) {
if (statementId != null) {
Identity.instance().checkPermission("metropolitalia", "view-admin-interface");
byId(statementId);
if (statement != null) {
Query q = entityManager.createNamedQuery("locationAssignment.byResourceAndPerson");
q.setParameter("resource", statement);
q.setParameter("person", person);
if (q.getResultList().size() > 0) {
statement = null;
facesMessages.addFromResourceBundle("statement.alreadyPlayed");
}
}
}
if (statement == null)
sensibleForLocationAssignment();
}
if (statement == null && (viewId.equals("/poker.xhtml") || viewId.equals("/pokerRequest.xhtml"))) {
sensibleForPoker();
}
if (statement == null) {
random();
}
return statement;
}
开发者ID:play4science,项目名称:gwap,代码行数:36,代码来源:StatementBean.java
示例6: checkAndAward
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Observer(Identity.EVENT_LOGIN_SUCCESSFUL)
public void checkAndAward() {
resetCache();
Badge b = getNextBestBadge();
Badge lastBadge = null;
while (b != lastBadge) {
lastBadge = b;
if (b.getWorth() <= 3) { // for location assignment
if (getNrLocationAssignmentsForNextBadge() <= 0) {
person = entityManager.find(Person.class, person.getId());
person.getBadges().add(b);
facesMessages.addFromResourceBundle("badge.reached");
log.info("#0 reached next badge #1", person, b);
}
} else if (b.getWorth() == 4) {
if (getNrBetsForNextBadge() <= 0) {
person = entityManager.find(Person.class, person.getId());
person.getBadges().add(b);
facesMessages.addFromResourceBundle("badge.reached");
log.info("#0 reached next badge #1", person, b);
}
} else if (b.getWorth() == 5) {
HighscoreBean highscoreBean = (HighscoreBean) Component.getInstance("highscoreBean", true);
List<HighscoreSet> highscores = highscoreBean.getHighscores();
for (HighscoreSet highscoreSet : highscores) {
if (highscoreSet.getGameType().getName().equals("mitRecognize")) {
if (highscoreSet.getHighscoreAll().get(0).getPersonId().equals(person.getId())) {
person.getBadges().add(b);
facesMessages.addFromResourceBundle("badge.reached");
log.info("#0 reached next badge #1", person, b);
}
}
}
}
entityManager.flush();
resetCache();
b = getNextBestBadge();
}
}
开发者ID:play4science,项目名称:gwap,代码行数:40,代码来源:BadgeBean.java
示例7: getLatestStatementsTeaser
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Factory("statementsTeaser")
public StatementsTeaser getLatestStatementsTeaser() {
try {
// For admins, allow access by ID
if (statementsTeaserId != null && Identity.instance().hasPermission("metropolitalia","view-admin-interface"))
statementsTeaser = entityManager.find(StatementsTeaser.class, statementsTeaserId);
else
statementsTeaser = (StatementsTeaser) entityManager.createNamedQuery("statementsTeaser.latestByPublicationDate")
.setMaxResults(1).getSingleResult();
return statementsTeaser;
} catch (NoResultException e) {
log.info("Could not find a StatementsTeaser that is currently published");
return null;
}
}
开发者ID:play4science,项目名称:gwap,代码行数:16,代码来源:StatementsTeaserBean.java
示例8: shibboleth2Authenticate
import org.jboss.seam.security.Identity; //导入依赖的package包/类
/**
* Authenticate using credentials passed from web request header
*/
public boolean shibboleth2Authenticate() {
log.debug("Checking if user authenticated with shibboleth already");
boolean result = false;
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String authType = request.getAuthType();
String userUid = request.getHeader("REMOTE_USER");
String userUidlower = request.getHeader("remote_user");
Enumeration<?> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = (String) headerNames.nextElement();
log.trace(headerName + "-->" + request.getHeader(headerName));
}
log.debug("Username is " + userUid);
log.debug("UsernameLower is " + userUidlower);
log.debug("AuthType is " + authType);
Map<String, String[]> headers = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderValuesMap();
for (String name : headers.keySet()) {
log.trace(name + "==>" + StringUtils.join(headers.get(name)));
}
if (StringHelper.isEmpty(userUid) || StringHelper.isEmpty(authType) || !authType.equals("shibboleth")) {
result = false;
return result;
}
Pattern pattern = Pattern.compile("[email protected]+\\.[a-z]+");
Matcher matcher = pattern.matcher(userUid);
User user = null;
if (matcher.matches()) {
// Find user by uid
user = personService.getPersonByEmail(userUid);
} else {
// Find user by uid
user = personService.getUserByUid(userUid);
}
if (user == null) {
result = false;
return result;
}
log.debug("Person Inum is " + user.getInum());
if (GluuStatus.ACTIVE.getValue().equals(user.getAttribute("gluuStatus"))){
credentials.setUsername(user.getUid());
// credentials.setPassword("");
Principal principal = new SimplePrincipal(user.getUid());
log.debug("Principal is " + principal.toString());
identity.acceptExternallyAuthenticatedPrincipal(principal);
log.info("User '{0}' authenticated with shibboleth already", userUid);
identity.quietLogin();
postLogin(user);
Contexts.getSessionContext().set(OxTrustConstants.APPLICATION_AUTHORIZATION_TYPE,
OxTrustConstants.APPLICATION_AUTHORIZATION_NAME_SHIBBOLETH2);
result = true;
if (Events.exists()) {
facesMessages.clear();
Events.instance().raiseEvent(Identity.EVENT_LOGIN_SUCCESSFUL);
}
}else{
result = false;
}
return result;
}
开发者ID:AgarwalNeha1,项目名称:gluu,代码行数:76,代码来源:Authenticator.java
示例9: testChangePassword
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Test
public void testChangePassword() throws Exception
{
Identity identity = Identity.instance();
Contexts.getSessionContext().set("user", new User("Gavin King", "foobar", "gavin"));
identity.setUsername("gavin");
identity.setPassword("foobar");
identity.login();
User user = (User)Component.getInstance("user");
assertEquals("Gavin King", user.getName());
assertEquals("gavin", user.getUsername());
assertEquals("foobar", user.getPassword());
assertFalse(Manager.instance().isLongRunningConversation());
assertTrue(identity.isLoggedIn());
user.setPassword("xxxyyy");
ChangePassword changePassword = (ChangePassword)Component.getInstance("changePassword");
changePassword.setVerify("xxyyyx");
changePassword.changePassword();
user = (User)Component.getInstance("user");
assertEquals("Gavin King", user.getName());
assertEquals("gavin", user.getUsername());
assertEquals("foobar", user.getPassword());
assertFalse(Manager.instance().isLongRunningConversation());
assertTrue(identity.isLoggedIn());
user = (User)Component.getInstance("user");
user.setPassword("xxxyyy");
changePassword = (ChangePassword)Component.getInstance("changePassword");
changePassword.setVerify("xxxyyy");
changePassword.changePassword();
user = (User)Component.getInstance("user");
assertEquals("Gavin King", user.getName());
assertEquals("gavin", user.getUsername());
assertEquals("xxxyyy", user.getPassword());
assertFalse(Manager.instance().isLongRunningConversation());
assertTrue(identity.isLoggedIn());
user = (User)Component.getInstance("user");
assertEquals("xxxyyy", user.getPassword());
user.setPassword("foobar");
changePassword = (ChangePassword)Component.getInstance("changePassword");
changePassword.setVerify("foobar");
changePassword.changePassword();
user = (User)Component.getInstance("user");
assertEquals("Gavin King", user.getName());
assertEquals("gavin", user.getUsername());
assertEquals("foobar", user.getPassword());
assertFalse(Manager.instance().isLongRunningConversation());
assertTrue(identity.isLoggedIn());
}
开发者ID:seam2,项目名称:seam-examples-migrated-off-seam2,代码行数:57,代码来源:ChangePasswordTest.java
示例10: hasPermission
import org.jboss.seam.security.Identity; //导入依赖的package包/类
@Override
public boolean hasPermission(Object target, String action) {
Identity identity = Identity.instance();
return identity.isLoggedIn() && identity.hasRole("admin");
}
开发者ID:play4science,项目名称:gwap,代码行数:6,代码来源:RolePermissionResolver.java
注:本文中的org.jboss.seam.security.Identity类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论