use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class PersonalRSSUtil method getPersonalRssLink.
/**
* Calculates the absolute URL to the users personal rss feed
* @param ureq
* @return String
*/
public static String getPersonalRssLink(UserRequest ureq) {
String token = null;
Identity identity = ureq.getIdentity();
BaseSecurity secManager = BaseSecurityManager.getInstance();
Authentication auth = secManager.findAuthentication(identity, RSS_AUTH_PROVIDER);
if (auth == null) {
// no token found - create one
token = RandomStringUtils.randomAlphanumeric(6);
auth = secManager.createAndPersistAuthentication(identity, RSS_AUTH_PROVIDER, identity.getName(), token, null);
} else {
token = auth.getCredential();
}
StringBuilder sb = new StringBuilder();
return sb.append(PersonalRSSUtil.URI_PERSONAL_CHANNEL).append(ureq.getIdentity().getName()).append("/").append(token).append("/olat.rss").toString();
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class JunitTestHelper method createAndPersistIdentityAsUser.
/**
* Create an identity with user permissions
* @param login
* @return
*/
public static final Identity createAndPersistIdentityAsUser(String login) {
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity = securityManager.findIdentityByName(login);
if (identity != null)
return identity;
SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
if (group == null)
group = securityManager.createAndPersistNamedSecurityGroup(Constants.GROUP_OLATUSERS);
User user = UserManager.getInstance().createUser("first" + login, "last" + login, login + "@" + maildomain);
identity = securityManager.createAndPersistIdentityAndUser(login, null, user, BaseSecurityModule.getDefaultAuthProviderIdentifier(), login, PWD);
securityManager.addIdentityToSecurityGroup(identity, group);
return identity;
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class UserTest method setup.
/**
* @see junit.framework.TestCase#setUp()
*/
@Before
public void setup() throws Exception {
System.out.println("running before...: " + this.hashCode());
// create some users with user manager
// set up fixture using the user manager
UserManager um = UserManager.getInstance();
BaseSecurity sm = BaseSecurityManager.getInstance();
if (sm.findIdentityByName("judihui") == null) {
u1 = um.createUser("judihui", "judihui", "judihui@id.uzh.ch");
u1.setProperty(UserConstants.INSTITUTIONALEMAIL, "instjudihui@id.uzh.ch");
u1.setProperty(UserConstants.INSTITUTIONALNAME, "id.uzh.ch");
u1.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, "id.uzh.ch");
i1 = sm.createAndPersistIdentityAndUser(u1.getProperty(UserConstants.LASTNAME, new Locale("en")), null, u1, "OLAT", u1.getProperty(UserConstants.LASTNAME, new Locale("en")), "");
} else {
System.out.println("Does not create user, found 'judihui' already in db");
i1 = sm.findIdentityByName("judihui");
u1 = i1.getUser();
}
if (sm.findIdentityByName("migros") == null) {
u2 = um.createUser("migros", "migros", "migros@id.migros.uzh.ch");
u2.setProperty(UserConstants.INSTITUTIONALEMAIL, "instmigros@id.migros.uzh.ch");
u2.setProperty(UserConstants.INSTITUTIONALNAME, "id.migros.uzh.ch");
u2.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, "id.uzh.ch");
i2 = sm.createAndPersistIdentityAndUser(u2.getProperty(UserConstants.LASTNAME, new Locale("en")), null, u2, "OLAT", u2.getProperty(UserConstants.LASTNAME, new Locale("en")), "");
} else {
System.out.println("Does not create user, found 'migros' already in db");
i2 = sm.findIdentityByName("migros");
u2 = i2.getUser();
}
if (sm.findIdentityByName("salat") == null) {
u3 = um.createUser("salat", "salat", "salat@id.salat.uzh.ch");
u3.setProperty(UserConstants.INSTITUTIONALEMAIL, "instsalat@id.salat.uzh.ch");
u3.setProperty(UserConstants.INSTITUTIONALNAME, "id.salat.uzh.ch");
u3.setProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, "id.uzh.ch");
i3 = sm.createAndPersistIdentityAndUser(u3.getProperty(UserConstants.LASTNAME, new Locale("en")), null, u3, " OLAT", u3.getProperty(UserConstants.LASTNAME, new Locale("en")), "");
} else {
System.out.println("Does not create user, found 'salat' already in db");
i3 = sm.findIdentityByName("salat");
u3 = i3.getUser();
}
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class Path method getFeedBaseUri.
/**
* Returns a podcast base URI of the type<br>
* http://myolat.org/olat/[podcast|blog]/[IDKEY/TOKEN]/ORESID
*
* @param feed
* @param identityKey
* @return The feed base uri for the given user (identity)
*/
public static String getFeedBaseUri(Feed feed, Identity identity, Long courseId, String nodeId) {
BaseSecurity manager = BaseSecurityManager.getInstance();
boolean isCourseNode = courseId != null && nodeId != null;
final String slash = "/";
StringBuffer uri = new StringBuffer();
uri.append(Settings.getServerContextPathURI());
uri.append(slash);
uri.append(FeedMediaDispatcher.uriPrefixes.get(feed.getResourceableTypeName()));
uri.append(slash);
if (isCourseNode) {
uri.append(COURSE_NODE_INDICATOR);
uri.append(slash);
}
if (identity != null) {
// The identity can be null for guests
String idKey = identity.getKey().toString();
Authentication authentication = manager.findAuthenticationByAuthusername(idKey, TOKEN_PROVIDER);
if (authentication == null) {
// Create an authentication
String token = RandomStringUtils.randomAlphanumeric(6);
authentication = manager.createAndPersistAuthentication(identity, TOKEN_PROVIDER, idKey, token, null);
}
// If the repository entry allows guest access it is public, thus not
// private.
boolean isPrivate = true;
RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(feed, false);
if (entry != null && entry.getAccess() == RepositoryEntry.ACC_USERS_GUESTS) {
isPrivate = false;
}
if (isPrivate) {
// identity key
uri.append(idKey);
uri.append(slash);
// token
uri.append(authentication.getCredential());
uri.append(slash);
}
}
if (isCourseNode) {
uri.append(courseId);
uri.append(slash);
uri.append(nodeId);
uri.append(slash);
}
// feed id
uri.append(feed.getResourceableId());
// Append base uri delimiter. (Used to identify the root path for caching)
uri.append("/_");
return uri.toString();
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class ChangePasswordWebService method register.
/**
* @param identityKey
* @param request
* @return
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response register(@QueryParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
if (!isUserManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
Identity identity = securityManager.loadIdentityByKey(identityKey);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!CoreSpringFactory.getImpl(UserModule.class).isPwdChangeAllowed(identity)) {
return Response.serverError().status(Status.FORBIDDEN).build();
}
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
String emailAdress = identity.getUser().getProperty(UserConstants.EMAIL, null);
String ip = request.getRemoteAddr();
TemporaryKey tk = rm.createAndDeleteOldTemporaryKey(identity.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
return Response.ok(new TemporaryKeyVO(tk)).build();
}
Aggregations